Forum Discussion
Averages for treemap
Hi,
I want to use a Treemap chart to display how much time, on average, different people spend on different activities (see sample dataset below). The sum of the average activities should always be 40 hours. However, when an activity is missing in one of the weeks, the average is done over the weeks when the activity is present instead of average for the entire period, e.g.:
The average time for Activity B and Person 1 is calculated as (12 + 6)/2 = 9, instead of (12+0+6)/3 = 6
So in total, the sum for Person 1 gives me more than 40 hours:
Activity A: (9+10+14)/3= 11
Activity B: (12 + 6)/2 = 9
Activity C: (19+30+20)/3= 23
Total = 43 hours
and this is how it should be:
Activity A: (9+10+14)/3= 11
Activity B: (12 +0+6)/3 = 6
Activity C: (19+30+20)/3= 23
Total = 40 hours
| Person | Activity | Week Number | Hours |
| Person 1 | Activity A | Week 1 | 9 |
| Person 1 | Activity B | Week 1 | 12 |
| Person 1 | Activity C | Week 1 | 19 |
| Person 1 | Activity A | Week 2 | 10 |
| Person 1 | Activity C | Week 2 | 30 |
| Person 1 | Activity A | Week 3 | 14 |
| Person 1 | Activity B | Week 3 | 6 |
| Person 1 | Activity C | Week 3 | 20 |
| Person 2 | Activity A | Week 1 | 5 |
| Person 2 | Activity B | Week 1 | 15 |
| Person 2 | Activity C | Week 1 | 20 |
| Person 2 | Activity A | Week 3 | 5 |
| Person 2 | Activity B | Week 3 | 5 |
| Person 2 | Activity C | Week 3 | 30 |
I am using this measure but it is obviously not working:
A very same problem was described in this thread but it was not answered: https://community.fabric.microsoft.com/t5/Desktop/Treemap-summarization-of-a-quick-measure/m-p/2695631#M943325
Thanks in advance!
- Anonymous2 years ago
Hi Aethelson
You can try the following measure.
Average Hour = VAR a = CALCULATE ( DISTINCTCOUNT ( 'Merged queries'[Activity] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[Person] IN VALUES ( 'Merged queries'[Person] ) ) VAR b = CALCULATE ( SUM ( 'Merged queries'[Hours] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[Person] IN VALUES ( 'Merged queries'[Person] ), 'Merged queries'[Activity] IN VALUES ( 'Merged queries'[Activity] ) ) RETURN DIVIDE ( b, a )Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi Aethelson
You can try the following measure.
Average Hour = VAR a = CALCULATE ( DISTINCTCOUNT ( 'Merged queries'[Activity] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[Person] IN VALUES ( 'Merged queries'[Person] ) ) VAR b = CALCULATE ( SUM ( 'Merged queries'[Hours] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[Person] IN VALUES ( 'Merged queries'[Person] ), 'Merged queries'[Activity] IN VALUES ( 'Merged queries'[Activity] ) ) RETURN DIVIDE ( b, a )Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AethelsonNew Member
Hi Yolo Zhu
I had to modify the formula a bit (changing distinctcount from Activity to Week number), as it still didn't return 40 hours for Person 2 but it now works like a charm! Thanks a lot, you saved me many hours.Average Hour = VAR a = CALCULATE ( DISTINCTCOUNT ( 'Merged queries'[Week Number] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[person] IN VALUES ( 'Merged queries'[person] ) ) VAR b = CALCULATE ( SUM ( 'Merged queries'[Hours] ), ALLSELECTED ( 'Merged queries' ), 'Merged queries'[name] IN VALUES ( 'Merged Queries'[Name] ), 'Merged Queries'[activity] IN VALUES ( 'Merged Queries'[activity] ) ) RETURN DIVIDE ( b, a )