How to make a SPARKLINE Line graph display only the last 7 days dynamically? That is, as data, or new rows, keep being added to HISTORY sheet, the SPARKLINE graph advances in order to show always just the last 7 days in the graph. I imagine there are ways to do that using the number of rows? But what I am interested is if there is also a way in which regardless of the number of rows, the graph will always show the last 7 days, or any other period of my choice? This is because the data, or new rows with values, will be added randomly: sometimes every hour, sometimes once a day etc.
Also is there a way of choosing between different times periods: 24h, 7 days, 1 month, 3 months, 6 months, 1 year etc. And then the SPARKLINE changes accordingly.
Appreciate any help.
Here is a small file for editing: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
last 7 records:
=SPARKLINE(QUERY(QUERY(SORT({HISTORY!B:B, ROW(HISTORY!B:B)}, 2, 0),
"where Col1 is not null limit 7", 0), "select Col1 order by Col2"),
{"charttype","line";"color","#1aded1"})
last 7 days:
=INDEX(SPARKLINE(QUERY({IFERROR(DATEVALUE(HISTORY!A:A)), HISTORY!B:B},
"select Col2
where Col2 is not null
and Col1 <= "&INT(MAX(HISTORY!A:A))&"
and Col1 >= "&INT(MAX(HISTORY!A:A)-6), 0),
{"charttype","line";"color","#1aded1"}))
example for 3 months: