Skip to content

How to aggregate joined column? #694

Answered by Skyscimitar
HuifangYeo asked this question in Q&A
Discussion options

You must be logged in to vote

Hi HuiFang,
Since you are aggregating a table column, it is aggregated on all levels by default. I'm assuming that there are mulitple OrderId per ProductId so the value you are getting for historicalPrices.SUM is probably the sum of the historical price for a product over all the OrderId it appears in.
To avoid this, you should use:

tt.agg.sum(tt.agg.single_value(table["historicalPrices"]), scope=tt.OriginScope(l["ProductId"]))

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jackschd
Comment options

Answer selected by tibdex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants