Forum Discussion
Conditional SUM based on related table
Hi Everyone,
Was hoping someone could help me out here. I built a measure that sums based on a condition from another table. The structure is as follows
Transaction Table
Columns: Transaction ID, Total Amount, Code
Codes Table
Columns:
Code, Classification
The Code Table lists down all the Code and it's respective clasification which could be either "Valid", "Pending", "Ignore" or "Void". I setup the relationship between the tables and now I want to SUM all amounts which does not include "Ignore" and "Void". This would also include Codes that have not been classified (i.e. Code does not exists on the Code table)
- Anonymous4 years ago
Hi Imrans123 ,
Try this code.
Outstanding Amount = CALCULATE ( SUM ( 'Transaction'[Total Amount] ), FILTER ( ALL ( Codes ), NOT Codes[Classification] IN { "Ignore", "Void" } ) )Here I build a sample to have a test.
Transaction Table:
Codes Table:
Based on your logic result should be A+B+E = 200+100+300+50 = 650. Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- Ashish_Mathur
Super User
Hi,
Could you illustrate with an example. Which are the ones being left out?
- AnonymousNot applicable
Hi Imrans123 ,
Try this code.
Outstanding Amount = CALCULATE ( SUM ( 'Transaction'[Total Amount] ), FILTER ( ALL ( Codes ), NOT Codes[Classification] IN { "Ignore", "Void" } ) )Here I build a sample to have a test.
Transaction Table:
Codes Table:
Based on your logic result should be A+B+E = 200+100+300+50 = 650. Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.