Forum Discussion
Distribute sales to filtered values
- 6 years ago
Hi Jos13 ,
The measure Total doesn’t summarize, it is based on the calculation logic of each row.
If you want to get the correct total, we suggest to create a calculate column like this.
Column = var _C4_C5 = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Customer] in {"Customer 4","Customer 5"} && 'Table'[Date]=EARLIER('Table'[Date]))) var _avg = _C4_C5 / 3 return 'Table'[Sales] + _avgBut if you want to show the Total sales of each customer using a bar chart, you can try this Measure.
Measure = VAR _Total123 = CALCULATE ( SUM ( 'Table'[Sales] ), ALLSELECTED ( 'Table' ) ) VAR _Total45 = CALCULATE ( SUM ( 'Table'[Sales] ), ALL ( 'Table' ) ) -_Total123 VAR _count = CALCULATE ( DISTINCTCOUNT ( 'Table'[Customer] ), ALLSELECTED('Table') ) VAR _sum_sales = SUM ( 'Table'[Sales] ) RETURN _Total45 / _count + _sum_salesThe measure only displays the correct value in the current context.
If you have any question, please kindly ask here and we will try to resolve it.
BTW, pbix as attached.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi v-zhenbw-msft ,
The filter I was talking about will look like this,
On 1st June 2020, combined sale of customers 4 & 5 is 3. I want to distribute this 3 to other 3 customers equally so that they get 1 sale each.
Thanks,
Jos
Hi Jos13 ,
We can create a measure to meet your requirement.
Total Sales minus the selected Sales to get the Sales that need to be allocated.
Measure =
VAR _Total123 =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] = MAX ( 'Table'[Date] ) )
)
VAR _Total45 =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( ALL ( 'Table' ), 'Table'[Date] = MAX ( 'Table'[Date] ) )
) - _Total123
VAR _count =
CALCULATE ( DISTINCTCOUNT ( 'Table'[Customer] ), ALLSELECTED ( 'Table' ) )
VAR _sum_sales =
SUM ( 'Table'[Sales] )
RETURN
DIVIDE ( _Total45, _count ) + _sum_sales
The result like this,
If you have any question, please kindly ask here and we will try to resolve it.
BTW, pbix as attached.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Jos136 years ago
Helper III
Hi v-zhenbw-msft ,
Could you please tell why total is 23 in table ? It should be 32. The sales by customers 1,2 & 3 adding to 27 in bar chart. This should also be 32. Please help.
Regards,
Jos
- v-zhenbw-msft6 years ago
Community Support
Hi Jos13 ,
The measure Total doesn’t summarize, it is based on the calculation logic of each row.
If you want to get the correct total, we suggest to create a calculate column like this.
Column = var _C4_C5 = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Customer] in {"Customer 4","Customer 5"} && 'Table'[Date]=EARLIER('Table'[Date]))) var _avg = _C4_C5 / 3 return 'Table'[Sales] + _avgBut if you want to show the Total sales of each customer using a bar chart, you can try this Measure.
Measure = VAR _Total123 = CALCULATE ( SUM ( 'Table'[Sales] ), ALLSELECTED ( 'Table' ) ) VAR _Total45 = CALCULATE ( SUM ( 'Table'[Sales] ), ALL ( 'Table' ) ) -_Total123 VAR _count = CALCULATE ( DISTINCTCOUNT ( 'Table'[Customer] ), ALLSELECTED('Table') ) VAR _sum_sales = SUM ( 'Table'[Sales] ) RETURN _Total45 / _count + _sum_salesThe measure only displays the correct value in the current context.
If you have any question, please kindly ask here and we will try to resolve it.
BTW, pbix as attached.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.