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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
kaylendao
Regular Visitor

format text to HH:MM:SS based on condition

Hi there, I have a text column that contains "None" and time in HH:MM:SS, but sometimes the data submitted is incorrect such as H:MM:SS, instead of the correct HH:MM:SS format.  I would like a write a formula in Excel power query (perhaps a custom column) to correct the time format with one condition:

if the text in column [time of request] = None, then None, other wise format the text in [time of request] to HH:MM:SS. 

 

Any help is appreciated. 

1 ACCEPTED SOLUTION
adudani
Super User
Super User

hi @kaylendao ,

 

add a custom column and paste the following code:

 

if [time of request] = "None"   then "None" else if Text.Length([time of request]) =8 then [time of request] else "0"&[time of request]

 

This concatenates  0 infront of the values that don't have a "HH:MM:SS" format.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

View solution in original post

4 REPLIES 4
kaylendao
Regular Visitor

Thank you for the great idea. But now that I think about it, if the data is showing 8:30:10, we can't really assume that it is supposed to be 08:30:10 since it could be 18:30:10. So I guess I won't be able to apply this logic. 

@kaylendao 

Please provide sample input data removing sensitive data, for various different cases and I'll be happy to try and adapt a formula that could fit the requirement.

If there is an indicator for AM/PM any other reference columns as well?

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

I tried the formula you suggested and it put a 0 in front of the None and not the 8:32:00

kaylendao_0-1676141644337.png

 

adudani
Super User
Super User

hi @kaylendao ,

 

add a custom column and paste the following code:

 

if [time of request] = "None"   then "None" else if Text.Length([time of request]) =8 then [time of request] else "0"&[time of request]

 

This concatenates  0 infront of the values that don't have a "HH:MM:SS" format.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors