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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
paul_cranberry
Frequent Visitor

Splicing together text string "pairs" from adjacent columns

I have data that looks like this...

NameColorsFruit
BobYellow; Red; Green; BlueBanana; Apple; Grape; Blueberry
KarenGreen; Blue; BrownGrape; Blueberry; Kiwi

 

How can I get a new column that concatenates text strings from "Colors" with the matching text string in "Fruit"? For example...

NameMatched Pairs
BobYellow - Banana; Red - Apple; Green - Grape; Blue - Blueberry
KarenGreen - Grape; Blue - Blueberry; Brown - Kiwi

 

Note: The number of text strings in "Colors" is always equal to the number of text strings in its adjacent "Fruit" cell.

 

What I've tried:

I tried adding an index column and then splitting "Colors" and "Fruit" by delimiter (to rows), but I get a huge number of new rows and duplicate information that I don't know how to work my way out of...

IndexNameColorsFruit
0BobYellowBanana
0BobYellow

Apple

0BobYellowGrape
0BobYellowBlueberry
0BobRedBanana
0BobRedApple
0BobRedGrape
0BobRedBlueberry
etc.   
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

HI @paul_cranberry 

Here's one way of handling it.

Requires writing a little M code rather than pure interface.

Is this the sort of thing you're looking for?

let
  Source = #table(
    type table [Name = text, Colors = text, Fruit = text],
    {
      {"Bob", "Yellow; Red; Green; Blue", "Banana; Apple; Grape; Blueberry"},
      {"Karen", "Green; Blue; Brown", "Grape; Blueberry; Kiwi"}
    }
  ),
  #"Split Text into Lists" = Table.TransformColumns(
    Source,
    {
      {"Colors", Splitter.SplitTextByDelimiter("; "), type {text}},
      {"Fruit", Splitter.SplitTextByDelimiter("; "), type {text}}
    }
  ),
  #"Zip Lists" = Table.CombineColumns(
    #"Split Text into Lists",
    {"Colors", "Fruit"},
    each List.Zip({_{0}, _{1}}),
    "Matched Pairs"
  ),
  #"Combine Each Pair Hyphen" = Table.TransformColumns(
    #"Zip Lists",
    {{"Matched Pairs", each List.Transform(_, Combiner.CombineTextByDelimiter(" - "))}}
  ),
  #"Combine Pairs Semicolon" = Table.TransformColumns(
    #"Combine Each Pair Hyphen",
    {{"Matched Pairs", Combiner.CombineTextByDelimiter("; ")}}
  )
in
  #"Combine Pairs Semicolon"

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

HI @paul_cranberry 

Here's one way of handling it.

Requires writing a little M code rather than pure interface.

Is this the sort of thing you're looking for?

let
  Source = #table(
    type table [Name = text, Colors = text, Fruit = text],
    {
      {"Bob", "Yellow; Red; Green; Blue", "Banana; Apple; Grape; Blueberry"},
      {"Karen", "Green; Blue; Brown", "Grape; Blueberry; Kiwi"}
    }
  ),
  #"Split Text into Lists" = Table.TransformColumns(
    Source,
    {
      {"Colors", Splitter.SplitTextByDelimiter("; "), type {text}},
      {"Fruit", Splitter.SplitTextByDelimiter("; "), type {text}}
    }
  ),
  #"Zip Lists" = Table.CombineColumns(
    #"Split Text into Lists",
    {"Colors", "Fruit"},
    each List.Zip({_{0}, _{1}}),
    "Matched Pairs"
  ),
  #"Combine Each Pair Hyphen" = Table.TransformColumns(
    #"Zip Lists",
    {{"Matched Pairs", each List.Transform(_, Combiner.CombineTextByDelimiter(" - "))}}
  ),
  #"Combine Pairs Semicolon" = Table.TransformColumns(
    #"Combine Each Pair Hyphen",
    {{"Matched Pairs", Combiner.CombineTextByDelimiter("; ")}}
  )
in
  #"Combine Pairs Semicolon"

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors