Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
tomas12344
Helper III
Helper III

calculate average from aggregated values

HI All
Custome want a report, where the average is calcualted from aggregated values not from detail values of the table. 
The report table contains some hierarchies, base on which the data should be aggregated, so that the average is calcualted from these values.
Here some example data

tomas12344_0-1697208301026.png

This is the important part, what is not working, avg is calcualted from detail data

tomas12344_1-1697208351213.png

In this case, the levels a\a\a-c and the level a\b (in the picture pink marked) are calcualted correctly. the avg on level a\a is as it  should be the sum is 60 and count is 3, so the avg is 20. that is correct. similar for level a\b, sum is 60 and 2 rows, avg is correct 30.

But when collapsing to the a\a level, like bellow, this is correct when calcualting from detail data, but not with aggregated:

tomas12344_2-1697208585774.png

in this case (yellow in picture), this is not correct, base on aggregated values. There should be calcualted:
Sum is OK 120, number of cases should be 2 - that is equal to collaped levels a\a and a\b. So here i would need to have calcualted teh average as 120/2=60.
I think i shodl somehow use the Summarize function, but I did not found the correct way. The second thing is, that the results need to be merged within the table to the hierarchies (there is a summary table wich contains hierarchies and some detail sums of the amounts)

Thank you for help.

3 REPLIES 3
tomas12344
Helper III
Helper III

HI @amitchandak @Anonymous 

Thank you for the reply, but I'm not sure, that the results are correct. I have little bit experimented, and found out, that when I use two Summarize function, it will provide correct avg calcualtion. 

tomas12344_0-1697552330010.png

Currently, I dont know, how to connect this together, into the first matrix table( I mean the first table in the picture and the third, which shows correct avg values, as the user wants).

Anonymous
Not applicable

Hi  @tomas12344 ,

 

Here are the steps you can follow:

1. Create measure.

Avg_Measure =
IF(
    ISINSCOPE('Table'[c]) || ISINSCOPE('Table'[b]),AVERAGEX(
    'Table',[sum]),
        IF(
            ISINSCOPE('Table'[a]),
            DIVIDE(           SUMX(FILTER(ALL('Table'),'Table'[date]=MAX('Table'[date])&&'Table'[a]=MAX('Table'[a])),[sum])  CALCULATE(DISTINCTCOUNT('Table'[b]),FILTER(ALL('Table'),'Table'[date]=MAX('Table'[date])))),
            IF(
                ISINSCOPE('Table'[date]),
              DIVIDE(
            SUMX(FILTER(ALL('Table'),'Table'[date]=MAX('Table'[date])),[sum]),            CALCULATE(DISTINCTCOUNT('Table'[a]),FILTER(ALL('Table'),'Table'[date]=MAX('Table'[date])))),
            DIVIDE(
            SUMX(ALL('Table'),[sum]),
            CALCULATE(DISTINCTCOUNT('Table'[date]),ALL('Table'))))))

2. Result:

vyangliumsft_0-1697435687172.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@tomas12344 , seem like you need Avg of sum

 

Averagex(Values(Table[Level1]), calculate(Sum(Table[Value])) )

 

The values will be avg above "Level1" , field

 

Avg of Sum : https://youtu.be/cN8AO3_vmlY?t=22980

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.