Power Query Problems

How to Create Custom Formula Columns in Power Query

Maira MehtabMaira Mehtab Nov 11, 2026 869 views

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.

How to Create Custom Formula Columns in Power Query
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.
Before you start

Ensure your worksheets are correctly imported into Power Query and that your initial queries are successfully appended with duplicates removed before adding new calculations.

Solution 1Recommended

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.

1
Open the Power Query Editor

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.

2
Add a Custom Column

In the Power Query Editor, go to the 'Add Column' tab on the top ribbon and click on 'Custom Column'.

3
Write the M Formula

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.

4
Handle Dynamic Ranges

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.

5
Close and Load

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.

Add a Custom Column using Power Query M Formulas
M Code Sensitivity: Power Query M language is strictly case-sensitive. Ensure that all function names, such as Table.SelectRows, are capitalized correctly, and verify that column names precisely match your dataset.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the WPS Office official website to download the free installation package for your operating system.
  2. 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. 3. Analyze Data: Utilize WPS Spreadsheet's built-in data tools, PivotTables, and advanced formulas to manipulate and summarize your datasets effectively.
Fully compatible with Microsoft Excel (.xlsx and .xls) formats, ensuring your formulas and datasets open seamlessly.Lightweight software that installs quickly and runs smoothly even on older devices.Familiar user interface makes migrating your daily spreadsheet tasks effortless.Comprehensive built-in data processing and visualization tools.
QA img-9

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.