Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Good day dear community,
I came across the following task:
Calculate sum(value) but only for those buyers, which have no less that 5 transactions.
Let's say I have a model with these two tables:
Trans:
trans_id | buyer_id | trans_value |
---|---|---|
1 | A | 10 |
2 | A | 20 |
3 | B | 30 |
buyer_id | buyer_name |
---|---|
A | Alpha |
B | Bravo |
Then I visualize it in a bar chart:
Dimension: buyer_name
Measure: sum(trans_value)
I've achieved the desired result with IF: if(count(trans_id)>=5, sum(trans_value))
But wonder is there a more elegant/efficient way to do the same with set analysis?
Would appreciate any help, thanks
maybe like this
sum({<trans_id={"=count(trans_id)>=5"}>}trans_value)
Oh, thank you, so there was no need for aggr function
Your script works fine when trans_id is replaced with buyer_name:
sum({<buyer_name={"=count(trans_id)>=5"}>}trans_value)