Forum Discussion
Basket Type analysis
- Anonymous5 years ago
Hi Anonymous
Here I have two ways to get the average.
Calculated column:
Avg = VAR _CountOrder = CALCULATE ( DISTINCTCOUNT ( 'Table'[Sales_Order_ID] ), FILTER ( 'Table', 'Table'[SKU] = EARLIER ( 'Table'[SKU] ) ) ) VAR _OrderT = SUMMARIZE ( FILTER ( 'Table', 'Table'[SKU] = EARLIER ( 'Table'[SKU] ) ), 'Table'[Sales_Order_ID] ) VAR _CountItem = CALCULATE ( COUNT ( 'Table'[Line_Item_ID] ), FILTER ( 'Table', 'Table'[Sales_Order_ID] IN _OrderT ) ) RETURN _CountItem / _CountOrderResult is as below.
Measure:
M_Avg = VAR _CountOrder = CALCULATE ( DISTINCTCOUNT ( 'Table'[Sales_Order_ID] ), FILTER ( ALL('Table'), 'Table'[SKU] = MAX('Table'[SKU] ) ) ) VAR _OrderT = SUMMARIZE ( FILTER (ALL( 'Table'), 'Table'[SKU] = MAX ( 'Table'[SKU] ) ), 'Table'[Sales_Order_ID] ) VAR _CountItem = CALCULATE ( COUNT ( 'Table'[Line_Item_ID] ), FILTER ( ALL('Table'), 'Table'[Sales_Order_ID] IN _OrderT ) ) RETURN _CountItem / _CountOrderResult is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
If you want to get average number of line items per sales order for each SKU, you can build a calculated column as below.
Average Per Sales_Order Per SKU = CALCULATE(AVERAGE('Table'[Line_Item_ID]),FILTER('Table','Table'[Sales_Order_ID] = EARLIER('Table'[Sales_Order_ID])&&'Table'[SKU]=EARLIER('Table'[SKU])))
Then you can build a Rank column for TopN.
Rank per Sku = RANKX(FILTER('Table','Table'[SKU] =EARLIER('Table'[SKU])),[Average Per Sales_Order Per SKU])
Result is as below.
In your sample, I am confused about the average of per Sales Order for each SKU is the same as Line Item ID.
Your sample seems to be missing data under the same Sale_Order and the same SKU.
If this reply still couldn't help you solve your problem, please share more details about your sample to me by your Onedrive for Business.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous5 years agoNot applicable
The measure is clearly incorrect - the SKU "8" only appears in a single invoice, but that invoice has 2 line items:
therefore the average number of line items for the SKU "8" is 2.