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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Plump_Lil_Monk
Frequent Visitor

Separate Numerical and Text into separate Columns

Hi

 

I have quite a large data set and am having an issue separating a particular column that is similar to the following:

 

123
153
Dep One
1896
DepThree
3265
758

Dep Two

 

I need to separate the column into two separate ones, one with text and one with numbers so that it looks like.

 

123null
153Dep One
nullnull
1896null
nullDep Three
3265null
758null
nullDep Two

 

is this possible? 

Thanks

 

3 ACCEPTED SOLUTIONS
Syk
Super User
Super User

First lets create a new column to help us determine if each row is a number or text.
Add column > Custom Column

try if Number.FromText([Column])-Number.FromText([Column])=0 then 1  else 0
otherwise 0

Syk_0-1708458117956.png

There are a few ways you could do this.. In this example, we cast the value in the original column to a number and subtract it from itself. Since the text cant be cast to a number type we just wrap it in the try... otherwise to catch all the errors! 

Then we just create a few conditional columns to split the original column.

Syk_1-1708458323660.pngSyk_2-1708458339600.png

 

Here's the M query if you're interested as well..

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVorVAdKmENoltUDBPy8VImZhaQYTDMkoSoWIGhuZmYIZ5qYWcC0h5flKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"(blank)", "Column"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "NumOrText", each try if Number.FromText([Column])-Number.FromText([Column])=0 then 1  else 0
otherwise 0),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Number Column", each if [NumOrText] = 1 then [Column] else null),
    #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Text Column", each if [NumOrText] = 0 then [Column] else null),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column1",{{"Number Column", Int64.Type}})
in
    #"Changed Type1"

 Source is just the manually entered data. 

View solution in original post

tackytechtom
Super User
Super User

Hi @Plump_Lil_Monk ,

 

How about this? 🙂

 

Before:

tackytechtom_1-1708458748169.png

 


After:

tackytechtom_0-1708458724386.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVorVAdKmENoltUDBPy8VImZhaQYTDMkoSoWIGhuZmYIZ5qYWcC0h5flKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [column = _t]),
    #"Duplicated Column" = Table.DuplicateColumn(#"Source", "column", "columnString"),
    #"Changed Type" = Table.TransformColumnTypes(#"Duplicated Column",{{"column", Int64.Type}}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"column", null}}),
    #"Replace Values" = Table.ReplaceValue(#"Replaced Errors",each [columnString],each if [column] <> null then null else [columnString],Replacer.ReplaceValue,{"columnString"})

in
    #"Replace Values"

Hope this helps! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

slorin
Super User
Super User

Hi @Plump_Lil_Monk 

just one step with Table.SplitColumn

= Table.SplitColumn(
Your_Source,
"Your_Column",
each if Value.Type(_) = type number then {_, null} else {null, _},
{"Your_Column.1", "Your_Column.2"}
)

 Stéphane

View solution in original post

3 REPLIES 3
slorin
Super User
Super User

Hi @Plump_Lil_Monk 

just one step with Table.SplitColumn

= Table.SplitColumn(
Your_Source,
"Your_Column",
each if Value.Type(_) = type number then {_, null} else {null, _},
{"Your_Column.1", "Your_Column.2"}
)

 Stéphane

tackytechtom
Super User
Super User

Hi @Plump_Lil_Monk ,

 

How about this? 🙂

 

Before:

tackytechtom_1-1708458748169.png

 


After:

tackytechtom_0-1708458724386.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVorVAdKmENoltUDBPy8VImZhaQYTDMkoSoWIGhuZmYIZ5qYWcC0h5flKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [column = _t]),
    #"Duplicated Column" = Table.DuplicateColumn(#"Source", "column", "columnString"),
    #"Changed Type" = Table.TransformColumnTypes(#"Duplicated Column",{{"column", Int64.Type}}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"column", null}}),
    #"Replace Values" = Table.ReplaceValue(#"Replaced Errors",each [columnString],each if [column] <> null then null else [columnString],Replacer.ReplaceValue,{"columnString"})

in
    #"Replace Values"

Hope this helps! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Syk
Super User
Super User

First lets create a new column to help us determine if each row is a number or text.
Add column > Custom Column

try if Number.FromText([Column])-Number.FromText([Column])=0 then 1  else 0
otherwise 0

Syk_0-1708458117956.png

There are a few ways you could do this.. In this example, we cast the value in the original column to a number and subtract it from itself. Since the text cant be cast to a number type we just wrap it in the try... otherwise to catch all the errors! 

Then we just create a few conditional columns to split the original column.

Syk_1-1708458323660.pngSyk_2-1708458339600.png

 

Here's the M query if you're interested as well..

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVorVAdKmENoltUDBPy8VImZhaQYTDMkoSoWIGhuZmYIZ5qYWcC0h5flKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"(blank)", "Column"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "NumOrText", each try if Number.FromText([Column])-Number.FromText([Column])=0 then 1  else 0
otherwise 0),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Number Column", each if [NumOrText] = 1 then [Column] else null),
    #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Text Column", each if [NumOrText] = 0 then [Column] else null),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column1",{{"Number Column", Int64.Type}})
in
    #"Changed Type1"

 Source is just the manually entered data. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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