Skip to main content
Microsoft
Support
Support
Sign in
Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.
Excel for Microsoft 365 Excel 2021 Excel 2019 Excel 2016 More...Less
In Power Query, you can add new columns by providing one or more sample values to help create it. You can do this from a current selectionor by providing input based on selectedcolumns.This is useful when you know the data you want in your new column, but you're not sure which transformations to use.
The following examples useweb data at this location: List of states and territories of the United States.
The following steps are based on the video.
-
To open a query, locate one previously loaded from the Power Query Editor, select a cell in the data, and then select Query > Edit. For more information see Create, load, or edit a query in Excel.
-
Select Add Column > Column From Examples > From All Columns.
TheAdd Columns From Examples pane appears with a new, blank column on the right.
-
Enter a sample value for the new column data you want, and then press Ctrl + Enter. In thiscase, we entered "Montgomery, AL" to combine each capital with its respective state.
To makeedits to the new column, double-click any text field,edit it, and then press Ctrl + Enter when done.
The transformation steps appear above Data Preview.
-
Select OK.
-
Examine the step added to the Applied Steps section in the Query Settings pane by right-clicking the Step and selecting Edit Settings and the corresponding formula in the formula bar.
When adding a column from examples by selection, Power Query offers a helpful list of available fields, values, and suggested transformations for the selected columns. In this example based on the data in the video, create a new column to organize the states by how many representatives each has.
-
To open a query, locate one previously loaded from the Power Query Editor, select a cell in the data, and then select Query > Edit. For more information see Create, load, or edit a query in Excel.
-
To make it more convenient, move the column to the end uponwhich you want to base the column section by selecting Transform > Move > To End. In the example, move the Number of Repscolumn.
-
Select Add Column > Column From Examples > From Selection. A blank column is added.
-
Enter "1 to 7" as a range in the first blank cell.
-
To see suggestions for all cells,press Ctrl + Enter.
See AlsoCreate a Data Model in Excel -
If you are satisfied, select OK.
Sometimes, you may need to iterate a few times to get the results you want.
Results
Power Query arranges the data by subsets according to the range you entered. A quick way to see the subsets is to select AutoFilter on the new column. For example:
After adding columns from examples, consider removing the original columns if you no longer need to display them. The new column data is not affected.
Adding a column from examples is based on the top 100 rows of Data Preview. Alternatively, you can add your own sample data, add a column example based on thatsample data, and then delete the sample data when you no longer need it. The newly created column won't be affected.
See Also
Power Query for Excel Help
Add a column from examples (docs.com)
Add a custom column
Add a column based on a data type
Power Query M formula language reference (docs.com)
Need more help?
Want more options?
Discover Community
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Microsoft 365 subscription benefits
Microsoft 365 training
Microsoft security
Accessibility center
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
Thank you for your feedback!
×