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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Date slicer - duration

Hi,

 

How do I calculate the duration between the from and to dates of a date slicer which needs to be used in another DAX measure?

 

Kindly find the image below for reference.

 

Regards,

KavyaDATE.JPG

 

2 ACCEPTED SOLUTIONS
arvindsingh802
Super User
Super User

Considering the slicer is created on Date[Date]

 

Date Harvest Min = CALCULATE( MIN( Dates[Date] ), ALLSELECTED( Dates[Date] ) )
Date Harvest Max = CALCULATE( MAX( Dates[Date] ), ALLSELECTED( Dates[Date] ) )
Date Difference = DATEDIFF( [Date Harvest Min], [Date Harvest Max], DAY )


If this post helps, then please consider Accept it as the solution, Appreciate your Kudos!!
Proud to be a Super User!!

View solution in original post

v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,


Similar to the formula given by @arvindsingh802 , refer to the following test results.

M_ = 
var min_date = MIN('Table'[Date])
var max_date = MAX('Table'[Date])
return DATEDIFF(min_date,max_date,DAY)

vhenrykmstf_0-1647325725766.png

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


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

4 REPLIES 4
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,


Similar to the formula given by @arvindsingh802 , refer to the following test results.

M_ = 
var min_date = MIN('Table'[Date])
var max_date = MAX('Table'[Date])
return DATEDIFF(min_date,max_date,DAY)

vhenrykmstf_0-1647325725766.png

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


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

Anonymous
Not applicable

Thankyou @v-henryk-mstf 

It is working as expected but we need to add +1 in the DAX code in order to consider start and end date into consideration.

arvindsingh802
Super User
Super User

Considering the slicer is created on Date[Date]

 

Date Harvest Min = CALCULATE( MIN( Dates[Date] ), ALLSELECTED( Dates[Date] ) )
Date Harvest Max = CALCULATE( MAX( Dates[Date] ), ALLSELECTED( Dates[Date] ) )
Date Difference = DATEDIFF( [Date Harvest Min], [Date Harvest Max], DAY )


If this post helps, then please consider Accept it as the solution, Appreciate your Kudos!!
Proud to be a Super User!!
Anonymous
Not applicable

Thankyou @arvindsingh802 

It's working.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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