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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
gvg
Post Prodigy
Post Prodigy

Average calculation by criteria

Hi,

 

I would like to calculate average of Amount by some specific column in the same table. Thought this was simple, but I get strange results with this measure, which, I would expect, should do the job:

 

Calculated Average = CALCULATE(AVERAGE(Table1[Amount]),Table1[DocNo])

This is my source table and the result. Why the measure refuses to calculate average on DocNo, and instead arbitrarily calculates average on Manager?

 

Untitled.jpg

I am expecting Calculated Average to be like this regardless of Manager field:

 

Manager   DocNo       Calculated Average

John          322            35

John          566            20

Peter         123            10

Sam           322            35

-----------------------------

Total:                           21.7      

 

21.7 being  (35 + 20 + 10) / 3. Standard Quick Measure comes up with 33 in this case.

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @gvg

 

Try this MEASURE

 

Calculated_Average =
IF (
    HASONEFILTER ( Table1[DocNo] ),
    CALCULATE ( AVERAGE ( Table1[Amount] ), ALLEXCEPT ( Table1, Table1[DocNo] ) ),
    AVERAGEX (
        VALUES ( Table1[DocNo] ),
        CALCULATE ( AVERAGE ( Table1[Amount] ), ALLEXCEPT ( Table1, Table1[DocNo] ) )
    )
)

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @gvg

 

Try this MEASURE

 

Calculated_Average =
IF (
    HASONEFILTER ( Table1[DocNo] ),
    CALCULATE ( AVERAGE ( Table1[Amount] ), ALLEXCEPT ( Table1, Table1[DocNo] ) ),
    AVERAGEX (
        VALUES ( Table1[DocNo] ),
        CALCULATE ( AVERAGE ( Table1[Amount] ), ALLEXCEPT ( Table1, Table1[DocNo] ) )
    )
)

Yep, this works like charm. Thank you !

@gvg

 

Actually your MEASURE is equivalent to

 

CalculatedAverage = CALCULATE(AVERAGE(Table1[Amount]),ALL(Table1[DocNo]))

The Calculate Expression

 

CALCULATE (
    <expression>,
    table[column] = <value>
)

is internally transformed into

 

CALCULATE (
    <expression>, 
    FILTER (
        ALL ( table[column] ),
        table[column] = <value> 
    )
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.