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
Anonymous
Not applicable

Assistance required: Converting seconds measures

Hello All,

 

I needed some assistance. I have gone through the forums but cant seem to find an answer.

 

I have a measure called run time, which gives me numerical values like 78555,9875,etc.

 

What I want to do is convert and format this measure to display as  ' X' Days 'Y' Hours

 

For example if run time is 90,000. It should display as : 1 Day 1 Hours

Using simple math to do this conversion where in one day has 86,400 seconds and an hour has 3,600 seconds.

 

Please help!! I am stuck at a work project and have spent 2 days trying to figure this out.

 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

See if this article helps. https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486. But you probably want something along the lines of (as a column):

 

Column = 
VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT([Value]/__secondsInDay)
VAR __hours = INT(([Value]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi @Anonymous,

 

Rather than create a calculated column, you could new a measure instead still with above formula.

Measure = VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT('arms_reach vw_mold_tracking'[Enabled]/__secondsInDay)
VAR __hours = INT(([Enabled]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

See if this article helps. https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486. But you probably want something along the lines of (as a column):

 

Column = 
VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT([Value]/__secondsInDay)
VAR __hours = INT(([Value]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler , how would you do this in dax if you were to include minutes and seconds as well? So, day, hour, minute, second.

 

Best,

Nils

Anonymous
Not applicable

Thank You so Much Greg! It does what I want to do but it seems I under estimated the complexity of my end goal. I have a bar chart with the run time in seconds where I wanted to feed this into. I have scaled the bar chart by dividing the run time by 86400, so that it gives me a scale in days(be it decimal), But if I try to put this calculated column as a tooltip it wont give me the days and hours after summing all the run times on that day.

 

Any workaround for that? I'm thinking of changing the calculation so that instead of taking the 'enabled' measure, I have to create a new measure(sum of all runtimes for that particular date)  which feeds into the below code.

 

 
Column 5 = VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT('arms_reach vw_mold_tracking'[Enabled]/__secondsInDay)
VAR __hours = INT(([Enabled]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"
 

Hi @Anonymous,

 

Rather than create a calculated column, you could new a measure instead still with above formula.

Measure = VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT('arms_reach vw_mold_tracking'[Enabled]/__secondsInDay)
VAR __hours = INT(([Enabled]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank You so Much Greg! It does what I want to do but it seems I under estimated the complexity of my end goal. I have a bar chart with the run time in seconds where I wanted to feed this into. I have scaled the bar chart by dividing the run time by 86400, so that it gives me a scale in days(be it decimal), But if I try to put this calculated column as a tooltip it wont give me the days and hours after summing all the run times on that day.

 

Any workaround for that? I'm thinking of changing the calculation so that instead of taking the 'enabled' measure, I have to create a new measure(sum of all runtimes for that particular date)  which feeds into the below code.

 

 
Column 5 = VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT('arms_reach vw_mold_tracking'[Enabled]/__secondsInDay)
VAR __hours = INT(([Enabled]-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"
 

Right, so you want the measure form, which should be something like:

 

Column = 
VAR __secondsInDay = 86400
VAR __secondsInHour = 3600
VAR __days = INT(SUM([Value])/__secondsInDay)
VAR __hours = INT((SUM([Value])-(__days*__secondsInDay))/__secondsInHour)
RETURN
__days & " Days " & __hours & " Hours"

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.