Help putting a filter together

Hi,

This counts the number of weeks with a week value > 7

{{{ [tag[current]field:Y[1]get[week]compare:number:gt[7]count[]]  }}}

but what I want to do is sum the value of the ‘£’ field for the same weeks

{{{ [tag[current]field:Y[1]get[£]sum[]] }}}

But after looking through the docs, I’m struggling to put the two together.

Any help much appreciated,
Jon

I’m not quite sure how count[] fits into your desired result, but maybe this will get you started:

{{{ [tag[current]Y[1]] :filter[get[week]compare:number:gt[7]] :reduce[get[£]add<accumulator>] }}}

Or a slightly different approach with sum[]:

{{{ [tag[current]Y[1]] :filter[get[week]compare:number:gt[7]] :map[get[£]] +[sum[]] }}}

Notes:

  • The :filter prefix is the major piece you were missing: it lets us reject all the [tag[current]Y[1]] titles that don’t have a “week” value > 7 without modifying the input titles the way get normally does. This allows us to use get[£] in the next step.
  • The :reduce filter run prefix lets us do in one step what the combination of :map[get[£]] +[sum[]] does in two. First, for each input title, get the value of the “£” field. Then add up all these results.
3 Likes

Excellent - both work!

Many thanks - and for the explanation.
Jon