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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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