How to Use Power Query Queries and Steps as Variables
Question details
The user wants to know how to reference entire Power Query queries and individual query steps as variables to build dynamic data transformations.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Building dynamic tables, combining data sources, fuzzy matching, or setting up percentage calculations in complex data models.
- Observed behavior
- The goal is to reuse query results and earlier steps as values or variables to simplify complex transformations and maintain reusable data models.
Ensure you have your dataset loaded into the Power Query Editor and are comfortable accessing the Advanced Editor, as referencing steps often requires interacting directly with M code.
Reference Existing Queries as Variables
Reuse the output of an entire query as a starting point or variable in another query to prevent duplicating data extraction steps.
By referencing a query, you create a linked dependency. Any updates made to the original query will automatically flow through to the referenced query, making your data model much easier to maintain.
In the Power Query Editor, expand the left-hand Queries pane to view all your active queries.
Right-click the query you want to use as a variable or base, and select 'Reference' from the context menu.
A new query will be created with the original query's output as its source. You can now add new steps, merge it with other tables, or use it for isolated calculations.

Reference Individual Steps as Variables in the Advanced Editor
Use the Advanced Editor to manually call previous step names as variables for dynamic calculations, such as percentages or custom filtering.
Simplify Your Data Analysis with WPS Office
While advanced M code scripting is exclusive to Microsoft Excel's Power Query, you can perform powerful data transformations, merging, and filtering effortlessly using WPS Spreadsheet. It offers a familiar interface, highly compatible formatting, and essential data tools for free.
- 1. Download and Install: Get WPS Office from the official website and install it on your Windows, Mac, or Linux device.
- 2. Open Your Excel File: Launch WPS Spreadsheet and seamlessly open your existing .xlsx workbooks without losing any formatting.
- 3. Utilize Data Tools: Navigate to the Data tab to use PivotTables, Data Validation, and Advanced Filtering to analyze your data dynamically.

Frequently Asked Questions
Why do my Power Query step names have a hashtag and quotes?
In Power Query's M language, step names containing spaces are automatically wrapped in a hashtag and double quotes (e.g., #"Added Custom"). You must include this exact formatting when referencing the step as a variable in the Advanced Editor.
Can I reference a query step from a completely different query?
No, individual steps are scoped only to their specific query. To reuse data from another query, you must reference the entire query as a data source, rather than trying to call its internal steps.
Does referencing a query duplicate the data load?
No, referencing a query creates a logical link rather than duplicating the source data load. This helps optimize performance and keeps your data model efficient by preventing multiple calls to the underlying database or file.




