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
adrianoramos520
New Member

Converting string ex. "117:50:00" into hours

Well. I have two collums with a start service and other with the date closed as pic below:

pic_example1.PNG

 

I inserted a new collumn with the code:

(h):mm:ss =
var Hora= QUOTIENT('Incidentes (2)'[Segundos],3600)
var Minut0= QUOTIENT('Incidentes (2)'[Segundos]-'Incidentes (2)'[var Hora]*3600,60)
var Segundo='Incidentes (2)'[Segundos]-'Incidentes (2)'[var Hora]*3600-'Incidentes (2)'[var Minuto]*60
return
CONCATENATE(CONCATENATE(CONCATENATE(CONCATENATE('Incidentes (2)'[var Hora],":"),'Incidentes (2)'[var Minuto]),":"),'Incidentes (2)'[var Segundos])
 
And I got the result I wanted but as "String" and I'm not able to convert it into hours. So I can't find the time average and others calculations I expected.
When I try to convert it I get the message: "Its not possible convert the value '117:50:0' type of String into Date".
 
pic_example2.PNG
 
What am I doing wrong? Could you please help me?
Thanks a lot. 
1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @adrianoramos520 ,

 

You could use "Split" feature to get total hours in query editor.

Here is my result and test file for your reference.

4-1.PNG

 

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

View solution in original post

11 REPLIES 11
v-eachen-msft
Community Support
Community Support

Hi @adrianoramos520 ,

 

You could use "Split" feature to get total hours in query editor.

Here is my result and test file for your reference.

4-1.PNG

 

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

Thanks for everyone that tried to help me. @v-eachen-msft its worked fine for me, and now I can perform some measures.

Thank you so much.

mahoneypat
Employee
Employee

I see you are trying to solve this with a DAX column but why not do it in the query editor.  Do you need the hh:mm:ss format?  Or is that a step to get you toward total hours?  If the latter, you can get the total hours between the two columns with Duration.TotalHours([Resolved] - [Created]).  This will give total hours as a decimal number, which you can round to the nearest hour, if needed.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


lbendlin
Super User
Super User

Have you tried this ?

 

([Resolvido] - [Criado em]) * 24

 

Yeah but I got a negative number.... and I still can't convert it into hours. Take a look.

pic_example3.PNG

Can you show the power query code and some data samples in a table?

Given the range of your negative numbers I guess that your "Resolved" column only has time but no date.

I think its not the case. 

 

Criado emResolvido
01/05/2020 00:3701/05/2020 01:57
01/05/2020 00:5605/05/2020 14:51
01/05/2020 01:2501/05/2020 03:47
01/05/2020 01:3001/05/2020 01:55
01/05/2020 01:4801/05/2020 12:22
01/05/2020 01:5404/05/2020 17:05
01/05/2020 02:0401/05/2020 02:10
01/05/2020 03:0301/05/2020 09:03
01/05/2020 03:1726/05/2020 10:11
01/05/2020 06:3207/05/2020 11:52
01/05/2020 06:5401/05/2020 06:57
01/05/2020 10:0101/05/2020 10:24
01/05/2020 10:1104/05/2020 17:00
01/05/2020 10:1501/05/2020 14:51

i think i know what it is. Your columns are "Variant" data type, and are being interpreted as numbers. Change the columns to type "DateTime"

Its a good point but I converted as date/hour but not worked. After conversion I performed a subtraction and the result was the same.

Take a look. Ex. 4.21:50:00  Its a "string" 4days21hours:50min  The idea is to have it in hh:mm:ss  Ex. 117:50:00 and I have it, but When I try to convert it as hour DAX says that cannot convert string 117:50:00 as hour.

pic_example6.PNG

 

pic_example7.PNG

pic_example8.PNG

Change the subtraction column to number and multiply it by 24

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
Top Kudoed Authors