Since you say "I need to find the average of the currency-column for the last 50 rows", you could use this:
=ArrayFormula(query({D2:E}; "select AVG(Col2) where (Col1 > date '"&TEXT(WORKDAY($D139:D;-50); "YYYY-MM-DD")&"' AND Col1 < date '"&TEXT($D139:D; "YYYY-MM-DD")&"') label AVG(Col2) ''"))
But then you say "I need this in every row for the 50 predecessor rows without copying the formula", so this is the best way I can think of having the formula in one cell:
={query({C2:C};"where Col1 is null limit 49";0);query(ARRAYFORMULA(if(E2:E="";"";(E2:E+E3:E+E4:E+E5:E+E6:E+E7:E+E8:E+E9:E+E10:E+E11:E+E12:E+E13:E+E14:E+E15:E+E16:E+E17:E+E18:E+E19:E+E20:E+E21:E+E22:E+E23:E+E24:E+E25:E+E26:E+E27:E+E28:E+E29:E+E30:E+E31:E+E32:E+E33:E+E34:E+E35:E+E36:E+E37:E+E38:E+E39:E+E40:E+E41:E+E42:E+E43:E+E44:E+E45:E+E46:E+E47:E+E48:E+E49:E+E50:E+E51:E)/50));"limit "&counta(E2:E)-49&" ";0)}
NOTE: the formula must go in row 2!! Anywhere else and it might cause issues with your sheet adding more rows.
For query({C2:C};"where Col1 is null limit 49";0)
to work correctly and offset the arrayformula, you must have at least 49 blank cells. If not, reference a different column.
Since your sample sheet is location Germany, I've had to use ; rather than , as function separators.
Update
If you create a named range called 'RowsToAverage' containing the number of rows you want to average (ie. 50), here is a revised formula:
={query({C2:C};"where Col1 is null limit "&RowsToAverage-1&"";0);query(ARRAYFORMULA(if(E2:E="";"";(E2:E+E3:E+E4:E+E5:E+E6:E+E7:E+E8:E+E9:E+E10:E+E11:E+E12:E+E13:E+E14:E+E15:E+E16:E+E17:E+E18:E+E19:E+E20:E+E21:E+E22:E+E23:E+E24:E+E25:E+E26:E+E27:E+E28:E+E29:E+E30:E+E31:E+E32:E+E33:E+E34:E+E35:E+E36:E+E37:E+E38:E+E39:E+E40:E+E41:E+E42:E+E43:E+E44:E+E45:E+E46:E+E47:E+E48:E+E49:E+E50:E+E51:E)/RowsToAverage));"limit "&counta(E2:E)-(RowsToAverage-1)&" ";0)}
You'll still need to manually create the range (E2:E+E3:E+E4:E+E5:E+E6:E+E7:E+E8:E+E9:E+E10:E+E11:E+E12:E+E13:E+E14:E+E15:E+E16:E+E17:E+E18:E+E19:E+E20:E+E21:E+E22:E+E23:E+E24:E+E25:E+E26:E+E27:E+E28:E+E29:E+E30:E+E31:E+E32:E+E33:E+E34:E+E35:E+E36:E+E37:E+E38:E+E39:E+E40:E+E41:E+E42:E+E43:E+E44:E+E45:E+E46:E+E47:E+E48:E+E49:E+E50:E+E51:E)
, but his can be done easily in another cell, then copied into the formula above:
=textjoin("+";true;arrayformula("E"&row(indirect("A2:A"&RowsToAverage+1))&":E"))
AVERAGEIFS()
? - Harun24HRARRAYFORMULA
. Where the start date is 24/06/1998 17:30:00, it will average 50 days rolling, working on 5790 rows of data. - Aresvik