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
JulianaMacedo
Helper I
Helper I

Calculate Total Hours and Minutes (for every hour) and total days

Hi!

I need help.
 I have a table with a time stamp as the example below. I have tried using this time stamp directly or creating a time table, either way I can't figure out what is wrong.

 

I need to calculate the total of days, hours and minutes from this by device / state. The thing is... I'm trying to calculate for how long time a device stays in a specific state (which basically means someone pressed a button, then I need the total of time out of it). The hours are not continous though, a certain device can be in a determined state from 12:00 -14:00 for example, and then start again at 16:00-17:00. Because of that, I need to calculate first the total of minutes and seconds per hour, and then the total hours per day, and total days per month.

 

So the outcome I'm looking for is a measure that will show a result like this:
Filter on ID 24 for month X:        5d 12h 30min

 

I have tried different calculates such as:

 

 

Total Time = 
CALCULATE(
    1.0*(MAX(production[Time]) - MIN(production[Time])),
    FILTER(
        production,
        Hour(production[Time])
    ))

 

 

And:

 

TEST = MINX(FILTER(TimeDim, TimeDim[Hour] <=23 || TimeDim[Hour] >22 ), TimeDim[Minute] + (TimeDim[Second]/60))

 

But none of them yields the results I need.

 

Example of data:

LogData ID       Date                     Time           Hour    Minute Second

1162232022-06-0911:21:0111211
11622252022-06-0911:21:0111211
11632252022-06-0911:21:0111211
116482022-06-0911:21:0411214
11642252022-06-0911:21:0411214
116582022-06-0911:21:0411214
1165242022-06-0911:21:0411214
11652252022-06-0911:21:0411214
1166242022-06-0911:21:0411214
11662252022-06-0911:21:0411214
116782022-06-0911:21:0411214
1167242022-06-0911:21:0411214
11672252022-06-0911:21:0411214
116882022-06-0914:21:0514215
11682252022-06-0914:21:0514215
11692252022-06-0914:21:0514215
1170242022-06-0914:21:0514215
1170312022-06-0914:21:0514215


I appreciate any help

 

1 ACCEPTED SOLUTION

I finally found a solution, following this post:

https://community.powerbi.com/t5/Desktop/Time-in-State/m-p/941429

 

In case anyone has the same problem.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @JulianaMacedo,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I finally found a solution, following this post:

https://community.powerbi.com/t5/Desktop/Time-in-State/m-p/941429

 

In case anyone has the same problem.

daXtreme
Solution Sage
Solution Sage

Hi @JulianaMacedo 

 

Just wondering... Why don't you calculate this in Power Query or in the source system? Would that not be so much easier? You could calculate this in Power Query with ease since PQ has all the needed functions to extract the pieces of info you need from a period of time. It's doable in DAX as well but with much, much more effort.

 

You could pre-calculate the number of minutes (as this is you base granularity) between each two consecutive dates for any one ID and place them in a table from which you'd only need to read them out and sum up if desired. Then, once you've got the total number of minutes, it'd be easy to retrieve the number of days, hours and remaining minutes... right?

@daXtreme 

 

Hi, it is actually a good idea... it was what I was thinking during the weekend that it would be better maybe to aggregate it before and make an aggregated table out of it before moving to DAX.
But I'm still not sure if PQ has what I need or it will be just as much work as in DAX, maybe just using SUMMARIZE function in DAX might do it.

I'll have to test a bit to find a solution, thanks for the idea.

Hi again

 

If you need to pre-calculate something, Power Query is the way to go. ALWAYS. This component of PBI is more than capable of doing any calculation (even recursive, where DAX is useless)... and with ease that you very often won't find in DAX.

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.

Top Solution Authors