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
Anonymous
Not applicable

custom aggregation in matrix not working

I have a matrix with 3 levels:

 

I have a custom aggregation, working fine, the dax code is:

 

 

 

 

 

 

 

 

FixedCosts = SUM('Table'[FCosts])
VariableCosts = SUM('Table'[VCosts]) 

 

Then create 2 measures:

 

Basic =
VAR _sumat = [FixedCosts] + [VariableCosts]
VAR _sumlevel2 =
    IF ( _sumat < 0, 0, _sumat )
RETURN
    IF (
        ISINSCOPE ( 'Table'[Level3] ),
        _sumat,
        IF ( ISINSCOPE ( 'Table'[Comp] ), _sumlevel2 )
    )
Result =
VAR _LEVEL1 =
    SUMX (
        SUMMARIZE (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Proj] = MAX ( 'Table'[Proj] )
                    && 'Table'[Comp] IN VALUES ( 'Table'[Comp] )
            ),
            'Table'[Proj],
            'Table'[Comp]
        ),
        [Basic]
    )
RETURN
    IF ( ISINSCOPE ( 'Table'[Proj] ), _LEVEL1, [Basic] )

 

 

 

 

 

I want to add a higher level, that would just a simple SUM, but I am unable...

 

I tried re-writing the MEASURE as:

 

Result =
VAR _LEVEL1 =
    SUMX (
        SUMMARIZE (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Proj] = MAX ( 'Table'[Proj] )
                    && 'Table'[Comp] IN VALUES ( 'Table'[Comp] )
            ),
            'Table'[Proj],
            'Table'[Comp]
        ),
        [Basic]
    )






VAR Higher_Level=
    SUMX (
        SUMMARIZE (
            FILTER (
                ALL ( 'Client' ),
                'Client'[Name] = MAX ( 'Client'[Name] )
                    && 'Table'[Proj] IN VALUES ( 'Table'[Proj] )
            ),
            'Client'[Name],
            'Table'[Proj]

        ),
        [Basic]
    )





RETURN
    IF ( ISINSCOPE ( 'Table'[Proj] ), _LEVEL1, [Basic] )
    IF ( ISINSCOPE (  'Client'[Name]), Higher_Level, [Basic] )

 

 

but of course in the ALL ('Client') I am forced to use only one table, so I am not sure how to do it..

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.

vtangjiemsft_0-1669706720994.png

(2) We can create a calculated column.

 

Column = 
VAR _level2 =
    CALCULATE (
        SUM ( 'Table'[value] ),
        ALLEXCEPT ( 'Table','Table'[level2] )
    )
RETURN
    IF ( _level2 > 0, 0, _level2 )

 

(3)Then we can create a measure.

 

Measure = 
SWITCH (
    TRUE (),
    ISINSCOPE ( 'Table'[level3]), SUM ('Table'[value] ),
    SUM ( 'Table'[Column] )
)

 

(4) Then the result is as follows.

vtangjiemsft_1-1669706774670.png

 

Best Regards,

Neeko Tang

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.

vtangjiemsft_0-1669706720994.png

(2) We can create a calculated column.

 

Column = 
VAR _level2 =
    CALCULATE (
        SUM ( 'Table'[value] ),
        ALLEXCEPT ( 'Table','Table'[level2] )
    )
RETURN
    IF ( _level2 > 0, 0, _level2 )

 

(3)Then we can create a measure.

 

Measure = 
SWITCH (
    TRUE (),
    ISINSCOPE ( 'Table'[level3]), SUM ('Table'[value] ),
    SUM ( 'Table'[Column] )
)

 

(4) Then the result is as follows.

vtangjiemsft_1-1669706774670.png

 

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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