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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Marcus-G
Frequent Visitor

Measure or Formating to calculate the difference between 2 columns on 2 tables but share same codes

Hey! Ive been wracking my head on this and trying to find some help. So I have a 2 reports that pull directly out of our accounting program and the 2 tables are for sales invoices and sales credits. 

 

I am trying to find a way to create a single table that has it calculated but it always results in some strange numbers that dont match.

 

The tables do share the same items codes and want to calculate the total difference when selecting different filters for reporting purposes. 

 

The Outcome is I want a table that looks like below but im not sure what im missing to match it. 

Screenshot 2024-09-25 151826.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Marcus-G ,

 

As per your description, I have created two tables.

vkaiyuemsft_0-1727683669346.pngvkaiyuemsft_1-1727683679326.png

 

You can refer to the following steps.
1. create relationship for both tables.

vkaiyuemsft_2-1727683695512.png


2.Create measure and calculate the sum separately.

sumCredit =
CALCULATE(SUM(SalesCredits[Amount]),FILTER(ALL(SalesCredits),'SalesCredits'[ItemCode] = MAX('SalesCredits'[ItemCode])))

 

sumInvoice =
CALCULATE(SUM(SalesInvoices[Amount]),FILTER(ALL(SalesInvoices),'SalesInvoices'[ItemCode] = MAX('SalesInvoices'[ItemCode])))

 

3. Create the measure and calculate the difference.

diff =
[sumInvoice] - [sumCredit]

vkaiyuemsft_3-1727683747941.png

 

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Marcus-G ,

 

As per your description, I have created two tables.

vkaiyuemsft_0-1727683669346.pngvkaiyuemsft_1-1727683679326.png

 

You can refer to the following steps.
1. create relationship for both tables.

vkaiyuemsft_2-1727683695512.png


2.Create measure and calculate the sum separately.

sumCredit =
CALCULATE(SUM(SalesCredits[Amount]),FILTER(ALL(SalesCredits),'SalesCredits'[ItemCode] = MAX('SalesCredits'[ItemCode])))

 

sumInvoice =
CALCULATE(SUM(SalesInvoices[Amount]),FILTER(ALL(SalesInvoices),'SalesInvoices'[ItemCode] = MAX('SalesInvoices'[ItemCode])))

 

3. Create the measure and calculate the difference.

diff =
[sumInvoice] - [sumCredit]

vkaiyuemsft_3-1727683747941.png

 

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

PhilipTreacy
Super User
Super User

@Marcus-G 

 

Please provide your source data (or at least  a representative sample of it) - I can't give you a solution without the source data to work with.

 

Please provide a file or a table pasted in here, not an image.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors