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
Brendy_P
Frequent Visitor

Running Totals

Hi 

I have the solution but want to understand the logic of the solution, below is the formula with the logic of what I think the formula is performing. Can someone correct me in understanding the logic or am I correct.

 

Running Total (Filter) =
CALCULATE([Sales],
FILTER(ALL(Full_Date_Table),-- We are going to filter the full dates table but before we do make sure all the filters are cleared
Full_Date_Table[Date]>MAX(Full_Date_Table[Date])-30&&-- If the date in the filter context is > to the date(s) of the Max date in the filter context then go back 30 days (MAX is a scalar Function) AND
Full_Date_Table[Date]<=MAX(Full_Date_Table[Date]))) -- If the date in the filter context is <= to Max date in the filter context then Calculate sales
 
I know I can create the same formula with 
Running Totals (DatesInPeriod) =
CALCULATE([Sales],
DATESINPERIOD(Full_Date_Table[Date],
MAX(Full_Date_Table[Date]),-30,DAY))
 
But I want to get my head around how the first formula works. 
Thanks for your time
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Brendy_P Seems like you understand things correctly. Looks like you are calculating a measure called Sales. You first break out of filter context by using ALL. Then you impose your own filter context where you are retrieving the last 30 days. So the maximum date in context and then back 30 days from there. 

 

I personally avoid time "intelligence" functions if possible. You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see my Time Intelligence the Hard Way:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Brendy_P 

Yes, no problem at all. DATESINPERIOD function and the filter conditions both return the same date range.

Although, each function has its own usage, you can tweak and change the expression to get the same result as another function.

 

Best Regards,
Community Support Team _ Eason

Greg_Deckler
Super User
Super User

@Brendy_P Seems like you understand things correctly. Looks like you are calculating a measure called Sales. You first break out of filter context by using ALL. Then you impose your own filter context where you are retrieving the last 30 days. So the maximum date in context and then back 30 days from there. 

 

I personally avoid time "intelligence" functions if possible. You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see my Time Intelligence the Hard Way:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.