Forum Discussion
Weighted Average Recalculation when filtered
Good Evening,
I am trying to work out the contribution of the calculation of Days taken to pay when I apply various filters.
looking at the total data set, I have a column in Power Query that calculates the Contribution
Power Query Added Column:
= Table.AddColumn(#"Changed Type1", "Contribution", each [Days]/List.Sum(#"Changed Type1"[Days]) * List.Average(#"Changed Type1"[Days]))
I think because this is essentially hard coded its not dynamic so when i want to view differently it doesnt give me the correct output.
When i look at the full year data i get an average (Calculated Field Contribution) of 12.9 days.
If in POWER BI i then use a filter to only look at Q1 for example it incorrectly shows me 3.1 days instead of 12.5 days.
I have copied sample data below and how i expected it to calculate, apologies the format does not look the best i was unsure how to add as an attachment.
I would like to create a measure in Power BI that is dynamic and ideally remove the calculated column, however the file still operates at a good speed if i need to keep it.
Any help would be appreciated as i have been trying to solve this for about a week.
| Full Year View | Annual View | |||||||||
| Terms | Quarter | Days | CALCULATED FIELD Contribution | Quarterly Summary | Contribution | |||||
| A10 | Q1 | 7 | 0.22 | Q1 | 100 | 3.1 | ||||
| A10 | Q2 | 8 | 0.25 | Q2 | 92 | 2.9 | ||||
| A10 | Q3 | 8 | 0.25 | Q3 | 85 | 2.7 | ||||
| A10 | Q4 | 7 | 0.22 | Q4 | 137 | 4.3 | ||||
| A10 | Q1 | 8 | 0.25 | 414 | 12.9 | |||||
| A10 | Q4 | 7 | 0.22 | |||||||
| A10 | Q1 | 7 | 0.22 | looking at specific quarters | ||||||
| A10 | Q2 | 8 | 0.25 | Q1 | 100 | 12.5 | ||||
| A10 | Q3 | 7 | 0.22 | Q2 | 92 | 13.14 | ||||
| A10 | Q4 | 7 | 0.22 | |||||||
| A10 | Q1 | 8 | 0.25 | Reference | Terms | Quarter | Days | Contribution | ||
| A10 | Q2 | 7 | 0.22 | A | A10 | Q1 | 7 | 0.88 | ||
| A10 | Q3 | 8 | 0.25 | A | A10 | Q1 | 8 | 1.00 | ||
| A10 | Q4 | 7 | 0.22 | A | A10 | Q1 | 7 | 0.88 | ||
| Z20 | Q1 | 6 | 0.19 | A | A10 | Q1 | 8 | 1.00 | ||
| Z20 | Q2 | 8 | 0.25 | B | Z20 | Q1 | 6 | 0.75 | ||
| Z20 | Q3 | 3 | 0.09 | B | Z20 | Q1 | 8 | 1.00 | ||
| Z20 | Q4 | 7 | 0.22 | C | Z20 | Q1 | 49 | 6.13 | ||
| Z20 | Q1 | 8 | 0.25 | C | A10 | Q1 | 7 | 0.88 | ||
| Z20 | Q2 | 7 | 0.22 | Total Days | 100 | 12.50 | ||||
| Z20 | Q3 | 8 | 0.25 | Average Days | 12.5 | |||||
| Z20 | Q4 | 37 | 1.16 | |||||||
| Z20 | Q1 | 49 | 1.53 | |||||||
| Z20 | Q2 | 46 | 1.44 | |||||||
| Z20 | Q3 | 43 | 1.34 | Reference | Terms | Quarter | Days | CALCULATED FIELD Contribution | ||
| A10 | Q4 | 43 | 1.34 | A | A10 | Q2 | 8 | 1.14 | ||
| A10 | Q1 | 7 | 0.22 | A | A10 | Q2 | 8 | 1.14 | ||
| A10 | Q2 | 8 | 0.25 | A | A10 | Q2 | 7 | 1.00 | ||
| A10 | Q3 | 8 | 0.25 | B | Z20 | Q2 | 8 | 1.14 | ||
| A10 | Q4 | 7 | 0.22 | B | Z20 | Q2 | 7 | 1.00 | ||
| A10 | Q4 | 8 | 0.25 | C | Z20 | Q2 | 46 | 6.57 | ||
| A10 | Q4 | 7 | 0.22 | C | A10 | Q2 | 8 | 1.14 | ||
| Total Days | 92 | 13.14 | ||||||||
| Total Days | 414 | 12.94 | Average Days | 13.14286 |
Hi Anonymous ,
You can add another filter condition in the formula:
Measure_Contribution = CALCULATE ( AVERAGE ( 'Table'[Days] ), FILTER ( ALLSELECTED ( 'Table'[Quarter] ), 'Table'[Quarter] IN DISTINCT ( 'Table'[Quarter] ) && 'Table'[Terms] IN DISTINCT ( 'Table'[Terms] ) ) )Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.Hi Anonymous ,
You should want to correct the total value so that the values in the matrix shows the average value, and the total shows the sum value.
Besides the average measure previous and the second measure you have created by yourself, you can create this measrue to combine them to adjust the column total value in matrix:
Re = IF ( HASONEVALUE ( 'Table'[Terms] ), [Average_Contribution], [Sum_Contribution] )The result and the comparsion should be like this:
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
8 Replies
- v-yingjlCommunity Support
Hi Anonymous ,
You can create a measure like this:
Measure_Contribution = CALCULATE ( AVERAGE ( 'Table'[Days] ), FILTER ( ALLSELECTED ( 'Table'[Quarter] ), 'Table'[Quarter] IN DISTINCT ( 'Table'[Quarter] ) ) )Attached a sample file in the below, hopes it could help.
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- AnonymousNot applicable
v-yingjl thank you that works well. One more questions if you dont mind. Is their a way to get it to perform correctly when i add in Terms to the table, or so i need to create a seperate measure to analyse Contribution against the Terms?
I have added a screen shot of the amended view below.
Thank you very much, thats a great help already.- v-yingjlCommunity Support
Hi Anonymous ,
You can add another filter condition in the formula:
Measure_Contribution = CALCULATE ( AVERAGE ( 'Table'[Days] ), FILTER ( ALLSELECTED ( 'Table'[Quarter] ), 'Table'[Quarter] IN DISTINCT ( 'Table'[Quarter] ) && 'Table'[Terms] IN DISTINCT ( 'Table'[Terms] ) ) )Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.