I want this cell to output the average value according to the time period chosen. If I choose 7 days, the cell should display the average value for the last week / 7 days. If I choose 6 months, it displays the average of the last 6 months and so on. Is this possible?
Link for editable file: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
you can change B14 to:
=INDEX(SPARKLINE(QUERY({IFERROR(DATEVALUE(HISTORY!A:A)), HISTORY!D:D},
"select Col2
where Col2 is not null
and Col1 <= "&INT(MAX(HISTORY!A:A))&"
and Col1 > "&INT(MAX(HISTORY!A:A))-C12-1, 0),
{"charttype","line";"color","#1aded1"}))
and for average use in C13:
=INDEX(AVERAGE(QUERY({IFERROR(DATEVALUE(HISTORY!A:A)), HISTORY!D:D},
"select Col2
where Col2 is not null
and Col1 <= "&INT(MAX(HISTORY!A:A))&"
and Col1 > "&INT(MAX(HISTORY!A:A))-C12-1, 0)))