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
asdfasdf3321g
Regular Visitor

Is it possible to get the date range in a date slicer?

I need to generate a downtime report for devices.  I have a database of support tickets.  If a device is down, I have a ticket which includes the date of the problem and the number of hours of downtime.

 

The calculation would look something like this...

Sum of Downtime / DATEDIFF(MinDate, MaxDate, HOUR) = downtime percentage

 

I posted this question a while back and got this answer...

https://community.powerbi.com/t5/Desktop/How-can-I-perform-a-calculation-based-on-the-dates-in-a-dat...

 

The problem with this solution is that it looks at the records filtered by the date slicer, rather than the date slicer itself.  If I select January 1 - January 31 in the slicer, the earliest ticket might be January 10 and the latest ticket might be January 20, then the datediff is calculated based on the ticket dates rather than the date selected in the slicer.

 

Is there a way to get the values selected in the slicer?

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

If you have a Calendar table that is what your slicer is based on, then you should be able to do this:

Diff =
VAR __Max = MAX('Calendar'[Date])
VAR __Min = MIN('Calendar'[Date])
...

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
MFelix
Super User
Super User

Hi @asdfasdf3321g ,

 

Use the following code:

 

Measure = DATEDIFF(min(Table[Date]);MAX(Table[Date]);HOUR)

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



amitchandak
Super User
Super User

@asdfasdf3321g , Can you share sample data and sample output?

 

You can refer my blog for date diff: https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Greg_Deckler
Super User
Super User

Also, VALUES('Calendar'[Date]) should get you all of the values in a single column table.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

If you have a Calendar table that is what your slicer is based on, then you should be able to do this:

Diff =
VAR __Max = MAX('Calendar'[Date])
VAR __Min = MIN('Calendar'[Date])
...

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I had to look up a "calendar table" but that worked, thanks for pointing me in the right direction.

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.