cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AccrualJoke
Frequent Visitor

Cumulative (Running) Totals for Specified Period Based on Single Date Selection

I'm struggling trying to find a measure that can do the following:

  • Based on a date selection from a single-select date slicer, calculate the cumulative (running) totals for the last 5 days.
  • Relative date slicer CANNOT be used to achieve this

For example, assuming the data begins January 1, 2020. If Nov 30, 2020 is selected from the date slicer, the corrresponding visual (bar chart with dates as x-axis) should show Nov 25, 26, 27, 28, 29, 30 along the x-axis while the counts for each date should equal to the amounts from Jan 1, 2020 to Nov 25, Jan 1 to Nov 26...


Unforunately, every combination I try results in:

  • Counts flat lining from inception to date selected
  • Counts calculating correctly, but dates stuck at inception to date selected
  • Counts showing for ONLY the selected date

If someone could help provide a solution, i'd be extremely greatful. Thank you!

1 ACCEPTED SOLUTION
DataZoe
Microsoft
Microsoft

Hi @AccrualJoke ,

 

You can do this by creating a disconnected date table for the picker (this means it's not connected by relationship to another table in the model). You can do this with the TABLE DAX:

 

[Date Picker] = SUMMARIZE(MOCK_DATA,MOCK_DATA[date])

Then the measure for your chart:
[Measure] =
var pickeddate = SELECTEDVALUE('date picker'[date])
var ondate = SELECTEDVALUE(MOCK_DATA[date])
return
if(SELECTEDVALUE(MOCK_DATA[date])<=pickeddate && SELECTEDVALUE(MOCK_DATA[date])>=pickeddate-5,
TOTALYTD(sum(MOCK_DATA[value]),MOCK_DATA[date]))


Then you would NOT use the date picker date on your chart, the other one.

 

DataZoe_1-1606159050070.png

 

Respectfully,
DataZoe


See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

7 REPLIES 7
DataZoe
Microsoft
Microsoft

Hi @AccrualJoke ,

 

You can do this by creating a disconnected date table for the picker (this means it's not connected by relationship to another table in the model). You can do this with the TABLE DAX:

 

[Date Picker] = SUMMARIZE(MOCK_DATA,MOCK_DATA[date])

Then the measure for your chart:
[Measure] =
var pickeddate = SELECTEDVALUE('date picker'[date])
var ondate = SELECTEDVALUE(MOCK_DATA[date])
return
if(SELECTEDVALUE(MOCK_DATA[date])<=pickeddate && SELECTEDVALUE(MOCK_DATA[date])>=pickeddate-5,
TOTALYTD(sum(MOCK_DATA[value]),MOCK_DATA[date]))


Then you would NOT use the date picker date on your chart, the other one.

 

DataZoe_1-1606159050070.png

 

Respectfully,
DataZoe


See my reports and blog at https://www.datazoepowerbi.com/

@DataZoe Thank you so much! I just tried your measure now and it's working well!

The one issue is that I'll need to calculate totals beyond just the year. The data will most likely spanning past 2020 into future periods. So is there a variation that allows for that?

 

I tried substituting TOTALYTD with Calculate, but that doesn't seem to work.

Please let me know if you have further insight to this! Thank you again!

@AccrualJoke ,

 

The TOTALYTD will work on any period, so should accomodate future years just like it is.

DataZoe_0-1606164100895.png

 

 

 

Respectfully,
DataZoe


See my reports and blog at https://www.datazoepowerbi.com/

Is there a way to make it so that the cumulative count does NOT reset at the beginning of a new year?

For example, instead of a TOTALYTD is there an equivalent for life-to-date or inception-to-date? I would want 2021 to include the 2020 and prior year counts as part of the 2021 totals.

@AccrualJoke Sure, you can use this cumulative instead:

 

Cumulative =
CALCULATE (
    [Measure],
    FILTER (
        ALLSELECTED ( 'Date'[Date] ),
        ISONORAFTER ( 'Date'[Date], MAX ( 'Date'[Date] )DESC )
    )
)

 

Respectfully,
DataZoe


See my reports and blog at https://www.datazoepowerbi.com/

Thanks again for saving me! 

Instead of referencing the Date column from my disconnected Date Table, I used the date column from my actual data table. After making the switch, the measure seemed to work perfectly fine.

@AccrualJoke ah perfect, I am glad you got it to work 🙂 

Respectfully,
DataZoe


See my reports and blog at https://www.datazoepowerbi.com/

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors