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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Tomasavlis
Regular Visitor

Divide columns

Hi!

 

I have a column with numbers with either 4 or 7 characters, how can I divide the column into the ones with 4 and the ones with 7?

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Please provide sample data and expected outcome from that data.

There are many ways to accomplish this and variations depend on the nature of your data and expected outcome.

 

For example, if your data looks like:

ronrsnfld_0-1739802910845.png

This code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlGK1YEwTM3MwWwQE84wM7cAs0FMOMPcwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", Int64.Type}}),
    
    Split = Table.FromColumns(
        {Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=4)[Column],
         Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=7)[Column]},
         type table[Four=Int64.Type,Seven=Int64.Type])
in
    #"Split"

 

would produce:

ronrsnfld_1-1739802995831.png

 

 

 

View solution in original post

6 REPLIES 6
SundarRaj
Super User
Super User

Hi @Tomasavlis , here's a quick way to solve this problem. Do have a look. I'm attaching two images, one for output and second for the M code. Thanks!

SundarRaj_0-1739968920476.pngSundarRaj_1-1739968951058.png

 

Sundar Rajagopalan
ronrsnfld
Super User
Super User

Please provide sample data and expected outcome from that data.

There are many ways to accomplish this and variations depend on the nature of your data and expected outcome.

 

For example, if your data looks like:

ronrsnfld_0-1739802910845.png

This code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlGK1YEwTM3MwWwQE84wM7cAs0FMOMPcwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", Int64.Type}}),
    
    Split = Table.FromColumns(
        {Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=4)[Column],
         Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=7)[Column]},
         type table[Four=Int64.Type,Seven=Int64.Type])
in
    #"Split"

 

would produce:

ronrsnfld_1-1739802995831.png

 

 

 

Tomasavlis
Regular Visitor

IMG_0105.jpeg

 Something like this, column with random numbers with no rule, just there are some with 7 and others with 4 digits. Although in the picture it's in between, in the real data set it's random

Seems like my answer below does what you are looking for.

Yes it does, thank you so much!

ToddChitt
Super User
Super User

You would need to research the Power Query exact logic functions to use, but you could go off the length of the string. Create two calculated columns:

Column Four digits = IF Length of original column = 4 then original column, else null.




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.