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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX help on allexcept

my goal is get the last two columns (avg per subgroup and avg per group) in the pivot table by using a measure instead of a calculated column

 

IDVALUESUBGROUPGROUPAVG PER SUBGROUPAVG PER GROUP
120A12027.5
210B23030
350B23030
430B23030
535C13527.5

 

I manage to do this using calculated column 

 

AVERAGE PER SUBGROUP = CALCULATE(AVERAGE(Sheet2[VALUE]),ALLEXCEPT(Sheet2,Sheet2[SUBGROUP]))
 
However when i tried to do this in a measure it calculates all the rows. 
 
what changes should i put in the measure to consider also the row context in the pivot table 
3 REPLIES 3
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,

If I understood what you are looking for in your post.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

 

Average of subgroup =
VAR _subGroup =
    MAX ( 'Table'[SUBGROUP] )
VAR _groupcount =
    CALCULATE (
        [Count of Value],
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[SUBGROUP] ),
            MAX ( 'Table'[SUBGROUP] ) = _subGroup
        )
    )
VAR _calc =
    CALCULATE (
        [Sum of Value],
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[SUBGROUP] ),
            MAX ( 'Table'[SUBGROUP] ) = _subGroup
        )
    )
VAR _average =
    DIVIDE ( _calc, _groupcount )
RETURN
    _average
-----------------------------------------

Average of group = 
VAR _Group =
    MAX ( 'Table'[GROUP] )
VAR _groupcount =
    CALCULATE (
        [Count of Value],
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[GROUP] ),
            MAX ( 'Table'[GROUP] ) = _Group
        )
    )
VAR _calc =
    CALCULATE (
        [Sum of Value],
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[GROUP] ),
            MAX ( 'Table'[GROUP] ) = _Group
        )
    )
VAR _average =
    DIVIDE ( _calc, _groupcount )
RETURN
    _average

average of group and subgroup.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi @Nathaniel_C 

 

To further complicate my example, kindly refer to the revised fact table 

 

IDVALUESUBGROUPGROUP
120A1
210B2
350B2
430B2
535C1
6 B2
7 D

2

 

IDs 6 and 7 does not have values. My endgoal actually, is to provide values for these IDs using the average values derived in either subgroup or group. Particularly for ID 6 since it belongs to the same subgroup B, it will use the average value for subgroup B which is 30. Meanwhile for ID 7, since we do not have an average value for subgroup D, we will use the the average value for group 2, which is 30 also. Hence, im quite fascinated in the use of VAR since the actual fact data that i will using contains several thousand of rows and i fear making to iteration the average calculation will make the dax process inefficient. 

Anonymous
Not applicable

Hi @Nathaniel_C 

 

Thank you for the immediate reply, can clarify just to understand the measure? i'm quite new in DAX hence please bear with me in following your suggested measure.

 

1. The average was derived by getting the sum for each of the group divided by the number of rows for each group. My question is what does 

 MAX ( 'Table'[SUBGROUP] 

return? 

2. in this particular expression

MAX ( 'Table'[SUBGROUP] ) = _subGroup

what is the difference between the two?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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