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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DennisG
Frequent Visitor

Using Measure in DATESBETWEEN Function

My question is can I use a measure in the DATESBETWEEN dax function?

 

Using TODAY() this works just fine I can slice by any date range. I would like to substitute a measure for TODAY(). The measure would be a selected date from a separate calendar table example

TargetDate = SELECTEDVALUE(CalendarDynamicTarget[Date]) I simply want to

I simply want to allow the user to pick a single date and have the period table use that date as the Target Date and create date ranges plus or minus that date.

 

I have a calculated table defined like this

Period =



VAR

 

 _Next30Days = ADDCOLUMNS(

    CALCULATETABLE(

    'Calendar'

    ,DATESBETWEEN('Calendar'[Date],[TargetDate],  [TargetDate]+30)

    )

    ,"In the Next", "a_1 to 30 Days","ColorYN",0

 )

VAR  

 

_Next60Days = ADDCOLUMNS(

    CALCULATETABLE(

    'Calendar'

    ,DATESBETWEEN('Calendar'[Date],TODAY()+31,  TODAY()+60)

    )

    , "In the Next", "b_31 to 60 Days","ColorYN",0

)

 VAR

 

_Next90Days =

ADDCOLUMNS(

    CALCULATETABLE(

    'Calendar'

    ,DATESBETWEEN('Calendar'[Date],TODAY()+61, TODAY()+90)

    )

    , "In the Next", "c_61 to 90 Days","ColorYN",0

)

3 REPLIES 3
WinterMist
Impactful Individual
Impactful Individual

@DennisG 

 

My apologies for the screenshots still referring to TODAY().

It's the same solution.

You just replace it with the dynamic measure and it works, as long as you're using GENERATESERIES.

 

WinterMist_1-1688767135571.png

 

 

WinterMist_0-1688767082356.png

 

WinterMist_2-1688767234394.png

 

 

NOTE: I only added the CountRowsInPeriod VAR so that it would return a scalar value for testing.  If you're returning the table, then you'll need to use it in another way (e.g. as a filter argument or something).

 

Regards,

Nathan

DennisG
Frequent Visitor

Thank You @WinterMist for the reply my issue is I need a dynamic date picked by the user used instead of TODAY() that way they can generate a report from any given date with plus or minus date ranges at will. I hope I am making sense.

WinterMist
Impactful Individual
Impactful Individual

@DennisG 

 

I'm not sure why, but DATESBETWEEN doesn't seem to work for me either.

However, you can use GENERATESERIES to return the period of desired dates based on the [Target Date] selected from the slicer.

NOTE: I used a range of the last 10 days (including today), but this is arbitrary.  Use any range you like.

 

WinterMist_0-1688765408416.png

 

Perhaps someone else may know why DATESBETWEEN returns no records in this situation?

 

WinterMist_1-1688765476840.png

 

Hopefully GENERATESERIES works for you.

 

Regards,

Nathan

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.