Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
mrk777
Frequent Visitor

Convert to Time Format in the Power Query Editor in Power BI while importing the data from Excel

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:

 

mrk777_1-1680887962366.png

 

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.

mrk777_2-1680888001139.png

 

Appreciate your help, thank you!

 

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

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:

 

tackytechtom_0-1680915193912.png

 

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! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
ppm1
Solution Sage
Solution Sage

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

Microsoft Employee
ronrsnfld
Super User
Super User

tackytechtom
Super User
Super User

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:

 

tackytechtom_0-1680915193912.png

 

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! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors