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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
mjackson
Regular Visitor

sorting one column into two

Hey everyone so here is the issue, I have a column with mixed codes. They are CPT and HCPCS codes. Both are the same number of characters. The CPT codes do not contain letters and the HCPCS codes do. what would be the best way to split this into multiple columns?

 

mjackson_0-1677255804917.png

 

2 REPLIES 2
Peter_Beck
Resolver II
Resolver II

Here is a simple solution directly in M. "SourceTable" is your source, which I have given a column name "Column1"

 

Creating the List called CharList is a little awkward because M does not have a direct way of specifying that a type conversion is *not* valid, so there is some conditional logic to evaluate true to false and error to true (if that makes any sense 🙂 

 

let
Source = SourceTable,
ValsList = Source[Column1], // Create a list made of the column containing the data
NumeberList = List.Select(ValsList, each try Number.FromText(Text.At(_, 0)) is number otherwise false), // make a list based on the first list, made up of values that start with a number
CharList = List.Select(ValsList, each if try Number.FromText(Text.At(_, 0)) is number otherwise false then false else true), //make a list based on the first list, made up of values that *do not* start with a number
MyTable = Table.FromColumns({NumeberList,CharList}) // make a new table of the two lists

in
MyTable

serpiva64
Solution Sage
Solution Sage

Hi,

you can duplicate your column

in the duplicated column change Type to Whole Number and replace errors with null

now add a conditional column

serpiva64_0-1677265325618.png

and rename your columns

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

 

 

 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors