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
sajidtp
Frequent Visitor

DAX Help - Accounts Receivable Aging: calculate monthly closing balance for previous periods

Hi,
Newbie here, been trying to solve this for a while - appreciate any help: I have AR transaction table in following format:

Document NoDateAmountBalanceStatusClosed ON
Invoice No. 1631/01/20191,9060CLOSED31/03/2019
Invoice No. 1801/02/20193160CLOSED26/02/2019
Invoice No. 2210/02/201910,45910458OPEN 
Invoice No. 2310/02/20197600CLOSED24/03/2019
Invoice No. 4506/03/20195,1445143OPEN 
Payment No. 123/02/2019-6,8610CLOSED26/02/2019
Payment No. 326/03/2019-91,2210CLOSED31/03/2019

 

Table is live connected to Power BI and is constantly updated.  We need to find closing balance of each month as of today (report is always as of today's date) to show trend and for Days Sales Oustanding (DSO) calculation. How can this be achieved?

 

Result rendered in a graph: it shows total of open debt at end of each month, at that point in time when payment was not received and hence not closed. 

Accounts Receivable Aging sample graph.PNG

Thank you in advance! I have tried to search for answer in forum and haven't come across any; in case if I have missed please point me to it. Have a great day!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

On the assumption that there is no manual intervention and the outstanding against invoices are knocked-off based on payments on a FIFO basis, the following solution will work.  Go through this and we will fine-tune it once again to suit the requirements.

 

Table: Transactions

 

Document NoDateAmountBalanceStatusClosed ON
Invoice No. 1631-01-20191,9060CLOSED31-03-2019
Invoice No. 1801-02-20193160CLOSED26-02-2019
Invoice No. 2210-02-201910,4593914OPEN 
Invoice No. 2310-02-20197600CLOSED24-03-2019
Payment No. 123-02-2019-6,8610CLOSED26-02-2019
Invoice No. 4506-03-20195,1445143OPEN 
Payment No. 326-03-2019-9,221 OPEN31-03-2019

 

Step 1: Add a calendar table.

 

Calendar = CALENDAR(MIN(Transactions[Date]),MAX(Transactions[Date]))

Step 2: Add 3 calculated columns to the calendar table.

 

Year = YEAR('Calendar'[Date])
Month = FORMAT('Calendar'[Date],"mmm")
MonthNumber = MONTH('Calendar'[Date]) // for sorting the month names

Step 3: Create four measures

 

LastDate = MAX('Calendar'[Date])
Credit =
SUMX (
    FILTER (
        Transactions,
        Transactions[Amount] < 0
            && Transactions[Date] <= [LastDate]
    ),
    Transactions[Amount]
)
Debit =
SUMX (
    FILTER (
        Transactions,
        Transactions[Amount] >= 0
            && Transactions[Date] <= [LastDate]
    ),
    Transactions[Amount]
)
Outstanding = [Debit]+[Credit]

Step 4: Add a Matrix Visual to the model.

 

Add Calendar[Month] on Rows of the Matrix Visual

Add Credit, Debit, Outstanding to the Values filed of the Matrix Visual.

(Remember, you should not have any relationship between the calendar table and the transaction table.)

 

You will get the following output.

 

MonthDebitCreditOutstanding
Jan190601906
Feb13441-68616580
Mar18585-160822503
Total18585-160822503

 

The debit and credit are the running totals of the debit and credit up to the last day of the month in the current context.

Remember to sort the Month using the MonthNumber field. If you want the year, you may add Calendar[Year] field also to the visual. 

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

Based on the Table that you have shared, please show the exact expected result in a simple Table format.  Once we get the correct numbers in a Table, creating a column chart will not be a problem.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you @Ashish_Mathur .  Please consider below table (tweaked earlier table to fit in):

Document NoDateAmountBalanceStatusClosed ON
Invoice No. 1631/01/20191,9060CLOSED31/03/2019
Invoice No. 1801/02/20193160CLOSED26/02/2019
Invoice No. 2210/02/201910,4593914OPEN 
Invoice No. 2310/02/20197600CLOSED24/03/2019
Payment No. 123/02/2019-6,8610CLOSED26/02/2019
Invoice No. 4506/03/20195,1445143OPEN 
Payment No. 326/03/2019-9,221 OPEN31/03/2019

Expected results:

MonthClosing BalanceRemark
Jan-191906Invoice No.16 open balance
Feb-196580Payment No.1 offset against Invoice No.18 & partially offset with invoice 22 + new invoice 23 + old invoice 16 (1906 + 316 + 10459 + 760 - 6861)
Mar-19-2172Payment No.3 partially offset against Invoice No.45, fully offset 16, add new invoice 45 (1906 + 1 + 5144 - 9221)

Expected outcome in monthly context:

ClosingBalance.PNG

Thank you in advance!

Hi,

What is the relevance of the Balance column?  For Feb, why is invoice 16 not offset before invoice 18?  What is the relevance of the last 2 columns?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

1. Balance column is amount not offset, or "open" as of today (In our example 26-Mar-2019)
2. For Feb, offsetting is done based on business reasons (hence could be partial or non-chronological). 

3. "Status" is "Closed" when full value of invoice or payment that is offset. Any residual value is indicated as "Open". This status is as of today.

4. Closed ON: This is date of full offset. 


Included an additional column to indicate amounts that are offset. Balance as of 26-Mar-19 is 6390 (Excuse, -2172 was wrong in last table)

Document NoDateAmountOffsetBalanceStatusClosed ON
Invoice No. 1631/01/20191,9061,9060CLOSED31/03/2019
Invoice No. 1801/02/20193163160CLOSED26/02/2019
Invoice No. 2210/02/201910,4596,8613,914OPEN 
Invoice No. 2310/02/2019760 0CLOSED26/03/2019
Payment No. 123/02/2019-6,861-6,8610CLOSED26/02/2019
Invoice No. 4506/03/20195,14415143OPEN 
Payment No. 326/03/2019-9,221-6,554-2,667OPEN31/03/2019
    6390  

Hi,

I don't think i can help you with this.  Someone else would pitch in.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you @Ashish_Mathur for trying, appreciate it. Hope I get a solution soon... 

Anonymous
Not applicable

@sajidtp 

 

Refer to the table below...

Document NoDateAmountOffsetBalanceStatusClosed ON
Invoice No. 1631/01/20191,9061,9060CLOSED31/03/2019
Invoice No. 1801/02/20193163160CLOSED26/02/2019
Invoice No. 2210/02/201910,4596,8613,914OPEN 
Invoice No. 2310/02/2019760 0CLOSED26/03/2019
Payment No. 123/02/2019-6,861-6,8610CLOSED26/02/2019
Invoice No. 4506/03/20195,14415143OPEN 
Payment No. 326/03/2019-9,221-6,554-2,667OPEN31/03/2019
    6390  

 

Against Invoice No 22, there is a balance of 3914 and offset of 6861. How will you determine if the offset has been done in February or March? Based on that decision, the reported outstanding of Feb & March could vary. I am asking this question because you said it's not FIFO based.

 

Is it possible for you to include an offset date? To accurately calculate the figures, we need to know when an invoice's outstanding has been offset. 

Anonymous
Not applicable

On the assumption that there is no manual intervention and the outstanding against invoices are knocked-off based on payments on a FIFO basis, the following solution will work.  Go through this and we will fine-tune it once again to suit the requirements.

 

Table: Transactions

 

Document NoDateAmountBalanceStatusClosed ON
Invoice No. 1631-01-20191,9060CLOSED31-03-2019
Invoice No. 1801-02-20193160CLOSED26-02-2019
Invoice No. 2210-02-201910,4593914OPEN 
Invoice No. 2310-02-20197600CLOSED24-03-2019
Payment No. 123-02-2019-6,8610CLOSED26-02-2019
Invoice No. 4506-03-20195,1445143OPEN 
Payment No. 326-03-2019-9,221 OPEN31-03-2019

 

Step 1: Add a calendar table.

 

Calendar = CALENDAR(MIN(Transactions[Date]),MAX(Transactions[Date]))

Step 2: Add 3 calculated columns to the calendar table.

 

Year = YEAR('Calendar'[Date])
Month = FORMAT('Calendar'[Date],"mmm")
MonthNumber = MONTH('Calendar'[Date]) // for sorting the month names

Step 3: Create four measures

 

LastDate = MAX('Calendar'[Date])
Credit =
SUMX (
    FILTER (
        Transactions,
        Transactions[Amount] < 0
            && Transactions[Date] <= [LastDate]
    ),
    Transactions[Amount]
)
Debit =
SUMX (
    FILTER (
        Transactions,
        Transactions[Amount] >= 0
            && Transactions[Date] <= [LastDate]
    ),
    Transactions[Amount]
)
Outstanding = [Debit]+[Credit]

Step 4: Add a Matrix Visual to the model.

 

Add Calendar[Month] on Rows of the Matrix Visual

Add Credit, Debit, Outstanding to the Values filed of the Matrix Visual.

(Remember, you should not have any relationship between the calendar table and the transaction table.)

 

You will get the following output.

 

MonthDebitCreditOutstanding
Jan190601906
Feb13441-68616580
Mar18585-160822503
Total18585-160822503

 

The debit and credit are the running totals of the debit and credit up to the last day of the month in the current context.

Remember to sort the Month using the MonthNumber field. If you want the year, you may add Calendar[Year] field also to the visual. 

@Anonymous what an elegant and unexpected solution! Thank you thank you - made my whole week! Kudos to you and this community, marvelous...

Anonymous
Not applicable

Hi,

 

If you don't want to see Debit and Credit separately in your visuals, then you can directly calculate the outstanding...

 

Outstanding =
SUMX (
    FILTER (
        Transactions,
         Transactions[Date] <= [LastDate]
    ),
    Transactions[Amount]
)

You can avoid the other two measures that calculate Debit and Credit separately and adding them together to arrive at the Outstanding. Those measures are required only if you want to see the Debit and Credit in the visuals separately. So when you apply this solution to your final model, it's better to reduce the number of measures.

 

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.