My solution was this: [to generate a calculation field]
SUM({ FIXED [Order ID]: MAX(IF [Product Category]='Office Supplies' THEN [Sales] ELSE 0 END)})/COUNTD(if [Product Category]='Office Supplies' THEN [Order ID] ELSE NULL end)
The solution used the formula to get answer like this:
SUM({ FIXED [Order ID]: MAX(IF [Product Category]='Office Supplies' THEN 1 ELSE 0 END)}*[Sales])/COUNTD(if [Product Category]='Office Supplies' THEN [Order ID] ELSE NULL end)
This two gets totally different results:
My question is that the two solutions look equivalent, but the results are totally different. Please tell me why? Thank you so much and I appreciate it.
They are different. I suggest laying it all out in a table so you understand what is happening.
To start with this: SUM({ FIXED [Order ID]: MAX(IF [Product Category]='Office Supplies' THEN 1 ELSE 0 END)}*[Sales])
Any order id that contains Office Supplies will have all sales taken into account, not only those attributed to Office Supplies. Any order id with Office Supplies returns a 1 against ALL of their order items, and consequently all of their sales are taken into account.
This formula: SUM({ FIXED [Order ID]: MAX(IF [Product Category]='Office Supplies' THEN [Sales] ELSE 0 END)})
Will return the highest sales per order where the product category is Office Supplies.
For example if they purchased in the same Order Id Office Supplies at 10, Office Supplies at 200 and Food at 500 the top formula would return 710. The bottom formula would return 200.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.