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

Use Power Query to Subtract time frames form a complete day

Hello everybody,

 

There might be an easier solution to my problem, or to not do it in Power Query at all. Any help is appreciated:

 

I have a Dataset with start and end times like this:

Start: 10:30 am, End: 10:33 am

Start: 10:31 am, End 10:45 am

 

See the picture below.

 

Many of these timeframes overlap each other. I want a way to show me the time (in seconds or hours) of a full 24 hour day, where non of these time frames happend. So if a day has 1440 minutes and i only have two time frames (10:30 am to 10:45 am and 10:40 am to 10:45 am) i want the result to be 1425 minutes (and not 1420).

I hope this makes sense.

 

Thanks

 

 

Capture9.JPG

 

 

 

 

2 REPLIES 2
Zneta
Regular Visitor

Thank you, this is a great starting point. I followed your steps but for some reason the Fault Durations are not being added up. For example the first two Faults are within the same time frame. So the first faultduration should read 1696 as it is 1696 seconds long. The second FaultDuration should also read 1696 since that fault is in the time frame of the first and wont add to the total. why does it only show 5? unlike in your example.

 

Capture12.JPG

v-yangliu-msft
Community Support
Community Support

Hi  @Zneta ,

 

Here are the steps you can follow:

1. Create calculated column.

Date =
DATE(YEAR('Table'[Fault start]),MONTH('Table'[Fault start]),DAY('Table'[Fault start]))
Minute =
var _mindate=
MINX(FILTER(ALL('Table'),'Table'[Date]=EARLIER('Table'[Date])),[Fault start])
var _maxdate=
MAXX(FILTER(ALL('Table'),'Table'[Date]=EARLIER('Table'[Date])),[Fault end])
return
DATEDIFF(
    _mindate,_maxdate,MINUTE)

vyangliumsft_0-1716169955067.png

2. Create measure.

Measure =
var _mindate=MAX('Table'[Date]) + TIME(0,0,0)
var _maxdate=_mindate +1
var _oneday=
DATEDIFF(
    _mindate,_maxdate,MINUTE)
return
_oneday - MAX('Table'[Minute])

3. Result:

vyangliumsft_1-1716169955069.png

 

Best Regards,

Liu Yang

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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