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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rogletree
Helper III
Helper III

DAX experts, I need help with time manipulation

I have a table that tracks downtimes for machines. Some fields I have are [start_time] & [end_time] (both are datetime), [duration] (in minutes as a decimal number). Those are all pretty self-explanatory. I have created another field in power query called [date_hour] (as datetime) that is the hour of the day that a downtime occurred, for example if a downtime started at 10:15 am on October 13th, it would show as "10/13/2020 10:00:00 AM".

Some of these downtimes are only a few minutes, but some of them can last several hours. I want to display these visuals as graphs where I can drill down to the [date_hour] field for specific machines and see how many minutes they were down for any given hour of the day. But with how I currently have it modeled, if a downtime starts at 10:15 AM and lasts for 120 minutes, it shows that the 10 AM hour has 120 minutes of downtime, and obviously there can only be 60 minutes in an hour so it showing 120 minutes of downtime in one hour is kind of misleading.

So basically what I would like to do is, if there is a downtime that is longer than 60 minutes, have a DAX expression that basically drags it out across however many [date_hour] fields are necessary for however many minutes it is.

Is this something that sounds feasibly? I'm not that good at DAX so I figure there are some people around here that are really good at it that might have some ideas.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@rogletree 

1. You need a complete date-time table with all the hours, no gaps. You should also have a full date table with all days in the year (full years) to avoid unexpected issues.

2. No relationship between date-time table and Main table 

3. Create this measure for the chart:

 

Measure = 
VAR startSlot_ = SELECTEDVALUE('date hours'[date_hour])
VAR endSlot_ = startSlot_ + (1/24) //1 hour later
RETURN
SUMX(Main, 
VAR aux_ =  MIN(endSlot_,Main[end_time])- MAX(startSlot_, Main[start_time])
VAR timeInSlot_ = IF(aux_>=0, 24*60*aux_, 0)
RETURN
timeInSlot_)

 

4. See it all at play in the attached file

 

AlB_0-1603454317479.png

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

5 REPLIES 5
Daviejoe
Memorable Member
Memorable Member

Calling @Greg_Deckler 

 

Hope you didn't mind me tagging you in this one!  Reminded me of your MTBF chapter.





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

Proud to be a Super User!




AlB
Community Champion
Community Champion

Hi @rogletree 

I haven't understood. Can you show an example based on data with the expected result? To help clarify a bit

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

@AlB sure, here are a couple screenshots.

Here is a row from my table. As you can see, for the "duration" it shows 375.262. This is in minutes, so that comes out to a little over six hours, as shown by the start time and end time. And since the start time was at 4:06AM, the "date_hour" is at 4AM for that date.

1.jpg

Now when plotted on a graph, this is how it looks. This view shows all 24 hours of one date for one particular machine. That one long bar represents the 375 minute downtime event but it shows it as being within the 4AM hour, which is exactly how I told Power BI. You can also see that for the 5AM, 6AM, 7AM, 8AM, and 9AM hours it shows no downtimes, when in reality the 375 minute downtime carried over throughout those hours. Then in the 10AM hour that small sliver of a bar is for a downtime event that was a little over one minute, not related to the big one.

2.JPG

So I'm hoping that there is a way to kind of "spread out" the downtimes that are longer than 60 minutes, or if it goes from one hour into another hour, to show that. Because right now the visual looks misleading with how I have it.

AlB
Community Champion
Community Champion

@rogletree 

1. You need a complete date-time table with all the hours, no gaps. You should also have a full date table with all days in the year (full years) to avoid unexpected issues.

2. No relationship between date-time table and Main table 

3. Create this measure for the chart:

 

Measure = 
VAR startSlot_ = SELECTEDVALUE('date hours'[date_hour])
VAR endSlot_ = startSlot_ + (1/24) //1 hour later
RETURN
SUMX(Main, 
VAR aux_ =  MIN(endSlot_,Main[end_time])- MAX(startSlot_, Main[start_time])
VAR timeInSlot_ = IF(aux_>=0, 24*60*aux_, 0)
RETURN
timeInSlot_)

 

4. See it all at play in the attached file

 

AlB_0-1603454317479.png

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

@AlB thank you so much!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.