In the [print] Layout Composer in QGIS 3.18.1 I am trying to filter the legend styles displayed for an item that is a polygon layer styled by the "categorised renderer" by the min, max and median values displayed within the current view of the linked map in the layout.
What I have:
Generated from the "categorised renderer" there is a different shade of purple for each season since ~1950 for each polygon in the layer.
When I use the "only show items inside linked map" checkbox in the legend there is now a subset of the ~70 years coloured purples since 1950 that are within/intersect the linked layout map.
However there are still say 20 entries, which makes for an overly large legend.
What I want:
I want to just show in the legend the min, max and median year entries as a subset of those within the linked map (not the entire layer) so that the result is just 3 lines in the legend (or 3 shades of purple labelled with the oldest, most recent and middle of the subset season).
What I've tried:
I know how to use the "Filter Expression" button (bottom right of the Legend Items list) to filter for some expressions, but not for the one desired and described above.
For example I can use
right("SEASON" ,1) IN ('0','2','4','6','8') to only return entries that end in those numbers, and it works.
I can also see that if I use
minimum("SEASON") the "Preview" returns the oldest record in the dataset, but because the oldest record is not within my current linked layout map, nothing is shown in the legend.
I suspect I need an expression that applies something like
minimum("SEASON") to just those polygons that intersect my linked map, so I can use something like:
"SEASON" = minimum("SEASON") OR "SEASON" = maximum("SEASON") OR "SEASON" = median("SEASON")
Is this the case, is it possible, what is the correct expression, or is there another or better way I should do this?