Power Query - Filter Using Workbook Table

Caleeco

Well-known Member
Joined
Jan 9, 2016
Messages
980
Office Version
  1. 2010
Platform
  1. Windows
Hello,

- I have about 10 data sources which I have Imported/Merged using Power query into 1 table, lets call this qryOUTPUT, and is loaded as 'Only Connection'
- In qryOUTPUT I have field called Part (Text type)
- I want to have a local table in the workbook called tbl_Part_Entry (user entry)
- I am then planning to have a MERGE (inner Join) to filter qryOUTPUT.Part based on tbl_Part_Entry (user entry)

The Problem
What can I put in tbl_Part_Entry, when I want to return all rows of qryOUTPUT? I've tried using "*", but get 0 rows returned as its doing a literal comparison.

Any help is appreciated
Cheers
Caleeco
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
as example
with value in DV list
SourceDVListResult
NameValueItemAndyNameValueItem
Andy6cupAndy6cup
Alan3glassAndy4pen
Mike11wanad
Andy4pen
Alan5knife

without value in DV list
SourceDVListResult
NameValueItemNameValueItem
Andy6cupAndy6cup
Alan3glassAlan3glass
Mike11wanadMike11wanad
Andy4penAndy4pen
Alan5knifeAlan5knife

Rich (BB code):
let
    DV = Excel.CurrentWorkbook(){[Name="dv"]}[Content],
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Mrg = Table.NestedJoin(DV,{"Column1"},Source,{"Name"},"Source", if DV{0}[Column1] = null then JoinKind.RightAnti else JoinKind.LeftOuter),
    Exp = Table.ExpandTableColumn(Mrg, "Source", {"Item", "Name", "Value"}, {"Item", "Name", "Value"}),
    TSC = Table.SelectColumns(Exp,{"Name", "Value", "Item"})
in
    TSC
if this is what you want, adapt to your needs
 
Upvote 0
Hi Sandy!

Thanks for getting back to me. Really appreciate you helping me with these PQ problems (i'm a noob! ?)

That looks to be almost exactly what I need! The only difference it the Source is another Query in the workbook.

I'll see if I can modify your code and get it working tomorrow (whilst Im at work).

I'll report back to let you know how I get on!

Thanks
Caleeco
 
Upvote 0
The only difference it the Source is another Query in the workbook.
Do all in that Query or New Blank Query then Source = Query1 (where Query1 is the name of your another Query) but imho all-in-one is a better option
would be fine to see structure of data and M
you can theorize for 20 or more posts and nothing will come of it :biggrin:
 
Last edited:
Upvote 0
Do all in that Query or New Blank Query then Source = Query1 (where Query1 is the name of your another Query) but imho all-in-one is a better option
would be fine to see structure of data and M
you can theorize for 20 or more posts and nothing will come of it :biggrin:

I haven't really used the Advanced editor before, been sticking to the GUI withing Power Query & Excel, this resulted in many tables of data being created.

I took your advice and re-did it all in one Query! M is shown below, apologies if this is messy!

Rich (BB code):
let
ZQM14 = Table.NestedJoin(ZQM14, {"Vendor"}, tbl_VendorGroup, {"Vendor Code"}, "tbl_VendorGroup", JoinKind.LeftOuter),
#"Expanded tbl_VendorGroup" = Table.ExpandTableColumn(ZQM14, "tbl_VendorGroup", {"Vendor Group"}, {"tbl_VendorGroup.Vendor Group"}),
ZQM14.VG = Table.ReplaceValue(#"Expanded tbl_VendorGroup",null,"Other",Replacer.ReplaceValue,{"tbl_VendorGroup.Vendor Group"}),

Merge.WC = Table.NestedJoin(ZQM14.VG, {"Unit to be insp."}, tbl_WorkCentreTable1, {"Work Centre"}, "tbl_WorkCentreTable1", JoinKind.LeftOuter),
#"Expanded tbl_WorkCentreTable1" = Table.ExpandTableColumn(Merge.WC, "tbl_WorkCentreTable1", {"Work Centre Name"}, {"tbl_WorkCentreTable1.Work Centre Name"}),
ZQM14.WC = Table.ReplaceValue(#"Expanded tbl_WorkCentreTable1",null,"Omitted",Replacer.ReplaceValue,{"tbl_WorkCentreTable1.Work Centre Name"}),

Merge.ZQM12 = Table.NestedJoin(ZQM14.WC, {"Notification"}, ZQM12, {"Notification"}, "ZQM12", JoinKind.LeftOuter),
#"Expanded ZQM12" = Table.ExpandTableColumn(Merge.ZQM12, "ZQM12", {"Reference number"}, {"ZQM12.Reference number"}),
ZQM14.ZQM12 = Table.ReplaceValue(#"Expanded ZQM12",null,"",Replacer.ReplaceValue,{"ZQM12.Reference number"}),

Merge.COOIS = Table.NestedJoin(ZQM14.ZQM12, {"ZQM12.Reference number"}, COOIS, {"Order"}, "COOIS", JoinKind.LeftOuter),
#"Expanded COOIS" = Table.ExpandTableColumn(Merge.COOIS, "COOIS", {"Rework Hours"}, {"COOIS.Rework Hours"}),
ZQM14.COOIS = Table.ReplaceValue(#"Expanded COOIS",null,0,Replacer.ReplaceValue,{"COOIS.Rework Hours"}),

Merge.LTH = Table.NestedJoin(ZQM14.COOIS, {"ZI33 H"}, LongText_Header, {"Object Reference"}, "LongText_Header", JoinKind.LeftOuter),
#"Expanded LongText_Header" = Table.ExpandTableColumn(Merge.LTH, "LongText_Header", {"Header Long Text"}, {"LongText_Header.Header Long Text"}),
ZQM14.LTH = Table.ReplaceValue(#"Expanded LongText_Header",null,"Long Text Missing",Replacer.ReplaceValue,{"LongText_Header.Header Long Text"}),

Merge.LTI = Table.NestedJoin(ZQM14.LTH, {"ZI33 I"}, LongText_Items, {"Object Reference"}, "LongText_Items", JoinKind.LeftOuter),
#"Expanded LongText_Items" = Table.ExpandTableColumn(Merge.LTI, "LongText_Items", {"Items Long Text"}, {"LongText_Items.Items Long Text"}),
ZQM14.LTI = Table.ReplaceValue(#"Expanded LongText_Items",null,"Long Text Missing",Replacer.ReplaceValue,{"LongText_Items.Items Long Text"}),

Merge.LTC = Table.NestedJoin(ZQM14.LTI, {"ZI33 C"}, LongText_Causes, {"Object Reference"}, "LongText_Causes", JoinKind.LeftOuter),
#"Expanded LongText_Causes" = Table.ExpandTableColumn(Merge.LTC, "LongText_Causes", {"Cause Long Text"}, {"LongText_Causes.Cause Long Text"}),
ZQM14.LTC = Table.ReplaceValue(#"Expanded LongText_Causes",null,"Long Text Missing",Replacer.ReplaceValue,{"LongText_Causes.Cause Long Text"})

in
ZQM14.LTC

So I have a Query called 'Material Selection' (imported as a data table into PQ). This list will change as the User will paste in the materials they wish to see data for.

Rich (BB code):
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Material", type text}})

in

#"Changed Type"

This table has 1 column called 'Material' which can have No Data (null), 1 Material in row 1, or multiple Materials which I want to use to filter ZQM14.LTC in the following manner.

Material Selection Table PossibilitiesReturn from ZQM14.LTC
Blank (Null)All rows
1 Material eg ID1020All rows where Material = ID1020
Multiple Materials eg ID1020, ID1021, ID1022 (all on separate rows)All rows where Material = ID1020 or Material = ID1022 or Material = ID1022

So I need to be able to filter the Material field in ZQM14.LTC based on the Material Selection (which is a table on the workbook). Noting the ZQM14.LTC table has many columns, too many to list in the fashion shown in your example. Is there a way to accomplish this goal?

Hopefully that makes sense!

Thanks for your help ?

Caleeco
 
Upvote 0
ok,
first of all I suggest to use short labels in steps, eg.
#"Expanded tbl_VendorGroup" = Table.ExpandTableColumn(ZQM14, "tbl_VendorGroup", {"Vendor Group"}, {"tbl_VendorGroup.Vendor Group"}),
to
tbl_VendorGroup = Table.ExpandTableColumn(ZQM14, "tbl_VendorGroup", {"Vendor Group"}, {"tbl_VendorGroup.Vendor Group"}),
because repeat the same is not necessary. I see this is Expand :)
or just ExpVendorGroup =
some people write poems like: #"This is first step which Expand table from blabla bla bla bla bla" = ... ;)

second: does your table ZQM14.LTC (result of the big M above) contain column Material?

third: create list from table3 for DataValidationList (classic Data Validation) then use as first line in the big Query

DV = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
then merge DV with ZQM14.LTC by [Material] after last step in you big Query as you can see in my M with Mrg step

there will be some differences because I used named range, if you've table, the name of column in DV will be different not Column1, I think
 
Last edited:
Upvote 0
too late... cannot edit post above
my [Column1] will be your [Material Selection Table Possibilities] (again poem :biggrin: ), maybe simply: [Choose Material] ?
 
Upvote 0
to be clear
dvdef.png

pqdv.png
 
Last edited:
Upvote 0
Hi Sandy,

Thanks for the additional input, it's really helpful!

I had a play around with it and modified it slightly.
- I needed an Inner Join so that I could Match for multiple materials.
- I switched to a table input instead of a Data Validation list (again so I can pick multiple parts)

Note: I did try using short labels, but was getting a circular reference error. So I just used prefixes of exp. This is my latest M Code (only the last step) which seems to work in testing!

So thank you again for your help, I really appreciate your time :)

Rich (BB code):
    Merge.LTC = Table.NestedJoin(ZQM14.LTI, {"ZI33 C"}, LongText_Causes, {"Object Reference"}, "LongText_Causes", JoinKind.LeftOuter),
    expLongText_Causes = Table.ExpandTableColumn(Merge.LTC, "LongText_Causes", {"Cause Long Text"}, {"LongText_Causes.Cause Long Text"}),
    ZQM14.LTC = Table.ReplaceValue(expLongText_Causes,null,"Long Text Missing",Replacer.ReplaceValue,{"LongText_Causes.Cause Long Text"}),
    
    Merge.Out = Table.NestedJoin(ZQM14.LTC, {"Material"}, Material_Selection, {"Material"}, "Material_Selection", if Material_Selection{0}[Material]=null then JoinKind.LeftAnti else JoinKind.Inner)
in
    Merge.Out
 
Upvote 0
You are welcome :)

My M and suggestion about labels are NOT MANDATORY (as I said this is example only) but M looks more clear and less scrolling horizontally :biggrin:
btw. use underscore instead of dot, less troubles in the future with more complicated queries
eg. Merge.Out ==> Merge_Out

I am glad it works for you, thanks for the feedback (y)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top