March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I have some data in an EXCEL TABLE which has total hours worked and actual work hours and which resembles the Duration in the form of %s as per the below-mentioned screenshot:
Now, I would use this Excel file in POWER BI and showcase the same duration and %s. But unfortunately, In PowerBI, the data type is being considered as Text, and hence unable to convert them to the formats as per Excel file. If I try to change it to Date or Date/Time, Decimal, or Duration, it is throwing an error. I need to perform calculations like the Sum of all the Durations etc.,
Following is one type of error when I converted to Duration Data Type, likewise, it is showing an error for all the data types I tried.
Appreciate your help, thank you!
Solved! Go to Solution.
Hi @mrk777 ,
I'd suggest to convert your duration column into seconds. With that you should be able to do all your calculations. You might wanna do something like the below:
And here the M code for the new column:
Number.FromText ( Text.BeforeDelimiter([duration],":") ) * 60 * 60 + Number.FromText ( Text.BetweenDelimiters([duration], ":", ":" ) ) * 60 + Number.FromText ( Text.AfterDelimiter([duration], ":", {0, RelativePosition.FromEnd}) )
I used the example above in this blog post with a little bit more explanations:
https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#11_Calculate_duration_from_time_col...
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
Here is another approach. You can add a custom column with this expression which will get you as a decimal in days. You can then use the approach in the linked article to do your measures and then format as durations.
= let
splitlist = List.Transform(Text.Split([YourColumn], ":"), each Number.From(_))
in
splitlist{0}/24 + splitlist{1}/(24*60) + splitlist{2}/(24*60*60)
Calculate and Format Durations in DAX – Hoosier BI
Pat
See this answer to your identical question at Convert to Time Format in the Power Query Editor in Power BI while importing the data from Excel
Hi @mrk777 ,
I'd suggest to convert your duration column into seconds. With that you should be able to do all your calculations. You might wanna do something like the below:
And here the M code for the new column:
Number.FromText ( Text.BeforeDelimiter([duration],":") ) * 60 * 60 + Number.FromText ( Text.BetweenDelimiters([duration], ":", ":" ) ) * 60 + Number.FromText ( Text.AfterDelimiter([duration], ":", {0, RelativePosition.FromEnd}) )
I used the example above in this blog post with a little bit more explanations:
https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#11_Calculate_duration_from_time_col...
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
17 | |
13 | |
13 | |
8 |
User | Count |
---|---|
36 | |
32 | |
20 | |
19 | |
17 |