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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
LvanLaar
Frequent Visitor

Starting date in running totals

Hi, I'm looking for a way to do running totals with a starting date.

I have tried looking into the forums and most answers I found had something like:

 

Running = CALCULATE(
    SUM(Invoices[Amount]),
    FILTER(
        ALL(Calendar[CDate]),
        Calendar[CDate] <= MAX(Calendar[CDate])
    )
)


The problem for me seems to be that I'm not sure how to add a starting date from which to start counting.

For example:

 

LvanLaar_1-1669385476723.png

What I'm trying to accomplish is a running total that starts at 0 on the first date in my calendar table (1st of october in this example.) which then adds up untill the 30th of November. It seems however with the code used above my running total starts counting at the start date of my calendar table. Which I think makes sense considering the all filter used.

 

Some extra info

  • The invoice table is connected to my calendar in a many to one relationship.
  • On both the slicer, X axis and in my formula I use the date column from my calendar table.

LvanLaar_0-1669385444701.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@LvanLaar , Use allselected in place of all

 

Running = CALCULATE(
SUM(Invoices[Amount]),
FILTER(
allselected (Calendar[CDate]),
Calendar[CDate] <= MAX(Calendar[CDate])
)
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@LvanLaar , Use allselected in place of all

 

Running = CALCULATE(
SUM(Invoices[Amount]),
FILTER(
allselected (Calendar[CDate]),
Calendar[CDate] <= MAX(Calendar[CDate])
)
)

@amitchandak thank you for your answer. When using all selected I noticed this resolved my problem when using a default date slicer on my visual. However when I tried applying a date hierarchy it reverted to display the same values as when using ALL.

I'm relatively new to Power BI. From my understanding this happens because of the table a date hierarchy creates in the background. I ended up creating a firstday variable outside of my final calculate sum which does seem to have finally solved my problem.

Running =
VAR _FirstDay =
    CALCULATE(FIRSTDATE('Calendar'[CDate].[Date]),
    ALLSELECTED('Calendar'[CDate].[Day])
) RETURN CALCULATE(
    SUM(Invoices[Amount]),
    FILTER(
        ALLSELECTED(Calendar[CDate]),
        'Calendar'[CDate] <= MAX(Calendar[CDate]) &&
        'Calendar'[CDate] >= _FirstDay
    )
)

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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