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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JuiceNZ
New Member

Split column by every second space in a string of names

Hi,

 

Hoping there's a simple solution to this. I have a CSV with a column containing one or more names separated by spaces. Every name is firstname and lastname but there could be between one or a hundred names in a field. I want to split into one row per name. Can't figure out splitting by every second space, or alternately inserting a delimiter(|) into every second space making a simple split by delimiter.

 

Input:

JANCY LI
JANCY LI JANCY LI
JULIE SUN JAMES BLUNT JULIE SUN JULIE SUN

 

Output:

JANCY LI
JANCY LI
JANCY LI
JULIE SUN
JAMES BLUNT
JULIE SUN
JULIE SUN
1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

    split = Table.TransformColumns(
        input_table, 
        {"names_column", (x) => 
            List.Transform(
                List.Split(Text.Split(x, " "), 2),
                (w) => Text.Combine(w, " ")
            )}
    ),
    exp = Table.ExpandListColumn(split, "names_column")

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @JuiceNZ, similar approach here:

 

Restult

dufoq3_0-1713252649485.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nL0c45U8PFUitVBcBRQRUN9PF0VgkP9gMK+rsEKTj6hfiEKSKIwllJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Ad_Split = Table.AddColumn(Source, "Split", each List.Transform(List.Split(Text.Split([Column1], " "), 2), (x)=> Text.Combine(x, " ")), type list),
    Combine = Table.FromList(List.Combine(Ad_Split[Split]), Splitter.SplitByNothing(), type table[Column1=text])
in
    Combine

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

AlienSx
Super User
Super User

    split = Table.TransformColumns(
        input_table, 
        {"names_column", (x) => 
            List.Transform(
                List.Split(Text.Split(x, " "), 2),
                (w) => Text.Combine(w, " ")
            )}
    ),
    exp = Table.ExpandListColumn(split, "names_column")

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors