Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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,

Kavya

 

  • 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 )

  • 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)

    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.

4 Replies

  • arvindsingh802's avatar
    arvindsingh802
    Icon for Community Champion rankCommunity Champion

    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 )

  • v-henryk-mstf's avatar
    v-henryk-mstf
    Icon for Community Support rankCommunity 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)

    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's avatar
      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.