Forum Discussion
Excel Power Query equivalent for an excel formula for converting negative decimal hours
- Anonymous3 years ago
Hi spittingfire ,
Please try this:
let sign = if [Hours] < 0 then "-" else "", hh_1 = Number.RoundDown(Number.Abs([Hours])), hh_2 = if hh_1 >= 10 then Text.From(hh_1) else "0" & Text.From(hh_1), mm_1 = Number.RoundUp((Number.Abs([Hours]) - hh_1) * 60), mm_2 = if mm_1 >= 10 then Text.From(mm_1) else "0" & Text.From(mm_1) in sign & hh_2 & ":" & mm_2Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
You can do it with a formula like this in the popup box when you add a custom column.
let
sign = if [Hours] < 0 then "-" else ""
in
sign & Duration.ToText(Duration.From( Number.Abs([Hours]/24)))
However, not sure if you plan to add those up, etc., but it is better practice to keep them as a decimal (in days, divide by 24) and then FORMAT at the end.
Calculate and Format Durations in DAX – Hoosier BI
Pat
Thanks Pat,
These will not be summed up as I expect that the end result will be in text format.
Also once the hours goes over 24 in you solution it changes to -2 days, 15 hours and 45 minutes. I will like it all to strictly be in hh:mm so in this case -63:45