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
dancarr22
Helper V
Helper V

Measure totals and subtotals incorrect - tried HASONEFILTER but still not working

Hello,

 

I have a measure which is grouping fields and then summing.  Then taking the average of those summed values. 

That works for initial groupings but not for subtotals and grand totals.  Need those to calculate average of sums also.

I know there are quite a few explanations of this online - have tried various fixes using HASONEFILTER but haven't worked.  

Need average of subtotals/totals at the Firm and MatterType level.  

Any help appreciated.  

 

 

ByMatterTypeAndFirm_Average = 
AVERAGEX(
    ADDCOLUMNS(
        SUMMARIZE(
            LT,LT[Firm],LT[Matter],LT[Matter Type]),
        "@Amount", CALCULATE(SUM(LT[Total Amount Billed]))),
    [@Amount]
)

 

 

Thanks,

Dan

1 ACCEPTED SOLUTION
daxer-almighty
Solution Sage
Solution Sage

 

// These helper measures should be hidden.
[_HelperMeasure1] =
    SUM( LT[Total Amount Billed] )
[_HelperMeasure2] = 
    AVERAGEX(
        DISTINCT( LT[Matter Type] ),
        [_HelperMeasure1]
    )
[_HelperMeasure3] =
    AVERAGEX(
        DISTINCT( LT[Firm] ),
        [_HelperMeasure2]
    )

// This measure will work correctly only
// with the hierarchy.
ByMatterTypeAndFirm_Average =
switch( true(),
    // You might need to swap the 2nd and 3rd
    // condition depending on the hierarchy
    // you have. I've assumed you've got
    // a hierarchy of Firm > Matter Type > Matter.
    ISINSCOPE( LT[Matter] ), [_HelperMeasure1],
    ISINSCOPE( LT[Matter Type] ), [_HelperMeasure1],
    ISINSCOPE( LT[Firm] ), [_HelperMeasure2],
    [_HelperMeasure3]
)

 

View solution in original post

3 REPLIES 3
daxer-almighty
Solution Sage
Solution Sage

 

// These helper measures should be hidden.
[_HelperMeasure1] =
    SUM( LT[Total Amount Billed] )
[_HelperMeasure2] = 
    AVERAGEX(
        DISTINCT( LT[Matter Type] ),
        [_HelperMeasure1]
    )
[_HelperMeasure3] =
    AVERAGEX(
        DISTINCT( LT[Firm] ),
        [_HelperMeasure2]
    )

// This measure will work correctly only
// with the hierarchy.
ByMatterTypeAndFirm_Average =
switch( true(),
    // You might need to swap the 2nd and 3rd
    // condition depending on the hierarchy
    // you have. I've assumed you've got
    // a hierarchy of Firm > Matter Type > Matter.
    ISINSCOPE( LT[Matter] ), [_HelperMeasure1],
    ISINSCOPE( LT[Matter Type] ), [_HelperMeasure1],
    ISINSCOPE( LT[Firm] ), [_HelperMeasure2],
    [_HelperMeasure3]
)

 

Thanks @daxer-almighty  - that fixed it.  
One interesting thing (which I'm not sure about) is for the initial variables which you said to hide - and I did and it worked.  Then I tried including them directly in the main formula as VAR(iables) and then referenced those VAR values.  But that didn't work.
Anyways, your solution worked!  Appreciate your help.

Dan

@dancarr22 

 

"One interesting thing (which I'm not sure about) is for the initial variables which you said to hide..."

 

They are not variables, they are measures. A completely different thing.

 

"Then I tried including them directly in the main formula as VAR(iables) and then referenced those VAR values.  But that didn't work."

 

That did not work because variables in DAX are static. Once calculated, they don't change, so applying any filters to them and/or using them in context transition scenarios do not affect their values.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.