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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
witbi
Helper I
Helper I

Create an intersection table from reference and transaction tables

Hello,


I have a reference table (a) with values that I would like to look up in a transaction table (b) across multiple columns "Location" and "Interests" and generate a new intersection table (c).

The reference table has text.startwith values like "cycl" so I can match "cycle" or "cycling". Duplicated relationships are ok as I can remove them later.

Any help would be most appreciated! Thank you and happy new year.

a) Reference table

ID_categoryValue
1UK
2Canada
3Australia
4cycl
5travel
6read
7theatre
8cook
9sport
10garden

 
b) transaction table

ID_personNameLocationInterests
1AlexLondon, UKTraveling, going to the theatre, gardening are my weekend pleasures
2BevToronto, CanadaI'm a world traveler. Most recently I cycled the UK on a 20 day food and cooking tour
3CathSydney, AusstraliaI'm an avid sports fan. I belong to a sports travel club that's visited Canada for ice hockey and Europe for cycling
4DeanGlasgow, UKI started a book club that reads 10 books a month. We're all avid readers! 
5EdMontreal, CanadaI get the most joy from cooking with the freshest ingredients direct from my garden


c) intersection table (new table)

ID_categoryID_personColumn
11Location
15Interests
110Interests
22Location
25Interests
21Interests
28Interests
33Location
39Interests
32Interests
34Interests
41Location
46Interests
52Location
58Interests
510Interests
2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

= let a=Table.Buffer(Table.UnpivotOtherColumns(TransactionTable,{"ID_person","Name"},"Attributes","Value")) in Table.Sort(#table({"ID_person","ID_category","Custom"},List.TransformMany(Table.ToRows(Table.AddColumn(ReferenceTable,"n",(x)=>Table.SelectRows(a,each Text.Contains([Value],x[Value],Comparer.OrdinalIgnoreCase)))),each Table.ToRows(_{2}),(x,y)=>{y{0},x{0},y{2}})),"ID_person")

View solution in original post

let me guess

= let a=Table.Buffer(TransactionTable) in Table.Sort(#table({"ID_person","ID_category"},List.TransformMany(Table.ToRows(Table.AddColumn(ReferenceTable,"n",(x)=>Table.SelectRows(a,each not List.Contains(List.Skip(Record.ToList(_),2),x[Value],(m,n)=>Text.Contains(m,n,Comparer.OrdinalIgnoreCase))))),each Table.ToRows(_{2}),(x,y)=>{y{0},x{0}})),"ID_person")

View solution in original post

5 REPLIES 5
wdx223_Daniel
Super User
Super User

= let a=Table.Buffer(Table.UnpivotOtherColumns(TransactionTable,{"ID_person","Name"},"Attributes","Value")) in Table.Sort(#table({"ID_person","ID_category","Custom"},List.TransformMany(Table.ToRows(Table.AddColumn(ReferenceTable,"n",(x)=>Table.SelectRows(a,each Text.Contains([Value],x[Value],Comparer.OrdinalIgnoreCase)))),each Table.ToRows(_{2}),(x,y)=>{y{0},x{0},y{2}})),"ID_person")

Hello again @wdx223_Daniel 

I'm also interested in the opposite case where the transaction table row does not contain the search value. Below isn't giving the desired result. Any help most appreciated. Thank you!

= let a=Table.Buffer(Table.UnpivotOtherColumns(TransactionTable,{"ID_person","Name"},"Attributes","Value")) in Table.Sort(#table({"ID_person","ID_category","Custom"},List.TransformMany(Table.ToRows(Table.AddColumn(ReferenceTable,"n",(x)=>Table.SelectRows(a,each not  Text.Contains([Value],x[Value],Comparer.OrdinalIgnoreCase)))),each Table.ToRows(_{2}),(x,y)=>{y{0},x{0},y{2}})),"ID_person")

let me guess

= let a=Table.Buffer(TransactionTable) in Table.Sort(#table({"ID_person","ID_category"},List.TransformMany(Table.ToRows(Table.AddColumn(ReferenceTable,"n",(x)=>Table.SelectRows(a,each not List.Contains(List.Skip(Record.ToList(_),2),x[Value],(m,n)=>Text.Contains(m,n,Comparer.OrdinalIgnoreCase))))),each Table.ToRows(_{2}),(x,y)=>{y{0},x{0}})),"ID_person")

Thank you! 

wdx223_Daniel this was spot on! Thank you for the new knowledge.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.