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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
webportal
Impactful Individual
Impactful Individual

Sum values of a column with two conditions

Tables A and B below are related by ID:

 

webportal_0-1615805211223.png

 

 

I want to add the "Value" column per ID - with the following conditions:

1-Valid = TRUE

2-Value >0 on aggregate.

 

That is,  I'm expecting the results:

 

123 = -158, so it will not be added

456  is FALSE, so it will not be added

789 = 177. It will be added.

 

So, the end result is 177.

1 ACCEPTED SOLUTION

Hey @webportal ,

 

thank you very much, providing the file helped a lot.

 

I found my error, I filtered "Table B" wrong, so that we did the sum on duplicated rows.

I could solve that by summarizing by ID.

 

Please check the corrected measure, that should hopefully solve your problem:

Value Table B = 
VAR _table =
    FILTER(
        ADDCOLUMNS(
            SUMMARIZE(
                FILTER( 'Table B', RELATED( 'Table A'[Valid] ) = TRUE ),
                'Table B'[ID]
            ),
            "SumValue", CALCULATE( SUM( 'Table B'[Value] ) )
        ),
        [SumValue] >= 0
    )
VAR result =
    SUMX( _table, [SumValue] )
RETURN
    result

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi

View solution in original post

8 REPLIES 8
webportal
Impactful Individual
Impactful Individual

@selimovd 

Here's the link to the PBIX.

Hey @webportal ,

 

thank you very much, providing the file helped a lot.

 

I found my error, I filtered "Table B" wrong, so that we did the sum on duplicated rows.

I could solve that by summarizing by ID.

 

Please check the corrected measure, that should hopefully solve your problem:

Value Table B = 
VAR _table =
    FILTER(
        ADDCOLUMNS(
            SUMMARIZE(
                FILTER( 'Table B', RELATED( 'Table A'[Valid] ) = TRUE ),
                'Table B'[ID]
            ),
            "SumValue", CALCULATE( SUM( 'Table B'[Value] ) )
        ),
        [SumValue] >= 0
    )
VAR result =
    SUMX( _table, [SumValue] )
RETURN
    result

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi

webportal
Impactful Individual
Impactful Individual

@selimovd 

Thanks for your help. I just don't like the RELATED, but it worked!

Hey @webportal ,

 

what is the issue with RELATED?

 

Best regards

Denis

webportal
Impactful Individual
Impactful Individual

Nothing, it is just expensive, memory-wise, that's all 🙂

webportal
Impactful Individual
Impactful Individual

@selimovd 

Thanks, but I don't think it is working..

 

webportal_0-1615812172052.png

 

 

I'm expecting to obtain 177 from ID = 789

Hey @webportal ,

 

step by step, we will find the mistake 😉

Can you send me a screenshot of the Table B, if you want filtered to product 789 and a screenshot of the relationship between Table A and Table B?

 

Thank you and best regards

Denis

selimovd
Super User
Super User

Hello @webportal ,

 

try the following measure:

Value Table B =
VAR _table =
    FILTER(
        ADDCOLUMNS(
            FILTER( VALUES( 'Table B' ), RELATED( 'Table A'[Valid] ) = TRUE ),
            "SumValue", CALCULATE( SUM( 'Table B'[Value] ) )
        ),
        [SumValue] >= 0
    )
VAR result =
    SUMX( _table, [SumValue] )
RETURN
    result

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

Top Solution Authors