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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dancarr22
Helper V
Helper V

Creating cumulative (running) total which responds to date slicer

Hello,

 

I am trying to create a cumulative total which responds to dates changed in a date slicer.

I did read several other posts about this -- all of which had the same DAX formula:

 

calc_RunningTotalPrincipal = CALCULATE(SUM(Transaction[Principal]),FILTER(ALL(Transaction[TradeDate]),Transaction[TradeDate] <= MAX(Transaction[TradeDate])))

 

 

But, this is not working properly. 

I created a simple example with several records.  There is a date, transaction type and amount.  i.e. 1/1/2017, BUY, $100,  Want a running sum of amount based on filters applied -- generally a date slicer.  Though curious, if we add other filters -- ie. transaction type -- do we need to define this in the DAX forumla?

Please see screenshots below as example.

Any assistance greatly appreciated.

 

Thanks,

Dan

 

All DatesAll Dates

 

 

 

 

With Date FilterWith Date Filter

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@dancarr22

You could try a measure as below.

Measure =
VAR sumTotal4previousDates =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        FILTER ( ALLSELECTED ( yourTable ), yourTable[date] < MAX ( yourTable[date] ) )
    )
VAR sumTotal4currentDayBuyTrans =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        FILTER ( yourTable, yourTable[transtype] = "Buy" )
    )
VAR sumTotal4currentDayBuyAndSellTrans =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        ALLEXCEPT ( yourTable, yourTable[date] )
    )
RETURN
    IF (
        LASTNONBLANK ( yourTable[transtype], "" ) = "Buy",
        sumTotal4previousDates + sumTotal4currentDayBuyTrans,
        sumTotal4previousDates + sumTotal4currentDayBuyAndSellTrans
    )

Capture.PNG

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@dancarr22

You could try a measure as below.

Measure =
VAR sumTotal4previousDates =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        FILTER ( ALLSELECTED ( yourTable ), yourTable[date] < MAX ( yourTable[date] ) )
    )
VAR sumTotal4currentDayBuyTrans =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        FILTER ( yourTable, yourTable[transtype] = "Buy" )
    )
VAR sumTotal4currentDayBuyAndSellTrans =
    CALCULATE (
        SUM ( yourTable[Principal] ),
        ALLEXCEPT ( yourTable, yourTable[date] )
    )
RETURN
    IF (
        LASTNONBLANK ( yourTable[transtype], "" ) = "Buy",
        sumTotal4previousDates + sumTotal4currentDayBuyTrans,
        sumTotal4previousDates + sumTotal4currentDayBuyAndSellTrans
    )

Capture.PNG

Thanks Eric!

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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