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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Summing with filter changing each row

My data does not have a correct value for the highest level in the hierachy. The value should be calculated based on all the values belonging to the same main project.

 

I can calculate this in Excel quite easily with the following formula

=IF(A2=B2; SUMIF($A$2:$A$17;"="&B2;$C$2:$C$17); C2)

to get the desired output in the table below.

 

Main projectProject numberValueCALC
AA0-237700
AA1-134100-134100
AA2-103600-103600
BB15000-1864449,97
BB1-338250-338250
BB2-451699,98-451699,98
BB3-418999,74-418999,74
BB4-670500,25-670500,25
CC0-2013599,94
CC1-338250-338250
CC2-451699,98-451699,98
CC3-418999,98-418999,98
CC4-804649,98-804649,98
DD0-789949,98
DD1-338250-338250
DD2-451699,98-451699,98

 

I cannot figure out how to do this same calculation with Power BI. Either with the query or DAX is fine.

 

I tried using the row by row SUMX with FILTER but I am not getting a correct output.

CALC = SUMX(FILTER('Table'; 'Table'[Main project] == 'Table'[Project number]); 'Table'[Value])
Main projectProject numberValueCALC
AA015000
AA1-13410015000
AA2-10360015000
BB1500015000
BB1-33825015000
BB2-451699,9815000
BB3-418999,7415000
BB4-670500,2515000
CC015000
CC1-33825015000
CC2-451699,9815000
CC3-418999,9815000
CC4-804649,9815000
DD015000
DD1-33825015000
DD2-451699,9815000

 

How do I achieve this in Power BI?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

That did not work correctly. It gives the same value for each row. But luckily I managed to figure out a way to do it. Below table contains both calculations. Correct one in CALC and your suggestion in Measure.

 

 

CALC = SUMX(
    FILTER(
        'Table'; 
        'Table'[Main project] == EARLIER('Table'[Project number]) || 
        'Table'[Project number] == EARLIER('Table'[Project number])
        ); 
    'Table'[Value]
)

 

 

Main projectProject numberValueCALCMeasure
AA0-237700-59819198,68
AA1-134100-134100-59819198,68
AA2-103600-103600-59819198,68
BB15000-1864449,97-59819198,68
BB1-338250-338250-59819198,68
BB2-451699,98-451699,98-59819198,68
BB3-418999,74-418999,74-59819198,68
BB4-670500,25-670500,25-59819198,68
CC0-2013599,94-59819198,68
CC1-338250-338250-59819198,68
CC2-451699,98-451699,98-59819198,68
CC3-418999,98-418999,98-59819198,68
CC4-804649,98-804649,98-59819198,68
DD0-789949,98-59819198,68
DD1-338250-338250-59819198,68
DD2-451699,98-451699,98-59819198,68

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

you can try this code:

Measure =
SUMX (
    'Table';
    IF (
        'Table'[Main project] = 'Table'[Project number];
        CALCULATE (
            SUM ( 'Table'[Value] );
            FILTER (
                ALL ( 'Table' );
                'Table'[Main project] = MIN ( 'Table'[Main project] )
            )
        );
        SUM ( 'Table'[Value] )
    )
)

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Anonymous
Not applicable

That did not work correctly. It gives the same value for each row. But luckily I managed to figure out a way to do it. Below table contains both calculations. Correct one in CALC and your suggestion in Measure.

 

 

CALC = SUMX(
    FILTER(
        'Table'; 
        'Table'[Main project] == EARLIER('Table'[Project number]) || 
        'Table'[Project number] == EARLIER('Table'[Project number])
        ); 
    'Table'[Value]
)

 

 

Main projectProject numberValueCALCMeasure
AA0-237700-59819198,68
AA1-134100-134100-59819198,68
AA2-103600-103600-59819198,68
BB15000-1864449,97-59819198,68
BB1-338250-338250-59819198,68
BB2-451699,98-451699,98-59819198,68
BB3-418999,74-418999,74-59819198,68
BB4-670500,25-670500,25-59819198,68
CC0-2013599,94-59819198,68
CC1-338250-338250-59819198,68
CC2-451699,98-451699,98-59819198,68
CC3-418999,98-418999,98-59819198,68
CC4-804649,98-804649,98-59819198,68
DD0-789949,98-59819198,68
DD1-338250-338250-59819198,68
DD2-451699,98-451699,98-59819198,68

Then I misunderstood, I thought you wanted a measure, not a calculated column

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.