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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Robin96
Helper II
Helper II

Calculation if ID match

Hey all,

i need to create a calculation that substract an amount from table1 from table2. (Amount from table1 - amount from table2). This should be based on if the ID's match. So if Reference ID from table1 match the ID from table2, then do the substraction, else nothing.

 

i have posted a screenshot of an example.

Robin96_1-1708330984666.png

 

 

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

In the last row of the desired output table, shouldn't the answer be 300?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey, yes. The last row of Desired output should be 300. thanks for highlighting this.

Hi,

In table2, write these calculated column formulas

Table1 reference ID = calculate(max(Table1[reference ID]),filter(Table1,Table1[reference ID]=earlier(Table2[id])))

Amount = calculate(sum(Table1[amount]),filter(Table1,Table1[reference id]=earlier(Table1 reference ID)))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ryan_mayu
Super User
Super User

@Robin96 

create relationship between two tables and create two columns

Column = RELATED('Table 1'[reference id])+0

Column 2 = if(ISBLANK(sumx(FILTER('Table 1','Table 2'[id]='Table 1'[reference id]),'Table 1'[amount])),0,'Table 2'[amount]-sumx(FILTER('Table 1','Table 2'[id]='Table 1'[reference id]),'Table 1'[amount]))

11.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hey, Thanks for the response! There is no relation between these two ID's in the original semantic model. They both relate to the date table i have. Is there a way to add this link with for example TREATAS in the column syntax?

@Robin96 

then you change the column  to 

Column = maxx(FILTER('Table 1','Table 1'[id]='Table 2'[id]),'Table 1'[reference id])+0
11.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hey,

i get this response on the syntax in the DAX, what am i doing wrong here?

Robin96_0-1708952463802.png

 

your DAX is different from mine. maybe try to remove the part after "-"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors