Creating conditional columns
A conditional column fills each row with a value chosen by a set of if-then rules. Power Query has a dialog for building these rules, so a common need such as grouping values into bands takes no M at all.
The example
Section titled “The example”This page adds an age band to a customer table, using these bands:

A banded column like this works well as a slicer or a grouping in any report built on the data.
1. Find the Conditional Column button
Section titled “1. Find the Conditional Column button”The data is the customer table from Microsoft’s AdventureWorks sample database, loaded into Power Query. Conditional Column sits in the General group of the Add Column tab:

2. Add an age column
Section titled “2. Add an age column”The bands need an age to test, so the first job is to work one out from the birth date:
- Select the Birth Date column, then on the Add Column tab choose Date, then Year, then Year. This adds a column holding the year of birth, and keeps the original Birth Date column.

- Edit the new step’s code in the formula bar. Power Query writes something like this:
= Table.AddColumn(_Customers, "Custom", each Date.Year([BirthDate]), type number)- Change it to this, which subtracts the year of birth from the current year and names the column Age:
= Table.AddColumn(#"Removed Columns", "Age", each Date.Year(DateTime.LocalNow()) - Date.Year([Birth Date]), Int64.Type)The result is only approximate, because it ignores whether the customer has had this year’s birthday yet, but it is close enough for this example.
3. Build the bands
Section titled “3. Build the bands”- Click Conditional Column, which opens the Add Conditional Column dialog:

- Name the column Age Band, and use Add Clause to build one rule for each band, choosing the column, the operator, the value and the output for each:

The order of the rules matters. Power Query tests them from the top down and stops at the first one that is true, so each rule only has to set the lower limit of its band. Starting from the highest band means that by the time a row reaches is greater than 50, any age over 60 has already been caught.
4. Check the result
Section titled “4. Check the result”Click OK, and the new Age Band column appears beside Age:

The same column could always have been written by hand as a custom column, with if … then … else in M. The dialog writes that M for you, which makes the technique open to anyone, whether or not they know the language.