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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tsql_simon
Advocate I
Advocate I

Sum If Header Table Value <> Sum of Details Table Values

SO I have two tables Bills and Payments, Each customer has One bill and they pay it off in stages over the Year, I am trying to get to the amount Unpaid BUT not count any bills which may have been over paid.

CustomerBills

Customer IDBill Amount
1100
2150
3120
4110
5200

 

CustomersPayment

Customer IDPaid Amount
150
150
250
250
3120
450
450
410
550
550
550
575

 

I need to get to 50 Overdue and not the total sum which shows as 25 (Customer 5 is over paid)

 

Thanks in advance

Simon

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @tsql_simon ,

 

not sure if I understand your requirement 100%.

I created the following 2 measures, this is more a habit than necessary for the solution:

 

Total Bill Amount = SUM('CustomersBill'[Bill Amount]) 

 

and

 

Total Paid Amount = SUM('CustomersPayment'[Paid Amount])

 

 

After this I created the following measure that now provides the solution (at least from my understanding of your requirement):

 

Overdue Amount = 
SUMX(
    VALUES(CustomersBill[Customer ID])
    , var billed = [Total Bill Amount]
    var paid = [Total Paid Amount]
    var diff = billed - paid
    return
    IF(diff > 0 , diff , BLANK())
)

 

This allows to a create a report like this:

image.png

 

Hopefully this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey @tsql_simon ,

 

not sure if I understand your requirement 100%.

I created the following 2 measures, this is more a habit than necessary for the solution:

 

Total Bill Amount = SUM('CustomersBill'[Bill Amount]) 

 

and

 

Total Paid Amount = SUM('CustomersPayment'[Paid Amount])

 

 

After this I created the following measure that now provides the solution (at least from my understanding of your requirement):

 

Overdue Amount = 
SUMX(
    VALUES(CustomersBill[Customer ID])
    , var billed = [Total Bill Amount]
    var paid = [Total Paid Amount]
    var diff = billed - paid
    return
    IF(diff > 0 , diff , BLANK())
)

 

This allows to a create a report like this:

image.png

 

Hopefully this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens ;

 

You understood perfectly, Thank you very much, I have been fighting with similar SUMX logic but could not piece it together quite right. That works perfectly for me.

 

Kindest Regards

Simon 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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