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
Kira_Net
Helper I
Helper I

How to create a dynamic start and end date for DATESBETWEEN function?

Hey there,
I have a calculation created by datesbetween. I used Today()-7 function for the start and Today() for end date. BUt now I want to change it with a dynamic date which comes from my date slicer. Can anyone help me on this please?

1 ACCEPTED SOLUTION

@Kira_Net 

 

Add the variable in a measure to see whether it returns the correct date 

e.g.

 

Measure MIN_DATE = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Replace today()-7 with min(calendar[date]) and today() with max(calendar[date]).  Ensure that the Date slicer is built from the Calendar Table. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
themistoklis
Community Champion
Community Champion

Hello @Kira_Net 

 

Considering you have a Calendar table, you need to write 2 measures or variables and call these measures in datesbetween function.

 

Measure = 

var _min_date = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

var _max_date = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

RETURN

CALCULATE(SUM('Table'[Sales]),
DATESBETWEEN('Calendar'[Date], _min_date , _max_date
)
)

I have similar approach for my problem statement to count no. of rows between two dates
but with this solution, its showing me the count of all rows. 

Hey @themistoklis Thank you. I used the variable for the start and end date but it still showing me blank on my score card. the calculation works fine when I use today() and today ()-7 for start and end date but it only gives me the last week result. I wanted to create the flexeblity for users to filter out date using slicer.

 

@Kira_Net 

 

Add the variable in a measure to see whether it returns the correct date 

e.g.

 

Measure MIN_DATE = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

speedramps
Super User
Super User

Create a detached calendar (list of dates).

Drad calender to a slicer with a slicer bar (with min and max range)

 

Create dax measure ....

 

VAR mindate = MIN(calandar(date))
VAR maxdate = MIN(calandar(date))
RETURN
DATEDIFF(mindate , maxdate , DAY )

 

I am not sure if this is exactly what you need, but I hope you can change the value as required.

 

Please click the thumbs up and accept as solution button. Thank you !   😎

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!

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.

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.