Thursday, April 27, 2017

Insert a custom column into a table (Power Query)

Insert a custom column into a table (Power Query)

Note: Power Query is known as Get & Transform in Excel 2016. Information provided here applies to both. To learn more, see Get & Transform in Excel 2016.

Note: Qery Editor only appears when you load, edit, or create a new query. For a quick video on how to display Query Editor, see the end of this article.

With Power Query, you can add an Index or Custom (you define the formula) column to your current query. When you create a column formula, Power Query will validate the formula syntax. This validation experience is consistent with how the Advanced Query Editing dialog validates formulas provided by you.

I want to

Insert an Index Column

Insert a Custom Column

Insert an Index Column

Using the Query Editor ribbon

  1. In the Query Editor ribbon, click Insert Index Column.

Using the table icon ( Table icon ) in the preview grid

  1. Click the table icon ( Table icon ).

  2. From the context menu, select Insert Index Column. An Index column is added in the query table. Rename the column name as required.

Top of Page

Insert a Custom Column

A custom column is a column where the value in a cell is computed using a formula that you create. For more information about the Power Query Formula Language, see Learn about Power Query formulas.

Using the Query Editor ribbon

  1. In the Query Editor ribbon, click Insert Custom Column.

Using the table icon ( Table icon ) in the preview grid

  1. Click the table icon ( Table icon ), and click Insert Custom Column.

To insert a custom column

  1. In the Insert Custom Column dialog box, enter a column name, and insert a column into the Custom Column Formula box:

    1. Double click a column from the Available Columns list or

    2. Click a column from the Available Columns list, and click Insert.

      Note:  You can use multiple reference columns as long as you separate them with some operator. For example, to calculate a TotalSales column, you add Total and SalesTax using the formula = each [Total] + [SalesTax].

  2. Click OK.

Example formulas

Formula

Description

"abc"

Creates a column with the text abc in all rows.

1+1

Creates a column with the result of 1 + 1 (2) in all rows.

[UnitPrice] * [Quantity]

Creates a column with the result of multiplying two table columns.

[UnitPrice] * (1 – [Discount]) * [Quantity]

Calculates the total price, considering the Discount column.

"Hello" & [Name]

Combines Hello with the contents of the Name column in a new column.

Note:  You can use custom column to merge values from two or more columns into a single custom column. For more information, see Merge columns.

With Power Query, Custom Columns, conditional formatting in Excel, and other customizations of worksheet tables are preserved after you refresh a query. Power Query will preserve worksheet customizations such as Data Bars, Color Scales, Icon Sets or other value-based rules across refresh operations and after query edits.

Custom Columns

Top of Page

Note: The Query Editor only appears when you load, edit, or create a new query using Power Query. The following video shows the Query Editor window appearing after editing a query from an Excel workbook. To view the Query Editor without loading or editing an existing workbook query, from the Get External Data section in the Power Query ribbon tab, select From Other Sources > Blank Query. The following video shows one way to display the Query Editor.

How to see Query Editor in Excel

No comments:

Post a Comment