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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PHO
Frequent Visitor

Merge Table 1 Column A to Table 2 Column A,B or C

Is it possible to make a left outer join.
I have a value in Table 1 Column A, and this Value can appear in table 2 Column A,B or C.
If this happens I want to merge them.

It was a comma  sepereated value in Table 2 which I had splitted.

________________________________________________________
So I want to find out whether a product group from Table 1 is contained in Table 2, in which more than one product group is grouped. Perhaps a "contains merge" would also work for the grouped non splitted Column.
I wasn't able to do this with fuzzy matching every time something was missing.

1 ACCEPTED SOLUTION

@PHO

Result

dufoq3_0-1719407654083.png

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1PSc0xVNJRclSK1YFyjYBcJwTXGMh1VoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Model = _t, Category = _t]),
    Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JYq5DQAwCMR2oabJX5NkC5T918hxFJZsye5SRInJU5cKCzarwYLD6rDgsgYsMM13wic77wVfbPzvAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Data 1" = _t, #"Data 2" = _t, Category = _t]),
    SplitColumnByDelimiter = Table.SplitColumn(Table2, "Category", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Category.1", "Category.2"}),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(SplitColumnByDelimiter, List.Select(Table.ColumnNames(SplitColumnByDelimiter), (x)=> not Text.StartsWith(x, "Category.")) , "Attribute", "Category"),
    MergedQueries = Table.NestedJoin(Table1, {"Category"}, UnpivotedOtherColumns, {"Category"}, "UnpivotedOtherColumns", JoinKind.LeftOuter),
    Expanded = Table.ExpandTableColumn(MergedQueries, "UnpivotedOtherColumns", {"Data 1", "Data 2"}, {"Data 1", "Data 2"}),
    SortedRows = Table.Sort(Expanded,{{"Model", Order.Ascending}})
in
    SortedRows

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

View solution in original post

8 REPLIES 8
PHO
Frequent Visitor

Thanks for the answer @dufoq3 

, I hope the example is clear enough.
I am searching for the Model category in Table 1 in Table 2, the result is shown in Result.

The file (or is there a better way to share? xlsx xls and zip aren't allowed to upload here):
https://file.io/l6LhnmE4Nxqr

dufoq3_0-1719398192329.png

 


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

 

let
    Table1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Table2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    dict = Record.FromList(Table1[Model], Table1[Category]),
    trn = Table.TransformColumns(Table2, {"Category", Splitter.SplitTextByDelimiter(",")}),
    expand = Table.ExpandListColumn(trn, "Category"),
    add_model = Table.AddColumn(expand, "Model", (x) => Record.FieldOrDefault(dict, x[Category])),
    filter = Table.SelectRows(add_model, each ([Model] <> null))
in
    filter

 

PHO
Frequent Visitor

I will try it with your suggestion.
And here is another hopefully working sharing link
https://filetransfer.io/data-package/M35pGd0u#link

Or based on your second Link:
table 1

ModelCategory
Model1A
Model2B
Model3C


table2

Data 1Data 2Category
11A
22B
33C
44D
55A,B
66A,C
77A,D

Result:

ModelCategoryData1Data2
Model1A11
Model1A55
Model1A66
Model1A77
Model2B22
Model2B55
Model3C33
Model3C66
Anonymous
Not applicable

Hi @PHO 

 

Here is another approach for your reference. 

Step 1: In Table2, split Category column by delimiter comma and expand the results into rows

vjingzhanmsft_0-1719456818557.png

This will transform Table2 into below format

vjingzhanmsft_1-1719456987528.png

 

Step 2: In Table1, use Merge queries feature to merge data from Table2 to Table1. Select Category column as matching column and select Left Outer join. After merging, expand the colums you want. This will finally give you the expected result. 

vjingzhanmsft_2-1719457287042.png

 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

PHO
Frequent Visitor

Thanks this is also a great solution which I wasn't aware of.

@PHO

Result

dufoq3_0-1719407654083.png

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1PSc0xVNJRclSK1YFyjYBcJwTXGMh1VoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Model = _t, Category = _t]),
    Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JYq5DQAwCMR2oabJX5NkC5T918hxFJZsye5SRInJU5cKCzarwYLD6rDgsgYsMM13wic77wVfbPzvAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Data 1" = _t, #"Data 2" = _t, Category = _t]),
    SplitColumnByDelimiter = Table.SplitColumn(Table2, "Category", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Category.1", "Category.2"}),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(SplitColumnByDelimiter, List.Select(Table.ColumnNames(SplitColumnByDelimiter), (x)=> not Text.StartsWith(x, "Category.")) , "Attribute", "Category"),
    MergedQueries = Table.NestedJoin(Table1, {"Category"}, UnpivotedOtherColumns, {"Category"}, "UnpivotedOtherColumns", JoinKind.LeftOuter),
    Expanded = Table.ExpandTableColumn(MergedQueries, "UnpivotedOtherColumns", {"Data 1", "Data 2"}, {"Data 1", "Data 2"}),
    SortedRows = Table.Sort(Expanded,{{"Model", Order.Ascending}})
in
    SortedRows

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

dufoq3
Super User
Super User

Hi @PHO, yes it is possible. If you can provide sample data and expected result based on sample data - we can help you 😉


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

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