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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
JNelson
Helper II
Helper II

Remove text from column but leave numbers

Hi community!

 

I have a data set where I have a column [Litres] which should be a numerical value, however the people inputting the data sometimes put text. I know I could use a data validation on the original data input sheet, but there are too many to police (and they just copy and paste over the data validation anyway!).

 

My question is, can I, in the existing [Litres] column replace any text with null and leave the correct values as is (ie numercial values).

OR in a new custom column, can I do an if function that if[Litres] is text then null else [Litres] but I just don't know the correct code for that.

 

Thanks in advance!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Easiest thing is a new column as you suggest, but use try/otherwise and not if/then/else.

 

The formula is:

try Number.From([Column1]) otherwise null)

edhans_0-1704844878406.png

 

If the conversion to number returns an error, try/otherwise will return null. You can change that to 0 or whatever in the formula.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

Easiest thing is a new column as you suggest, but use try/otherwise and not if/then/else.

 

The formula is:

try Number.From([Column1]) otherwise null)

edhans_0-1704844878406.png

 

If the conversion to number returns an error, try/otherwise will return null. You can change that to 0 or whatever in the formula.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you so much! Works perfectly

Good day JNelson,

A slight tweak on edhans solution is to transform the column using edhans formula. This avoids creating a new column and having to delete the old column.

= Table.TransformColumns( #"Previous Step", {{"Column1", each try Number.From(_) otherwise null }} )

 Hope this helps.

Thank you! That also works 🙂

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

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

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors