Conditional column in Power Query
Large order or not, on time or late, domestic or abroad: the conditional column classifies every row by a rule, without any formula. It is the IF of Power Query.
In short: Add Column, Conditional Column. A new column name, then the rule: if column operator value, then output; Else another value. The M code reads if … then … else.
Prerequisites: Group by.
Try it now
In this exercise the command is on the ribbon under Add Column. It needs no selected column; you choose the column in the dialog.
Task Sales distinguishes large orders from 1,000 upwards from all others. Add a conditional column Size: if Amount is greater than or equal to 1000, then Large, else Small.
| A | B | |
|---|---|---|
| 1 | OrderID | Amount |
| 2 | 1 | 1798 |
| 3 | 2 | 596 |
| 4 | 3 | 1000 |
| 5 | 4 | 229 |
| 6 | 5 | 3596 |
| 7 | 6 | 999 |
The dialog
| Field | Example |
|---|---|
| New column name | Size |
| Column Name | Amount |
| Operator | is greater than or equal to |
| Value | 1000 |
| Output | Large |
| Else | Small |
Power Query turns this into the step:
= Table.AddColumn(#"Changed Type", "Size", each if [Amount] >= 1000 then "Large" else "Small")
In the real editor, Add Clause adds more conditions (else if …), for example Small under 500, Medium under 1000, otherwise Large. The first matching clause wins, so the narrower conditions go at the top.
One more exercise: hit the limit exactly
Task Delivery within 5 days is promised. Add a conditional column Status: if DeliveryDays is greater than 5, then Late, else On time.
| A | B | C | |
|---|---|---|---|
| 1 | OrderID | Carrier | DeliveryDays |
| 2 | 302 | Northline | 3 |
| 3 | 303 | Swift & Co | 7 |
| 4 | 304 | Northline | 5 |
| 5 | 305 | River Freight | 9 |
| 6 | 306 | Swift & Co | 2 |
| 7 | 307 | River Freight | 6 |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
Conditional column or DAX?
A conditional column calculates once per row while loading. That is exactly right for fixed groupings the report groups or filters by. If the grouping depends on the selection in the report, such as "top customer in the selected year", you need a DAX measure (levels 4 and 5).
In real Power BI
- Add Column, Conditional Column in the Power Query Editor.
- Enter the rule, with Add Clause for more conditions.
- Check the data type: the new column starts with the type Any (ABC123). Set it to text or a number.
Common mistakes
Greater than or greater than or equal to
Exactly at the limit, the operator decides: 1000 is not greater than 1000. Read the task carefully: "from 1,000 upwards" means greater than or equal to.
Number compared as text
If Amount is still text, Power Query compares texts, and "999" is then greater than "1000". Change the data type first.
null in the column
An empty cell meets no greater-than condition and ends up under Else. If it should stand out, add a clause "equals null" at the top.
Frequently asked questions
Can I compare two columns?
Yes. Next to the value you can pick a column instead of a fixed value, for example "is greater than Target".
Where do I change the rule later?
Under Applied Steps, click the gear next to the step; the dialog opens again.