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
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
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.