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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Mohammadwazeri
Helper III
Helper III

How to Do Subtraction & Addition Using Tables With No Direct Relationship Using DAX?

Hi Guys,

I want to create a measure to subtract and add the columns from the tables with no direct relationship, see the screenshot below.

 

After some search on the internet, I created the below measure, BUT it doesn't work properly when I use it with the column 'Sales Invoice'[Aging Bucket]. It shows the $ values way too big.

 

Balance Due = 

VAR __IN_Invoice_Amnt = SUM('Sales Invoice'[Ivoice Amnt])

VAR __IN_Balance = SUM('Incoming Payment'[IN_Balance])

VAR __CN_Balance = SUM('Credit Memo'[CM_Balance])

VAR __DT_Balance = SUM('Down Payment'[DP_Balance])

RETURN

    ((__IN_Balance_Due - __RC_OpenBalSc) - __CN_Open_Balance) + __DT_Balance_Due
 
Can some one please give me some light on this?
 
Mohammadwazeri_0-1680013428942.png

 

Thank you,

Mohammad

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@Mohammadwazeri I guess first question would be why you can't create those relationships. But, you should be able to do something like this:

VAR __PBCustomers = DISTINCT('Customer'[PBCustomerKey])

VAR __Invoices = SUMX(FILTER('Sales Invoice'), [PBCustomerKey] IN __PBCustomers),[Invoice Amt])

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

I am not sure, I am following it. 

Would you mind writing the whole calculation?

 

Thanks,

Mohammad

@Mohammadwazeri 

Balance Due = 
VAR PBCustomers = DISTINCT('Customer'[PBCustomerKey])

VAR Customers = DISTINCT('Customer'[Customer_Key])

VAR IN_Invoice_Amt = SUMX(FILTER('Sales Invoice'), [PBCustomerKey] IN PBCustomers),[Invoice Amt])

VAR IN_Balance = SUMX(FILTER('Incoming Payment', [Customer_Key] IN Customers), [IN_Balance])

VAR CN_Balance = SUMX(FILTER('Credit Memo', [PBCustomerKey] IN PBCustomers),[CM_Balance])

VAR DT_Balance = SUMX(FILTER('Down Payment', [PBCustomerKey] IN PBCustomers),[DP_Balance])

RETURN

    ((IN_Balance_Due - RC_OpenBalSc) - CN_Open_Balance) + DT_Balance_Due

That said, this line in your code doesn't seem to correspond to known VARs

((IN_Balance_Due - RC_OpenBalSc) - CN_Open_Balance) + DT_Balance_Due



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you @Greg_Deckler  for your quick reply!

 

I tried to use the "Balance Due" with the 'Sales Invoice'[Aging Bucket], but now it is adding every values for every aging bucket this is the main problem.

 

Mohammadwazeri_0-1680019202788.png

 

Helpful resources

Announcements
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.

Top Solution Authors