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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Reigning_data
Frequent Visitor

Dynamic Date in the Future

Hi all,

 

I have tried to look for an answer to this question, but I keep coming up blank.

 

I need to reference a date in the future, based off of TODAY ( ). The date needs to be dynamic and I'd prefer not to just add x days.

 

I am trying to calculate the number of weeks between today and a future date within a calculation. See underlined below.

 

e.g. - DATEDIFF ( TODAY ( ) , (TODAY ( ) + 3 MONTHS)  , WEEK )

 

I had thought I could do this with DATEADD, but it seems that this is looking for a column reference.

 

Ideally, I'd be able to make the integer in the + 3 MONTHS  a variable, which can then be selected by the user through the use of a switch. I'm confident I'm able to do this part, but figured I'd include it, in case it alters any responses.

 

 

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi @Reigning_data 

First, you should know that:

1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary result.

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

Then for your case, you could use 

What if parameter

for example:

Step1:

There should be a date table in the report, if not, you could try this formula to create one.

Date = CALENDAR(TODAY()-365,TODAY()+365)

Step2:

Create a what if parameter

Step3:

If you just use (today+ days) as a variable, you could try this simple formula to create a measure

Measure 1 = DATEDIFF(TODAY(),TODAY()+[Parameter Value],WEEK)

Then just use slicer to select dynamic dates.

If you want use (today+months) as variable, you need to use this formula to create a measure

Measure 2 = var _table= ADDCOLUMNS('Date',"_movedate",DATEADD('Date'[Date],[Parameter Value],DAY)) return
DATEDIFF(TODAY(),MAXX(FILTER(_table,[Date]=TODAY()),[_movedate]),WEEK)

 

here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi @Reigning_data 

First, you should know that:

1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary result.

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

Then for your case, you could use 

What if parameter

for example:

Step1:

There should be a date table in the report, if not, you could try this formula to create one.

Date = CALENDAR(TODAY()-365,TODAY()+365)

Step2:

Create a what if parameter

Step3:

If you just use (today+ days) as a variable, you could try this simple formula to create a measure

Measure 1 = DATEDIFF(TODAY(),TODAY()+[Parameter Value],WEEK)

Then just use slicer to select dynamic dates.

If you want use (today+months) as variable, you need to use this formula to create a measure

Measure 2 = var _table= ADDCOLUMNS('Date',"_movedate",DATEADD('Date'[Date],[Parameter Value],DAY)) return
DATEDIFF(TODAY(),MAXX(FILTER(_table,[Date]=TODAY()),[_movedate]),WEEK)

 

here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Lin,

 

Thank you so much for your detailed reponse! I've been maunally writing my what-if tables all this time. Never knew that's what that button did...

 

Measure 2 is the real gold-mine for me, though.

 

Thanks!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

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.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.