How to Create Custom Formula Columns in Power Query
Question details
The user needs to create custom formula columns in Power Query to retrieve specific data like item codes, suppliers, and quantities based on a dynamic worksheet name after appending multiple queries.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Transforming and consolidating data from multiple worksheets using Power Query.
- Observed behavior
- The data needs to be conditionally shaped using Power Query M functions rather than traditional worksheet formulas or VBA scripts.
Ensure your worksheets are correctly imported into Power Query and that your initial queries are successfully appended with duplicates removed before adding new calculations.
Add a Custom Column using Power Query M Formulas
Use the built-in Custom Column feature alongside M functions to dynamically calculate and extract item codes, suppliers, and quantities.
Power Query can seamlessly handle dynamic data retrieval without the need for complex VBA scripting. By utilizing the 'Custom Column' feature, you can employ M functions such as Table.SelectRows, List.Sum, and conditional logic (if/then/else) to shape your appended dataset.
Navigate to the 'Data' tab on your Excel ribbon and select 'Get Data' or 'Queries & Connections' to open your existing appended query in the Power Query Editor.
In the Power Query Editor, go to the 'Add Column' tab on the top ribbon and click on 'Custom Column'.
In the Custom Column dialog box, enter a new column name. In the formula box, write your M code using conditional expressions or functions like Table.SelectRows to fetch the specific supplier or quantity based on the worksheet name.
If your worksheet names change dynamically, ensure your source step references the 'Item' or 'Name' column from the workbook metadata rather than hardcoding sheet names.
Once your custom columns are generating the correct values, go to the 'Home' tab and click 'Close & Load' to return the transformed data to your worksheet.

Streamline Your Data Analysis with WPS Office
If you are looking for a highly compatible and cost-effective solution for complex data management, WPS Office is an excellent free alternative to Microsoft Office. It easily handles vast datasets and provides robust data analysis tools without the steep learning curve.
- 1. Download and Install: Visit the WPS Office official website to download the free installation package for your operating system.
- 2. Open Your Excel Files: Launch WPS Spreadsheet and open your existing .xlsx files directly. All your data and traditional formulas will be instantly recognized.
- 3. Analyze Data: Utilize WPS Spreadsheet's built-in data tools, PivotTables, and advanced formulas to manipulate and summarize your datasets effectively.

Frequently Asked Questions
Do I need to write VBA macros to combine data from multiple worksheets?
No, Power Query allows you to append multiple queries and consolidate data using its graphical interface and M formula language, completely bypassing the need for VBA macros.
How do I update my custom columns when a new worksheet is added?
Power Query is highly dynamic. Once your queries and custom columns are set up, you simply need to click the 'Refresh All' button on the Data tab. Any new worksheets included in your source folder or workbook will automatically be processed through your applied steps.
Why does my Custom Column show an 'Error' value?
Errors in custom columns usually occur due to data type mismatches (e.g., trying to add text and numbers together) or incorrect casing in your M functions. Click on the whitespace next to the 'Error' text in the Power Query Editor to see the detailed error message at the bottom of the screen.




