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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pal95
Helper III
Helper III

Measure based on a date difference on a slicer

Hi, I just need a simple measure to count the number of days on a slicer filter.

If the start date on a slicer is 7/13/2020 and the end date 7/15/2020, I would like the measure to return a value of 2.
If the start date on a slicer is 7/13/2020 and the end date 7/17/2020, I would like the measure to return a value of 4.
If the start date on a slicer is 7/13/2020 and the end date 7/23/2020, I would like the measure to return a value of 10.


days.PNG


Any ideas on how to do this?

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @pal95 , 

You could create a table like below

slicer = CALENDAR(date(2020,1,1), date(2020,12,31))

Then use this in slicer and create measure like below

Measure = DATEDIFF( MIN(slicer[Date]),MAX(slicer[Date]),DAY)

 You could refer to my sample for details.

Best Regards,
Zoe Zhi

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

5 REPLIES 5
harshnathani
Community Champion
Community Champion

Hi @pal95 ,

 

 

Try this

 

measure =
VAR maxselval =
    MAXX (
        ALLSELECTED ( Date ),
        Date[Date]
    )
VAR minselval =
    MINX (
        ALLSELECTED ( Date ),
        Date[Date]
    )
RETURN
    DATEDIFF (
        maxselval,
        minselval,
        DAY
    )

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

What should I put in Date[Date]? I would like to use the value on the slicer, so here, I would like to have a measure value of 11.

days.PNG

dax
Community Support
Community Support

Hi @pal95 , 

You could create a table like below

slicer = CALENDAR(date(2020,1,1), date(2020,12,31))

Then use this in slicer and create measure like below

Measure = DATEDIFF( MIN(slicer[Date]),MAX(slicer[Date]),DAY)

 You could refer to my sample for details.

Best Regards,
Zoe Zhi

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

amitchandak
Super User
Super User

@pal95 , try like

measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return datediff(_min,_max,Day)
az38
Community Champion
Community Champion

Hi @pal95 

In the most common case it will be looked like

Measure = DATEDIFF(MIN('Table'[Date]), MAX('Table'[Date]),DAY)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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