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
AparnaJ
Helper I
Helper I

Convert text to time

Hi,

 

Have a file as below:

 

Seconds

300

814000

 

Am trying to create a new column using DAX as below:

-------------------------------------------------------------------------------------------------------------------------
Time Format =
Var H = INT(Sheet1[Seconds]/3600)
Var M = FORMAT(INT(DIVIDE(MOD(Sheet1[Seconds],3600),60)), "00")
Var S = FORMAT(INT(MOD(MOD([Seconds],3600),60)),"00")
RETURN
H& ":" & M & ":" & S
--------------------------------------------------------------------------------------------------------------------------------
However, am getting an error when I change the data type of the new column to Time as:
"Cannot convert value '226:06:40' of type text to type date.
Please advice.
 

 

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

Hi @AparnaJ 

Create columns

Time Format = 
Var H = MOD(INT(Sheet1[Seconds]/3600),24)
Var M = FORMAT(INT(DIVIDE(MOD(Sheet1[Seconds],3600),60)), "00")
Var S = FORMAT(INT(MOD(MOD([Seconds],3600),60)),"00")
RETURN
H& ":" & M & ":" & S

day = INT(INT(Sheet1[Seconds]/3600)/24)

1.png

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @AparnaJ 

Create columns

Time Format = 
Var H = MOD(INT(Sheet1[Seconds]/3600),24)
Var M = FORMAT(INT(DIVIDE(MOD(Sheet1[Seconds],3600),60)), "00")
Var S = FORMAT(INT(MOD(MOD([Seconds],3600),60)),"00")
RETURN
H& ":" & M & ":" & S

day = INT(INT(Sheet1[Seconds]/3600)/24)

1.png

 

Best Regards
Maggie

 

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

This doesn't seem to work in my case since I have cells with no values. How to get along this one?

Tani4ka_0-1619683376899.png

Many thanks

Anonymous
Not applicable

@AparnaJ  - 

That only works up to 23:23:59.

Does it need to be type time instead of the formatted time?

Cheers,

Nathan

Thank you. Is there a way that we can change to type time. 

Anonymous
Not applicable

Type Time is referring to a clock time.  https://dax.guide/time/

That is why, as mentioned by natelpeterson, the maximum value is 23:59:59.  Because a clock only has 24 hours.


Type Time is not meant to be used for a duration of time.  To display it in the format you're asking for with DAX, the only format you could use would be text.

Maybe clarify your requirements as to why it needs to be displayed in the specific format of 00:00:00.

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.