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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
pbi1908
Helper III
Helper III

Calculate Running Balance

Hi dear all, 

 

I have a problem of how to calculate the Running Balance. I already have a table with the Allocation of each payment and the history of an Invoice. 

In my table if i have an Invoice which is paid by 3 payments, i will have 3 lines for this invoice with the Allocated Amount (The amount of the payment which is allocated to this invoice) the Remaining Balance (Remaining Balance of this invoice after that Payment), The Payment Date, Invoice Date, The Customer, Invoice ID, The Initial Amount of the Invoice (for example if the remaining balance now is 1000 but the invoice was for 10000 in the begining i will have 10000 in the Total Amount). 

If for an invoice i do not have any payment yes the Payment Date, Payment ID, will be blank and the Remaining Balance will contain the whole amount. 

I have an example of my table below. 

 

What i want is to create a measure or calculated column i don't care which will give me the Running Balance in a visual. So i will have a slicer with the date ( i am not sure which date i should use in the slicer, invoice date or payment date) and when i will filter it for example on a date i want to see the Balance on that Date. 

 

Taking an example from my table below, if i want to see the Balance for Customer 1 ,on 2/3/2023 i should see 

100000 (Iinvoice ID 100) + 15000 (Invoice ID 102) + 5000 (Invoice ID 103) + 100000 (Invoice ID 105) so the Open Balance at 2/3/2023 was 220000.

 

 

Allocation Table in the link below:

https://docs.google.com/spreadsheets/d/1pVEi3Y6WsTMyYli3-746M-RwHWq4XGEF/edit?usp=sharing&ouid=11364...

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @pbi1908 ,

 

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
CALENDAR(
    DATE(2023,2,1),
    DATE(2023,12,31))

vyangliumsft_0-1689062309995.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table 2'[Date])
return
IF(
MAX('Table'[INVOICE_DATE])=MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_DATE])
    &&
MAX('Table'[INVOICE_ID])=MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_ID])
,
MAX('Table'[REMAINING_BALANCE]),
IF(
    MAX('Table'[PAYMENT_DATE])=BLANK()&&MAX('Table'[INVOICE_ID])<>MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_ID]),BLANK(),
IF(
    MAX('Table'[PAYMENT_DATE])<=_select,MAX('Table'[REMAINING_BALANCE]),BLANK())
))
Sum_All =
SUMX(
ALL('Table'),[Flag])

3. Result:

[Invoice_id]=101 is also during slicer filtering, so it is also added

 

vyangliumsft_1-1689062309999.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
v-yangliu-msft
Community Support
Community Support

Hi  @pbi1908 ,

 

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
CALENDAR(
    DATE(2023,2,1),
    DATE(2023,12,31))

vyangliumsft_0-1689062309995.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table 2'[Date])
return
IF(
MAX('Table'[INVOICE_DATE])=MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_DATE])
    &&
MAX('Table'[INVOICE_ID])=MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_ID])
,
MAX('Table'[REMAINING_BALANCE]),
IF(
    MAX('Table'[PAYMENT_DATE])=BLANK()&&MAX('Table'[INVOICE_ID])<>MINX(FILTER(ALL('Table'),'Table'[CUSTOMER_ID]=MAX('Table'[CUSTOMER_ID])),[INVOICE_ID]),BLANK(),
IF(
    MAX('Table'[PAYMENT_DATE])<=_select,MAX('Table'[REMAINING_BALANCE]),BLANK())
))
Sum_All =
SUMX(
ALL('Table'),[Flag])

3. Result:

[Invoice_id]=101 is also during slicer filtering, so it is also added

 

vyangliumsft_1-1689062309999.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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