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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.