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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
andy_pat
Helper I
Helper I

Rolling Calculation with Filter

I have a rolling sum calculation as my measure. The measure works fine, but the additonal requirement is to hide the last 7 days of calculated data.  The data older than 7 days should show up even if the slicer on Date column is moved around.

See pbix attached here

 

Moving sum = CALCULATE(SUM(Data[Value]),
                      DATESINPERIOD(Data[Date],LASTDATE(Data[Date]),-7,DAY)
)

 

 The Grand Total also needs to reflect the correct number, which at the moment is incorrectly showing as 7

Any guidance would be really helpful.

 

Adding more detail: 

 The dates from 7-26 to 08-01 should return blank value for the measure, when the latest date is 08-01.  The window of blank data should change from 7-27 to 08-02 the latest date changes to 08-02  In other words, trying to blank out the latest 7 days of data.

andy_pat_0-1600997490850.png

Part 2: 
The "Total" still shows 7. Need to fix that to reflect the correct value.

 

 

Thanks

Andy

1 ACCEPTED SOLUTION

@andy_pat , Try measure like these, see if this can help

measure =
var _max = maxx(all(Date), Date[Date])
return
calculate(if(max(Date[Date]) >=_max-7, blank(), [measure])) // you can use 0 in place blank

 

measure =
var _max = maxx(all(Date), Date[Date])
return
Sumx(values(Date[Date]), if(max(Date[Date]) >=_max-7, blank(), [measure])) // you can use 0 in place blank

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@andy_pat , not very clear .The information you have provided is not making the problem clear to me. Can you please explain with an example.

Something like this

Moving sum before 7 days= CALCULATE(SUM(Data[Value]),
                      all(Date)) - CALCULATE(SUM(Data[Value]),
                      DATESINPERIOD(Data[Date],mx(Data[Date]),-7,DAY))

 

or

7 Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-7,Day))



Appreciate your Kudos.


Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks. I added a scenario in my post.  The goal is to calculate the moving sum for all dates except the last 7 available dates, as the date range advances each day.

@andy_pat , Try measure like these, see if this can help

measure =
var _max = maxx(all(Date), Date[Date])
return
calculate(if(max(Date[Date]) >=_max-7, blank(), [measure])) // you can use 0 in place blank

 

measure =
var _max = maxx(all(Date), Date[Date])
return
Sumx(values(Date[Date]), if(max(Date[Date]) >=_max-7, blank(), [measure])) // you can use 0 in place blank

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.