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
ale259
Helper I
Helper I

Extract text from the same column_ US Census Data

Hello, I need help in extracting the US Census Data. I have the text as the example in column Race. I wonder how I can devide them into several columns based on their detail. I noticed there are several level, differenting by the number of space, so I'm looking for ways to seperate them, either using Power Query or SQL. Any idea is appreciated. Thanks so much! Example extracting.png

1 ACCEPTED SOLUTION
Akash_Varuna
Super User
Super User

Hi @ale259 ,Could you please try this

  • Add a custom column to count leading spaces:

    Text.Length([RACE]) - Text.Length(Text.TrimStart([RACE]))
    This will count the number of leading spaces in the RACE column.

  • Create a New Column for Each Level:

    • Split the RACE column into hierarchical levels based on the number of spaces:
      • Use Conditional Columns or assign levels to Level1 and so on , based on the number of spaces.
    • Alternatively, use Group By to summarize data by hierarchy.
  • Apply the Trim transformation to remove any leading or trailing spaces.
    You could also use SQL with CHARINDEX function to do the same 
    If this post helped please do give a kudos and accept this as a solution
    Thanks In Advance

View solution in original post

4 REPLIES 4
Akash_Varuna
Super User
Super User

Hi @ale259 ,Could you please try this

  • Add a custom column to count leading spaces:

    Text.Length([RACE]) - Text.Length(Text.TrimStart([RACE]))
    This will count the number of leading spaces in the RACE column.

  • Create a New Column for Each Level:

    • Split the RACE column into hierarchical levels based on the number of spaces:
      • Use Conditional Columns or assign levels to Level1 and so on , based on the number of spaces.
    • Alternatively, use Group By to summarize data by hierarchy.
  • Apply the Trim transformation to remove any leading or trailing spaces.
    You could also use SQL with CHARINDEX function to do the same 
    If this post helped please do give a kudos and accept this as a solution
    Thanks In Advance

Hi Akash, I managed to count the leading spaces. Can you guide me on how to split the column based on the number of spaces? There are different level of spaces: 0, 4, 8, 12, 16. Thank you

I have managed to do through all the steps. Thank you so much!

slorin
Super User
Super User

hi @ale259 

May be ?

let
Source = Your_Source,
Split = Table.AddColumn(Source, "Split", each Text.Split([RACE]," ")),
Columns = Table.SplitColumn(Split, "Split", each _, 5)
in
Columns

Stéphane 

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.