How to Name and Join Filtered Tables in Power Query
Question details
The user needs to create two distinct filtered tables from a single source dataset and join them together within a Power Query script.

- Product
- Power Query / Spreadsheet
- Device & OS
- not provided
- Scenario
- Writing a custom Power Query script (M code) to process and merge multiple filtered views of the same dataset.
- Observed behavior
- Renaming queries in the Queries pane does not make those names automatically available as variables in a combined script, leading to reference errors when attempting to execute the join step.
Ensure your source data is successfully loaded into Power Query and that you are familiar with accessing the Advanced Editor to modify the M code 'let' expression.
Define Reusable Intermediate Steps in a Single Let Expression
Instead of relying on separate queries in the Queries pane, define and name your filtered tables as intermediate steps within the same query so you can reference them directly in your join function.
In Power Query M code, the 'let' expression evaluates a series of steps sequentially. By defining your filtered tables as named steps within the same block, you create local variables that can be passed seamlessly into join functions like Table.NestedJoin.
From the Power Query Editor, go to the 'Home' tab and click on 'Advanced Editor' to view the underlying M code for your query.
Ensure your source data is loaded only once at the beginning of the 'let' block. For example: `Source = Excel.CurrentWorkbook(){[Name="MyData"]}[Content]`.
Define a new step to filter the source for your first condition. Name it clearly without spaces, such as: `TableMean = Table.SelectRows(Source, each [Type] = "Mean")`.
Define another step for your second condition using the original source step: `TableSTDV = Table.SelectRows(Source, each [Type] = "STDV")`.
Use the Table.NestedJoin function to merge the two steps you just created. For example: `MergedTables = Table.NestedJoin(TableMean, {"ID"}, TableSTDV, {"ID"}, "CombinedData", JoinKind.Inner)`.
Expand the joined column as needed using `Table.ExpandTableColumn`, perform any final cleanup, and ensure the final step name matches the one specified in the 'in' clause at the bottom of the script.

Need a Lightweight Alternative for Data Processing?
While complex Power Query M scripting is specific to Microsoft Excel, WPS Office provides a highly compatible, free, and lightweight alternative for everyday spreadsheet tasks, data analysis, and advanced filtering.
- 1. Download and Install WPS Office: Visit the official WPS Office website to download the free installer for your operating system.
- 2. Open Your Spreadsheet Files: Launch WPS Spreadsheet and open your existing Excel workbooks seamlessly to continue working.
- 3. Utilize Built-in Data Tools: Use the 'Data' tab to apply advanced filters, create PivotTables, and consolidate data effortlessly.

Frequently Asked Questions
Why do I get an error when trying to reference a query name from the Queries pane in my script?
Queries in the Queries pane act as separate scripts. Unless they are correctly evaluated and loaded as functions or global variables, one script cannot natively 'see' a local variable from another without proper referencing syntax. Defining variables inside the same 'let' expression avoids this issue.
How do I reference a step name that contains spaces in Power Query?
If a step name has spaces, Power Query requires you to wrap the name in double quotes and prefix it with a hash symbol, such as #"Filtered Table". It is highly recommended to use camelCase (e.g., FilteredTable) to simplify variable referencing.
Can I join a table to itself in Power Query?
Yes, you can perform a self-join. You simply use the same previous step name for both the left and right table arguments in the Table.NestedJoin function.
Does WPS Spreadsheet support Power Query scripts (M code)?
WPS Spreadsheet currently offers powerful data analysis and extraction tools natively, but advanced Power Query M code scripting is a proprietary feature of Microsoft Office. You can process complex datasets in WPS using PivotTables, Advanced Filter, and built-in functions.




