简体   繁体   中英

Tableau Level of Detail question. I do not know why my solution is getting wrong result

  1. A single order can include multiple items across multiple product categories. Each item will be on a different row of the data, but the rows will share a single Order ID. Find the average sales value for orders which include office supplies. Download data Excel sheet here

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:

  • Mine: 511.2
  • Key solution: 1186.4

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM