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
joshua1990
Post Prodigy
Post Prodigy

Splitting column individualy

Hi community!I have a column that contains a string in this format:

Type1 Type2 Product "in"Country City

 

String
Glas Tube A inFrance Lyon
Glas Tube B inSpain
Glas Tube C
Wood Chair A1 Spain Madrid

 

Now, based on the first word in the column I would like to apply an individual split of this column:

  • If it starts with Glas then the columns should be splittet after each blank space and "in" should be seperated from Country
  • If it starts with Wood, then the columns should be splittet after each blank space

 

How would you apply this kind of logic within power query?

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @joshua1990 

 

You could give this a go.

 

let
    ColNames = {"Type1", "Type2", "Product", "Country", "City"},
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs9JLFYIKU1KVXBUyMxzK0rMS05V8KnMz1OK1UGWdQLKBhckZqKLO4P54fn5KQrOGYmZRQqOhgpgdQq+iSlFmSlKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [String = _t]),
    SplitCol = Table.SplitColumn(Source, "String", Splitter.SplitTextByWhitespace() ),
    TrimStart = Table.TransformColumns(
        Table.RenameColumns( SplitCol, List.Zip( { Table.ColumnNames( SplitCol ), ColNames })),
        {{"Country", each Text.TrimStart(_, {"i", "n"}), type text }}
    )
in
    TrimStart

 

 

With this result

m_dekorte_0-1685780778811.png

 

View solution in original post

2 REPLIES 2
johnlhaase
Helper I
Helper I

Hello

 

Here is the magic code

= Table.AddColumn(#"Renamed Columns1", "New", each Text.Select([Name], {"a".."z"}))

We can subsitute Upper and Lower case or number {0..9}.

Thanks

John Haase

m_dekorte
Super User
Super User

Hi @joshua1990 

 

You could give this a go.

 

let
    ColNames = {"Type1", "Type2", "Product", "Country", "City"},
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs9JLFYIKU1KVXBUyMxzK0rMS05V8KnMz1OK1UGWdQLKBhckZqKLO4P54fn5KQrOGYmZRQqOhgpgdQq+iSlFmSlKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [String = _t]),
    SplitCol = Table.SplitColumn(Source, "String", Splitter.SplitTextByWhitespace() ),
    TrimStart = Table.TransformColumns(
        Table.RenameColumns( SplitCol, List.Zip( { Table.ColumnNames( SplitCol ), ColNames })),
        {{"Country", each Text.TrimStart(_, {"i", "n"}), type text }}
    )
in
    TrimStart

 

 

With this result

m_dekorte_0-1685780778811.png

 

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