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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
mgaut341
New Contributor III

Turning Format Text to number

I have formatted text values, but I want to switch them to number values so I can apply a conditional format based on if the time is between 0-30 mintes or 31+ minutes. 

mgaut341_0-1749480416437.png

 

1 ACCEPTED SOLUTION
grognard
New Contributor III

Presumably some data is formatted like “00:4:21” or “4:31:12”. Since the code is expecting two numbers between each colon, it’s reading the minute number as “4:” which DAX can’t convert as a number.  
 
You can either address this in your data, which might be more difficult, or you could replace your calculation with this: 
 

duration in minutes = 
var textSize = LEN([Check in duration avg])
var l = SEARCH(":",[Check in duration avg])
var r = SEARCH(":",RIGHT([Check in duration avg],textSize - l))

return INT(LEFT(RIGHT([Check in duration avg],textSize - l),r - 1))


which should be a little more fault tolerant. 

View solution in original post

4 REPLIES 4
grognard
New Contributor III

Hello  @mgaut341
You can get the number of minutes from the formated string using

duration in minutes = INT(RIGHT(LEFT([Check in duration avg],5),2))​

grognard_0-1749501144614.png

As an aside, this board is dedicated to developing custom visuals, and thus a little less active than the other boards. You might be able to get your question answered by posting to another forum such as https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/bd-p/DAXCommands.


mgaut341
New Contributor III

Thanks for the feedback. I get the following error message 

mgaut341_0-1749592312753.png

 

grognard
New Contributor III

Presumably some data is formatted like “00:4:21” or “4:31:12”. Since the code is expecting two numbers between each colon, it’s reading the minute number as “4:” which DAX can’t convert as a number.  
 
You can either address this in your data, which might be more difficult, or you could replace your calculation with this: 
 

duration in minutes = 
var textSize = LEN([Check in duration avg])
var l = SEARCH(":",[Check in duration avg])
var r = SEARCH(":",RIGHT([Check in duration avg],textSize - l))

return INT(LEFT(RIGHT([Check in duration avg],textSize - l),r - 1))


which should be a little more fault tolerant. 

mgaut341
New Contributor III

Thank you!!

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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 Solution Authors
Users online (14,789)