Forum Discussion
Average calculation
Hi all! I want to calculate an average this way
I have this table:
| Code | Period | Hours |
| 5125 | 201902 | 2 |
| 5125 | 201903 | 4 |
| 5125 | 201903 | 6 |
| 5125 | 201904 | 3 |
| 5125 | 201905 | 4 |
So, if I calculate it with the average function the calculation would be like this:
(2+4+6+3+4)/5 = 3,8
But I don't want this way of calculating it. The way I want is, first, calculating the average per period and finally calculating the average of those averages. Example:
Avg 2019/02 = 2
Avg 2019/03 = 5
Avg 2019/04 = 3
Avg 2019/04 = 4
So the final average would be 4,25 -> (2+5+3+4)/4
Any idea of how to solve it?
Thank you all!!
- Anonymous4 years ago
Hi pva
How did you get 4.5 when you use (2+5+3+4)/4 ? The correct answer is 3.5 .
For 5125 , the final result is 3.5 -> ((4+6)/2+2+3+4)/4 .For 2147 , the final result is 4.667 -> ((2+4)/2+8+3)/3 . So the final average is 4.08 ->(3.5+4.667)/2
To realize the final average , you need to nest an AVERAGEX() outside the formula provided by SU .
Avg =AVERAGEX(VALUES('Table'[Code]),calculate(AVERAGEX(VALUES('Table'[Period]),CALCULATE(AVERAGE('Table'[Hours])))))The final result is as shown :
I have attached my pbix file , you can refer to it .
Best Regard
Community Support Team _ Ailsa Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- parry2kSuper User
pva try this measure
Avg = AVERAGEX ( VALUES ( Table[Period] ), CALCULATE ( AVERGAGE ( Table[Hours] ) ) )✨ Follow us on LinkedIn and to our YouTube channel
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.
- pvaFrequent Visitor
Thank for your help. In the table there are more codes. The table would be like this:
Code Period Hours 5125 201902 2 5125 201903 4 5125 201903 6 5125 201904 3 5125 201905 4 2147 201902 2 2147 201902 4 2147 201903 8 2147 201904 3 So the global average should be:
5125 -> 4,25
2147 -> 3,66 (2+((4+8)/2)+3)/3
Total avg = (4,25+3,66)/2 = 3,955
- AnonymousNot applicable
Hi pva
How did you get 4.5 when you use (2+5+3+4)/4 ? The correct answer is 3.5 .
For 5125 , the final result is 3.5 -> ((4+6)/2+2+3+4)/4 .For 2147 , the final result is 4.667 -> ((2+4)/2+8+3)/3 . So the final average is 4.08 ->(3.5+4.667)/2
To realize the final average , you need to nest an AVERAGEX() outside the formula provided by SU .
Avg =AVERAGEX(VALUES('Table'[Code]),calculate(AVERAGEX(VALUES('Table'[Period]),CALCULATE(AVERAGE('Table'[Hours])))))The final result is as shown :
I have attached my pbix file , you can refer to it .
Best Regard
Community Support Team _ Ailsa Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.