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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
alya1
Helper V
Helper V

Sum 2 rows if ID and subtract from ID columns match?

Hello, 
I have table as below:

ID  Amount  Subtract from ID  
1-1003
2200 
3300 
4-502
5-103

 

Can I get to the goals table below in power bi? 
Goals:

ID  Amount  Subtract from ID  Final
1-10030
2200 150
3300 50
4-5020
5-15030
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @alya1 

Based on your description, I created a measure using the following DAX:

Result =
VAR _ID =
    SELECTEDVALUE ( 'Table'[ID  ] )
VAR _table =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[ID  ],
        'Table'[Subtract from ID  ],
        'Table'[Amount  ]
    )
VAR _amount =
    SELECTEDVALUE ( 'Table'[Amount  ] )
VAR _blank =
    FILTER ( _table, 'Table'[Subtract from ID  ] = _ID )
RETURN
    IF (
        _ID IN SELECTCOLUMNS ( _blank, 'Table'[Subtract from ID  ] ),
        _amount + SUMX ( _blank, 'Table'[Amount  ] ),
        0
    )

 Put the corresponding column and this measure in the table visual, and the result is as follows:

vjianpengmsft_0-1718245154720.png

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

4 REPLIES 4
Anonymous
Not applicable

Hi, @alya1 

Based on your description, I created a measure using the following DAX:

Result =
VAR _ID =
    SELECTEDVALUE ( 'Table'[ID  ] )
VAR _table =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[ID  ],
        'Table'[Subtract from ID  ],
        'Table'[Amount  ]
    )
VAR _amount =
    SELECTEDVALUE ( 'Table'[Amount  ] )
VAR _blank =
    FILTER ( _table, 'Table'[Subtract from ID  ] = _ID )
RETURN
    IF (
        _ID IN SELECTCOLUMNS ( _blank, 'Table'[Subtract from ID  ] ),
        _amount + SUMX ( _blank, 'Table'[Amount  ] ),
        0
    )

 Put the corresponding column and this measure in the table visual, and the result is as follows:

vjianpengmsft_0-1718245154720.png

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Hi Jianpeng, thank you so much for the clean and effective DAX! 
May I ask you to please explain the steps please? specifically VAR _table and the RETURN line please.

Anonymous
Not applicable

Hi, @alya1 

Thank you very much for your reply. First_ID returns the ID of the current table visual row, _amount something similar:

vjianpengmsft_0-1718333729341.png

_table generates a table of variables that looks like this:

vjianpengmsft_1-1718333834061.png

_blank returns a table of variables that contains only the current _ID. Finally, use the SELECTCOLUMNS method to select the ID column of the _blank table, and then determine whether the _ID of the current row is in this column. If the current ID is in this table, then the amount corresponding to the current ID + the amount that matches it. That's what you're looking for.

 

 

Best Regards

Jianpeng Li

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

 

 

Thank you Jianpeng!! 

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.