Forum Discussion
bwelsh
Helper I
9 years agoConvert Text to Hours
I have a colum that has duration as a text string "15 Hours, 48 Minutes". Is it possible to covert this to a decimal hour?
2 Replies
- MarcelBeug
Community Champion
My interpretation is that you want 15.8 as a result.
In Power Query it can be done by taking the part before the first space, convert this to a number and take the part between the second and the third space, convert this to a number, divide by 60 and add to the first number.
Example code from Power Query - Advanced Editor:
let Source = #table(1,{{"15 Hours, 48 Minutes"}}), TextToHours = Table.TransformColumns(Source, {{"Column1", each Number.From(Text.BeforeDelimiter(_," "))+Number.From(Text.BetweenDelimiters(_, " ", " ", 1, 0))/60, type number}}) in TextToHours - v-jiascu-msft
Microsoft Employee
Hi bwelsh,
Could you please mark the proper answer as solution or share the answer if it's convenient for you? That will be a help to the others.
Best Regards!
Dale