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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
CJDK
Helper II
Helper II

Split specific text strings into separate column

I have a column with a mix of 50 country names and 3 region names. I want to split the column so that the countries and regions are in separate columns, so that I can build a hierarchy. In other words, how do I split a column using specific text strings?

 

From:

CJDK_2-1601029017732.png

 

To:

CJDK_1-1601028823343.png

Thanks in advance!

4 REPLIES 4
FarhanAhmed
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs4vzSspqlQwVIrVQfCMwLyg1PTM/DwoByZljMIzQVYINCMWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column1", "Column1 - Copy"),

// Code to replace values
    #"Replaced Value" = Table.ReplaceValue( #"Duplicated Column"  ,each [Column1],each if Text.Contains([Column1], "Region") then "" else [Column1],Replacer.ReplaceValue,{"Column1"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Replaced Value",{{"Column1", "Country"}}),
    #"Added Conditional Column" = Table.AddColumn(#"Renamed Columns1", "Country_", each if [Country] = [#"Column1 - Copy"] then "" else [#"Column1 - Copy"]),
    #"Renamed Columns" = Table.RenameColumns(#"Added Conditional Column",{{"Country_", "Region"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Column1 - Copy"})
in
    #"Removed Columns"






Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




amitchandak
Super User
Super User

@CJDK , Can try a new column like

 

region = if( Search("Region",[country],,0) >0 , [country] , blank())

or

region = if( [country] in {"Bal Region","Ca Region"," .. Region"} , [country] , blank()) //give correct region name

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Wow! Fast! Thank you! 👍 I am getting an error Token RightParen expected. Do you have a suggestion about that?

CJDK_0-1601031460770.png

 

I am having technical problems with Power BI Desktop, so this might be why the column creation is not working.

Anonymous
Not applicable

Hi @CJDK,

 

You may try this.

each if [Country] = "Balkans Region" then "Balkans Region" else if [Country] = "Caucasus Region" then "Caucasus Region" else if [Country] = "Central Asian Region" then "Central Asian Region" else null

 3.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors