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.
Hello,
I'm using this workaround for getting duration in seconds into this form hh:mm:ss.
Its a quite know workaround provided by Chelsie Eiden:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Chelsie-Eiden-s-Duration/td-p/793639
How ever I have a calculation of a median which ends up negative as -44 seconds.
First Measure to get difference between two timestamps as seconds.
Measure1 = Datediff (time1-time2), seconds)
Second Measure to check if the Median of the timestamp:
If i drag that measure with another dimension I really get -44 seconds for that category displayed.
However if I'm using the hh mm ss conversion workaround it shows -00:40:84 instead of -00:00:44
I hope someone dealt with negative duration before. All positive values are shown correctly.
Thank you very much in advance.
Best.
Solved! Go to Solution.
@Applicable88 maybe tweak it a bit
Measure 2 =
VAR MedianValue = -44 //this will be your median value measure
VAR Negative = IF ( MedianValue < 0, -1, 1 )
VAR Duration = ABS ( MedianValue )
// There are 3,600 seconds in an hour
VAR Hours = INT ( Duration / 3600)
// There are 60 seconds in a minute
VAR Minutes = INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds = ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number
VAR Result =
// We put the hours, minutes and seconds into the proper "place"
Hours * 10000 + Minutes * 100 + Seconds
RETURN Result * Negative
✨ Follow us on LinkedIn
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
In this Measure, there are calculations in there which I presume are premised on a +ve Duration.
I think if you add in an ABS[DurationMeasure], and then in the RETURN put in a conditional IF:
IF [YourDurationMeasure] is -ve, then multiply by -1.
So, in other words, format it as if it was positive since those values work, and then transform it back to your negative value at the end.
Hope this might work for you.
Please see this article on a good way to calculate and format durations. It is not necessary to separately calculate hours, min, and sec.
Calculate and Format Durations in DAX – Hoosier BI
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
@mahoneypat , thank you.
I will defintely take a look. Your point "You don't need a Duration Column" sounds very interesting, since I'm unfortunately working a lot with Durations in PowerBi.
@Applicable88 maybe tweak it a bit
Measure 2 =
VAR MedianValue = -44 //this will be your median value measure
VAR Negative = IF ( MedianValue < 0, -1, 1 )
VAR Duration = ABS ( MedianValue )
// There are 3,600 seconds in an hour
VAR Hours = INT ( Duration / 3600)
// There are 60 seconds in a minute
VAR Minutes = INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds = ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number
VAR Result =
// We put the hours, minutes and seconds into the proper "place"
Hours * 10000 + Minutes * 100 + Seconds
RETURN Result * Negative
✨ Follow us on LinkedIn
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@Applicable88 not sure how you are converting seconds to hh:mm:ss but maybe this is what you need:
seconds in time format = TIME ( 0, 0, ABS ( [YourDifferenceMeasure] ) )
✨ Follow us on LinkedIn
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Hello @parry2k,
I'm using this workaround to get hh:mm:ss:
VAR Duration = calculate (Median(DurationMeasure)) // There are 3,600 seconds in an hour VAR Hours = INT ( Duration / 3600) // There are 60 seconds in a minute VAR Minutes = INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60) // Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours VAR Seconds = ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number RETURN // We put the hours, minutes and seconds into the proper "place" Hours * 10000 + Minutes * 100 + Seconds
As I said, it works well with positve values, but not if the duration is negative.
I tried your formula, but its not a value I can drag into a bar chart, rather a different display of the seconds:
Whenever I drag it into a bar charts "values" it will jumpt to Quickinfo immediately since its more like a dimension then a measure I guess. Hope there are other ways to work around that problem.
Cheers.
In this Measure, there are calculations in there which I presume are premised on a +ve Duration.
I think if you add in an ABS[DurationMeasure], and then in the RETURN put in a conditional IF:
IF [YourDurationMeasure] is -ve, then multiply by -1.
So, in other words, format it as if it was positive since those values work, and then transform it back to your negative value at the end.
Hope this might work for you.
@rsbin thank you 🙂 . This is basically the solution that parry2k also implemented.
I'm thinking (hoping? ) Parry used my answer to create his solution. 😀
Gotta give it to him.....he is much, much better at writing syntax on the fly than I am.
Glad you got your answer.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
100 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
94 | |
84 | |
67 |