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
EmaVasileva
Helper V
Helper V

Count hours between Slicer dates

Hi,

I need help with calculating the task completion in hours, between slicer dates. I have the following data:

Category

Task

StartDate&Time

EndDate&Time

Full Duration in Hours

A

A.1

2/14/24 9:30 PM

2/22/24 7:30 PM

190

B

B.1

2/14/24 8:00 AM2/14/24 9:30 AM

1.5

B

B.2

2/14/24 10:00 PM2/16/24 6:00 AM

32



For ex.: Cat A, Task A.1 starts on Feb-14-24 9:30 PM and ends on Feb-22-24 7:30 PM, so its duration was 190 h (every day counts as 24 hours. If I select from the date slicer (for which I’m using StartDate and EndDate from the table above) Feb 15th, I need the duration hours to show the duration between Feb 15th and 22 Feb, so the number should be 187.5 hours

EmaVasileva_0-1708952980574.png

 

If I select from the slicer StartDate = Feb 15th 24 and EndDate Feb 21st, I need to see a duration= 168 h.

I would like to see the real startdate and Enddate for the task, even the slicer is for another period, but I would like to receive the actual duration based on the slicer. Please let me know if it's necessary to use another field as a Slicer and how to calculate the duration. Thank you.

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi @EmaVasileva ,

The table data is shown below:

vzhouwenmsft_0-1709012350119.png

Please follow these steps:
1. Use the following DAX expression to create a measure named ‘Full Duration in Hours’

Full Duration in Hours = DIVIDE(DATEDIFF(SUM('Tabelle1'[StartDate&Time]),SUM('Tabelle1'[EndDate&Time]),MINUTE),60) & "h"

2. If you want to get the actual hourly difference between the two slicers
2.1Use the following DAX expression to create a table named ‘Year-round dates’

Year-round dates = CALENDAR(DATE(2024,1,1),DATE(2024,12,31))

 2.2Use the following DAX expression to create a measure named ‘Slicer_Duration’

Slicer_Duration = DATEDIFF(MIN('Year-round dates'[Date]),MAX('Year-round dates'[Date]),HOUR)

3. Final output

vzhouwenmsft_1-1709012528212.png

vzhouwenmsft_2-1709012535885.png

vzhouwenmsft_3-1709012550011.png

vzhouwenmsft_4-1709012563516.png

vzhouwenmsft_5-1709012573086.png

vzhouwenmsft_6-1709012585190.png

 

 

vzhouwenmsft_7-1709012595182.png

vzhouwenmsft_9-1709012625138.png

vzhouwenmsft_10-1709012645884.png

vzhouwenmsft_11-1709012652627.png

 

 

 

 

vzhouwenmsft_12-1709012661669.png

 

 

 

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

Hi @v-zhouwen-msft ,

Thank you for the response, but it's not quite the result I'm looking for. I need to get the sum of the hour duration between Slicer start date and actual Startd_Date_Time, and the sum between the Slicer end date and the actual End-Date_Time in the table. 

Because in some cases we can have the actual Start_Date_Time to be after 12am (but in the slicer we have only date and 12:00am by default) and to be finished a day earlier that the end date in the slicer.

Example 1:
Slicer dates = 14 Feb 2024 12:00 Am - 22 Feb 2024 12:00AM
Start&End date in the table: Feb 14 2024 09:30 PM  - Feb 22 2024 07:30 PM

If i take only the duration from the slicer I would receive 192 h, in this case it will be the right one. 

Example 2: Slicer dates = 15 Feb 2024 12:00 Am - 22 Feb 2024 10:00PM
Start&End date in the table: Feb 14 2024 09:30 PM  - Feb 22 2024 07:30 PM

If i take only the duration from the slicer I would receive 144 h, but the needed and the right result is 187.5h. (from 15 Feb 2024 12:00 Am to 22 Feb 2024 07:30PM).

If the start date in the slicer is sooner than the one in the table, we took the one in the table. If the end date in the slicer is sooner than the end date in the table, we took the one in the slicer, but if the end date is later than the one in the table, we took the one in the table.

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.