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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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