Dynamic stats in the decoration title lable, by time stamp, in QGIS

qgisstatisticstime seriestitlevector

I am trying to create a visualisation method of simple stats using the title label in QGIS canvas. I need to observe temporal changes in the stats, so I have tried to specify a dynamic chunk of text in the title label that provides the stats of the visible features that looks like this:

[%concat(format_date(@map_start_time, 'yyyy-MM-dd'), ' to ', format_date(@map_end_time, 'yyyy-MM-dd'))%]

[%'Water level mean: '%][%aggregate(
 layer:= 'Lake',
 aggregate:='mean', 
 expression:="Lake water level (m)",
 filter:=(attribute( $currentfeature , 'Date (YYYYMMDD)')) ,
 concatenator:=',')%]

Range:

[% '+-' %] [%aggregate(
 layer:= 'Lake',
 aggregate:='range', 
 expression:="Lake water level (m)",
 filter:="Date (YYYYMMDD)",
 concatenator:=',')/2%]; 

Max: [%aggregate(
layer:= 'Lake',
aggregate:='max',
expression:="Lake water level (m)",
filter:="Date (YYYYMMDD)",
concatenator:=',')%];

Min:

[%aggregate(
 layer:= 'Lake',
 aggregate:='min', 
 expression:="Lake water level (m)",
 filter:="Date (YYYYMMDD)",
 concatenator:=',')%]

However, these expressions only provide the layer stats, not the visible stats. My goal is to make those stats computed from the layer at each time period, so they relate to each visible time period. How can I do this?

Best Answer

Your issue is that the filter of your aggregate function is not a filter, but only an attribute. You need to add a comparison to actually make it a filter. Something like:

aggregate('Lake','mean',"Lake water level (m)",filter:="Date (YYYYMMDD)">=@map_start_time and "Date (YYYYMMDD)"<=@map_end_time)
Related Question