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
Leeroy444
New Member

Loop through Inner Join Merge to Filter Table

Hi Everyone, 

I have a data_table and a filter_table.  I would like to use the filter_table to filter the data_table.  This allows users to define a complex set of filters in a concise way. The headings of the filter_table would match the data_table

 

I would like to dynamicaly loop through each column on the filter_table and perform seperate merges for each column so that the filter_table can varied by creating more columns

 

One method is that I can apply a single column of filter values from filter_table using an inner join between the two tables, and then removing the joined table as follows. Note:  Performing a join with several columns is not suitable as this applies each row of filter table as a complex filter.

 

#"Merged Queries" = Table.NestedJoin(data_table, {"Column1"}, filter_table, {"Column1"}, "join", JoinKind.Inner),
#"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"join"})

 

 

Example filter_table:

Column1Column2Column3
A1text1
B2text4

 

Example data_table

Column1Column2Column3Column4Column5Column6
A1text1otherdata1other1data1
A4text3otherdata2other2data2
A5text4otherdata3other3data3
B2text5otherdata4other4data4
B4text6otherdata5other5data5
B7text7otherdata6other6data6
B1text4otherdata7other7data7
C9text9otherdata8other8data8
C1text4otherdata9other9data9
C1text7otherdata10other10data10
C1text8otherdata11other11data11
D8text9otherdata12other12data12
D3text10otherdata13other13data13
D2text4otherdata14other14data14
D2text9otherdata15other15data15
D2text10otherdata16other16data16

 

 

Expected result

Column1Column2Column3Column4Column5Column6
A1text1otherdata1other1data1
B1text4otherdata7other7data7

 

(I am only really considering exact match filters, but bonus points if its possible to add criteria, i.e.  Column2<3)

1 ACCEPTED SOLUTION
Mahesh0016
Super User
Super User

@Leeroy444 

 

let
Source = Table.NestedJoin(Filter_Table, {"Product"}, Table.SelectRows(Data_Table, each [ID] < 2), {"Product"}, "Data_Table", JoinKind.Inner),
#"Expanded Data_Table" = Table.ExpandTableColumn(Source, "Data_Table", {"Category", "Category 1", "Category 2"}, {"Data_Table.Category", "Data_Table.Category 1", "Data_Table.Category 2"})
in
#"Expanded Data_Table"

 

Mahesh0016_0-1673591337890.png

 

 

@Leeroy444 If this post helps, please consider accept as solution to help other members find it more quickly and Appreciate your Kudos.

View solution in original post

1 REPLY 1
Mahesh0016
Super User
Super User

@Leeroy444 

 

let
Source = Table.NestedJoin(Filter_Table, {"Product"}, Table.SelectRows(Data_Table, each [ID] < 2), {"Product"}, "Data_Table", JoinKind.Inner),
#"Expanded Data_Table" = Table.ExpandTableColumn(Source, "Data_Table", {"Category", "Category 1", "Category 2"}, {"Data_Table.Category", "Data_Table.Category 1", "Data_Table.Category 2"})
in
#"Expanded Data_Table"

 

Mahesh0016_0-1673591337890.png

 

 

@Leeroy444 If this post helps, please consider accept as solution to help other members find it more quickly and Appreciate your Kudos.

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