Financial Balance calculation for Last 13 months

L33

Board Regular
Joined
Jul 2, 2008
Messages
108
Hi
I've just started building a Power BI data model that will mostly be used via the Analyze in Excel feature in pivot tables, and have hit a problem that feels like it should be simple, but I am struggling!

I'm returning the sum total balance of transactions at the end of each month, but need to be able to dynamically show these numbers for the last 13 months based on the selection of a single month.

My balance is determined by this DAX:

Code:
Balance (Accumulating Sum of Transaction Amounts) =
VAR MaxDate = MAX ( 'Calendar'[Calendar Post Month] ) -- Saves the last visible date
RETURN
    CALCULATE (
        [Sum Transactions Amount],            -- Computes sales amount
        'Calendar'[Calendar Post Month] <= MaxDate,   -- Where date is before the last visible date
        ALL ( 'Calendar' )               -- Removes any other filters from Date
    )

Followed by this:

Code:
Balance at end of Selected Month =
TOTALMTD(
    [Balance (Accumulating Sum of Transaction Amounts)],
    Calendar[Calendar_Date]
)

Basically - how do I write the DAX so that I can achieve the middle table where I've manually selected 13 months from the slicer above it, but using the slicer for third table where I'm selecting just one month?


1667231028948.png
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
In one of those moments where you suddenly realise "Of course!", I did a bit more googling and found the answer, and - as usual with these things - it lays in the construction of the data model.

I've had to create a disconnected Calendar table (in fact, a cut down version which is only a list of the distinct Post Months from that table) and then the following formula allows me to pick the single month from that disconnected table to get me to that middle table I wanted:

Code:
Balance for Each of Last 12 Months =
VAR TRAILING_MTHS = 12

VAR PreviousDate =
    FIRSTDATE (
        DATEADD (
            'Post Months (Disconnected)'[Posting Month (dis)],
             TRAILING_MTHS * -1,
            MONTH
        )
    )

VAR Result =
    CALCULATE (
        [Balance at end of Selected Month],
        KEEPFILTERS ( Calendar ),
        Calendar[Calendar_Date] >= PreviousDate
            && Calendar[Calendar_Date] <= MAX ( 'Post Months (Disconnected)'[Posting Month (dis)] )
    )

RETURN
Result


1667381675472.png


The "Calendar Post Month" in the table still comes from the main Calendar table. The only drawback here is that my users will have to understand it a bit, remembering which tables to pick the relevant fields from.

If anyone knows a way to achieve the same ends without a disconnected table, I'd be very grateful!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top