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
SysLostInBI
Frequent Visitor

Get date and time difference in duration as time - or why I need dd.hh.mm.ss

I need to comply a report that calculates SLAs.

I got my data from statuscake in "periods" which means I got periods where the service is up, and periods where the service is down.

 

Example:

StartEndStatus
31.05.2021 17:2501.06.2021 00:00Up
31.05.2021 17:2431.05.2021 17:24Down
30.05.2021 12:2530.05.2021 12:25Up
30.05.2021 12:2430.05.2021 12:24Down
25.05.2021 21:4925.05.2021 21:49Up


Now, I manage to extract the difference between the dates with:

 

 

 

DATEDIFF([Start],[End],SECOND),

 

 

 

This gives me seconds. Which I could use to create a report "Sum of Seconds per Status".
But it would be nice to have a "Days, Hours, Minutes, Seconds per Status" instead.

I did some research around this topic already, and I found a lot of ways to calucate Time from seconds into hh:mm:ss, which seems to be a supported format - until - you have more than 24h timeframes
So I found ways to format d:hh:mm:ss or d.hh:mm:ss - but this format is not known by PowerBi, as it seems - and therefore I can't get a "SUM by Status".

 

Any help is appreciated. 

1 ACCEPTED SOLUTION

Hi @SysLostInBI 
even though you could "group", it won't do calculations because the type of duration(format: dd:hh:mm:ss) is string. by the way, there is no format of duration(dd:hh:mm:ss) supported in Power BI, at least for now. so I suggest you to do calculations manually.

You can create a measure, and group data by status(Down, Up), then you can use function left(), MID(), RIGHT() to get each part in duration(format: dd:hh:mm:ss, 4 parts), then use function value() to convert type from string to int. Finally, calculate each part separately and combine 4 parts into one.
FYI:
https://docs.microsoft.com/en-us/dax/text-functions-dax

One quick example (not exactly same, but the logic is similar😃),

https://community.powerbi.com/t5/Desktop/Count-With-Multiple-Conditions-DAX/td-p/1858846

 

if you have further questions, please let me know.

 

Best Regards,

Community Support Team _ Tang

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

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @SysLostInBI 

Based on your discription, you want to calculate the "Days, Hours, Minutes, Seconds per Status" instead of "sum of seconds per Status", but in Power BI there is no such format. So I suggest you create the column and measure bellow to custom your format "day:hh:mm:ss", e.g.

 

secondsColumn = DATEDIFF('Table'[Start],'Table'[End],SECOND)
d:hh:mm:ss perstatus = 
var _sumseconds_perstatus=CALCULATE(SUM('Table'[secondsCol]),ALLEXCEPT('Table','Table'[Status]))//calculate sum seconds per status
var _day=INT(_sumseconds_perstatus/(24*3600))
var _hour=INT((_sumseconds_perstatus-_day*(24*3600))/3600)
var _min=INT((_sumseconds_perstatus-_day*(24*3600)-_hour*3600)/60)
var _sec=INT((_sumseconds_perstatus-_day*(24*3600)-_hour*3600-_min*60))
return
_day&":"&_hour&":"&_min&":"&_sec

 

 

v-xiaotang_2-1623122334860.png

See sample file attached bellow.

 

 

Best Regards,

Community Support Team _ Tang

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

Hey thanks a lot @v-xiaotang 
I managed to do this already. Sorry if I wasn't clear about this.
My problem is that I'm stuck with this afterwards. What I would need is an option to calculate these values afterwards.

So, let's say I have:

SysLostInBI_0-1623851990937.png

 


My Result should be:
Up: 10 days
Down: 3 days and 1h

I guess I would need to create another table for this - as the "duration" support of PowerBI is weak for this right? I mean the best option would be if I could just "group" it, and it is calculated.

Hi @SysLostInBI 
even though you could "group", it won't do calculations because the type of duration(format: dd:hh:mm:ss) is string. by the way, there is no format of duration(dd:hh:mm:ss) supported in Power BI, at least for now. so I suggest you to do calculations manually.

You can create a measure, and group data by status(Down, Up), then you can use function left(), MID(), RIGHT() to get each part in duration(format: dd:hh:mm:ss, 4 parts), then use function value() to convert type from string to int. Finally, calculate each part separately and combine 4 parts into one.
FYI:
https://docs.microsoft.com/en-us/dax/text-functions-dax

One quick example (not exactly same, but the logic is similar😃),

https://community.powerbi.com/t5/Desktop/Count-With-Multiple-Conditions-DAX/td-p/1858846

 

if you have further questions, please let me know.

 

Best Regards,

Community Support Team _ Tang

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

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.