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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mcquerry-dillon
Regular Visitor

#Error Involving Time Conversion

Hello,

 

I am trying to convert an integer, for example 63148, which is the amount of seconds from midnight, into a time format such as '5:36PM'.

 

I've tried using combinations of changing the box properties to Time, using a mix of conversion functions, but I still end up with an #Err in my field. I tried looking this up and couldn't find a specific use case solution for what I'm trying to do.

 

Any help would be appreciated.

1 ACCEPTED SOLUTION
v-xiandat-msft
Community Support
Community Support

Hi @mcquerry-dillon ,

In the case of CDate expression, she can only convert a string of date type to a date, so if she converts the integer directly, an error will be reported.

Below is my table:

vxiandatmsft_1-1705461474485.png

I create Hrs , Mins , Time column

vxiandatmsft_2-1705461511739.png

The following expression might work for you:

Time =Fields!Hrs.Value & Format(Fields!Hrs.Value ,":")  & Format(Fields!Mins.Value)
Mins = Fields!NewColumn0.Value\60 - Fields!Hrs.Value*60
Hrs = Fields!NewColumn0.Value\3600
Time1 = CDate(Fields!Time.Value)

The final output is shown in the following figure:

vxiandatmsft_0-1705461388838.png

Expression examples in Power BI Report Builder - Power BI | Microsoft Learn

Best Regards,

Xianda Tang

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

3 REPLIES 3
v-xiandat-msft
Community Support
Community Support

Hi @mcquerry-dillon ,

In the case of CDate expression, she can only convert a string of date type to a date, so if she converts the integer directly, an error will be reported.

Below is my table:

vxiandatmsft_1-1705461474485.png

I create Hrs , Mins , Time column

vxiandatmsft_2-1705461511739.png

The following expression might work for you:

Time =Fields!Hrs.Value & Format(Fields!Hrs.Value ,":")  & Format(Fields!Mins.Value)
Mins = Fields!NewColumn0.Value\60 - Fields!Hrs.Value*60
Hrs = Fields!NewColumn0.Value\3600
Time1 = CDate(Fields!Time.Value)

The final output is shown in the following figure:

vxiandatmsft_0-1705461388838.png

Expression examples in Power BI Report Builder - Power BI | Microsoft Learn

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

gadielsolis
Super User
Super User

Hello,

 

I would recommend the following DAX:

gadielsolis_0-1705426508762.png

If this works please mark this message as solution.

hello, 

I should clarify that I'm using the PowerBI Report Builder so this is what I'm trying to work with

mcquerrydillon_0-1705427181625.png

 

The op_time field value is an integer as mentioned earlier in seconds

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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