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
Anonymous
Not applicable

Dynamic DATESINPERIOD function

Hi, I have an SSAS Tabular cube which feeds most of my PBI Desktop Reports.

I am trying to build a measure which compares the selected period in a date filter with the same period prior (in days)

 

For example, if a user selects 10-June-2020 to 13-June-2020, it will calculate the measure for the 3 days prior (as there are 3 days between the dates)

I have wrote the below DAX however it is just bringing me 0 each time which i know isn't correct - can anyone advise me how to resolve this please?

Many thanks!

TEST2:= CALCULATE('Productivity Advice'[Advice Actions],DATESINPERIOD('Calendar'[CleanDate],dateadd(FIRSTDATE('Calendar'[CleanDate]),-DATEDIFF(FIRSTDATE('Calendar'[CleanDate]),LASTDATE('Calendar'[CleanDate]),day),day), DATEDIFF(FIRSTDATE('Calendar'[CleanDate]),LASTDATE('Calendar'[CleanDate]),day),day))

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, my bad sorry - I had a filter applied which was causing the zero

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi, my bad sorry - I had a filter applied which was causing the zero

Hi @Anonymous ,

So this issue is caused by the filter and you have solved it by clearing the filter yourself right?

If so, you can accept the suitable reply as a solution to help others find it more quickly and close this isse, glad to hear that the issue is solved. If not, you can post more information here to let us better to help you to solve this issue.

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Can try something like this

 

Rolling 3 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-3,Day))

Rolling 3 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-3,Day))

 

Date is my calendar Table

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
Anonymous
Not applicable

Hi this works fine for a static 3 day period however I want it to be dynamic so if the number of days between the selected dates is 14 for example, it would show the data from the period 14 days.

@Anonymous ,

 

you can replace it with what-if parameter ?

 

Rolling 3 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-1* selectedvalues(param[param]),Day))

 

Rolling 3 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1* selectedvalues(param[param]),Day))

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

 

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!

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.