Forum Discussion

pva's avatar
pva
Frequent Visitor
4 years ago
Solved

Average calculation

Hi all! I want to calculate an average this way

 

I have this table:

 

 

CodePeriodHours
51252019022
51252019034
51252019036
51252019043
51252019054

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!!

  • Anonymous's avatar
    Anonymous
    4 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

  • 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.

    • pva's avatar
      pva
      Frequent Visitor

      Thank for your help. In the table there are more codes. The table would be like this:

      CodePeriodHours
      51252019022
      51252019034
      51252019036
      51252019043
      51252019054
      21472019022
      21472019024
      21472019038
      21472019043

       

      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

  • Anonymous's avatar
    Anonymous
    Not 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.