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
JTwohig
Helper I
Helper I

DAX Closing and Opening Balances

I have a table that contains a daily snapshot of an amount. I can get the amount at the end of each month with this formula:

 

Closing Balance:=CALCULATE(Sum(FactTable[AmountToDate]),LASTDATE(FactTable[Date]))

 

I need the balance at the end of the prior month so I can subtract and get the change in the month. I tried the following formula:

 

Last Month Closing:=CALCULATE([Closing Balance],PREVIOUSMONTH(LASTDATE(FactTable[Date])))

 

This gives me the correct closing balance for the last month of the year but all other months are blank. The results show below. I have tried many different ways but always get the same thing. What am I missing?

 

  Values 
CalendarYearMonthNameClosing BalanceLast Month Closing
2016March59,791,699.31 
 April62,596,269.14 
 May51,852,607.79 
 June53,945,802.67 
 July53,729,133.16 
 August57,174,277.35 
 September56,780,543.07 
 October57,852,783.08 
 November55,973,021.78 
 December57,976,571.96 
2016 Total 57,976,571.9655,973,021.78
2017January55,479,645.44 
 February50,214,362.52 
 March44,361,759.05 
 April46,053,405.57 
 May48,841,553.83 
 June52,345,876.41 
 July56,329,590.12 
 August55,859,204.39 
2017 Total 55,859,204.3956,329,590.12
Grand Total 55,859,204.39

56,329,590.12

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@JTwohig

 

Hi, if you always finished in the end of the month. this can help you

 

ClosingBalance-1month-Alt =
VAR EndofPrevMonth =
    PREVIOUSMONTH ( Table1[Date] )
RETURN
    CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER ( ALL ( Table1 ), Table1[Date] = EndofPrevMonth )
    )

 

Also you can review this DAX Functions:

 

OPENINGBALANCEMONTH

CLOSINGBALANCEMONTH

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

fhill
Resident Rockstar
Resident Rockstar

FINALLY!!!!    I got it....  This link helped!

https://community.powerbi.com/t5/Desktop/Help-using-Earlier-in-New-Measure/td-p/55799

 

EndofPriorMonth = CALCULATE(SUM(Table1[Balance]), FILTER(ALL(Table1), SUMX( FILTER( Table1, EARLIER(Table1[Date]) = LASTDATE(PREVIOUSMONTH(Table1[Date])) ), Table1[Balance])))

   ** What this does.. .Sum Blance,

                 Look at ALL Rows, (Filter ALL)

                 SUMX (Sums for each row of....)

                 Filter again (not sure why)

                 Compare 'previous row' (EARLIER) with Last Date of Pervious Month

                 When found, return Balance.

EndOfMonth = CALCULATE(SUM(Table1[Balance]), ENDOFMONTH(Table1[Date]))

Change = [EndOfMonth] - [EndofPriorMonth]

 

Capture.PNG

 

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

20 REPLIES 20

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.