Identity.From

Identity.From

D

The M Code Behind the Power Query M function Identity.From

What is Identity.From?

The Identity.From function is a simple yet powerful function in the M language. It allows you to create a new column in your query that is an exact copy of an existing column. This is useful when you want to apply additional transformations to the data in the copied column, or when you want to rename the column.

The syntax for Identity.From is as follows:


= Table.AddColumn(Source, NewColumnName, each [ExistingColumnName])


Here, Source is the name of the table or query you are working with, NewColumnName is the name you want to give to the new column, and ExistingColumnName is the name of the column you want to copy.

How to Use Identity.From

Using Identity.From is very straightforward. Simply follow these steps:

1. Open Power Query and create a new query.

2. Load the data you want to work with.

3. Select the column you want to copy.

4. Click the "Add Column" tab on the ribbon.

5. Click "Custom Column".

6. In the "Custom Column" dialog box, enter the following formula:


= Table.AddColumn(#”Previous Step”, “New Column Name”, each [Existing Column Name])


7. Replace "Previous Step" with the name of the previous step in your query, "New Column Name" with the name you want to give to the new column, and "Existing Column Name" with the name of the column you want to copy.

8. Click "OK" to close the dialog box.

9. The new column will be added to your query, with the same data as the column you copied.

Why Use Identity.From?

At first glance, it might seem like Identity.From is not very useful. After all, why would you want to copy data from one column to another without making any changes? However, there are several reasons why this function can be very helpful in your Power Query projects.

Renaming Columns

One of the most common reasons to use Identity.From is to rename a column. For example, suppose you have a table with a column named "Sales". You might want to rename this column to "Revenue" to better reflect the data it contains. Instead of manually copying the data to a new column and deleting the old one, you can simply use Identity.From to create a new column that is an exact copy of the original, with a new name.

Applying Multiple Transformations

Another reason to use Identity.From is to apply multiple transformations to the same data. For example, suppose you have a column with a long string of text that you want to split into multiple columns. Instead of splitting the text and creating new columns manually, you can use Identity.From to copy the original column to a new column, and then apply the split transformation to the new column.

Creating Backup Columns

Finally, Identity.From can be useful for creating backup columns. Suppose you have a complex query with multiple transformations, and you want to make some changes to it. Before you make any changes, you might want to create a backup copy of the original data. You can use Identity.From to copy the existing columns to new columns, and then make your changes to the new columns without affecting the original data.

In conclusion, Identity.From is a simple but powerful function in the M language. It allows you to create a new column in your query that is an exact copy of an existing column. This can be useful for renaming columns, applying multiple transformations, and creating backup copies of your data. If you use Power Query regularly, you should definitely add Identity.From to your toolkit.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

Subject

Your Name (required)

Company/Organisation

Email (required)

Telephone

Training Course(s)

Your Message

Upload Example Document(s) (Zip multiple files)

Copyright, G Com Solutions Ltd, 2024.
Tower Bridge Business Centre, 46-48 East Smithfield, London E1W 1AW
0800 998 9248   |   9:00 a.m. till 5:30 p.m.

Connect With Me: