Power BI Lesson 27 – Conditional Columns | Dataplexa
Power Query · Lesson 27

Conditional Columns

Conditional Column is the point-and-click version of a Custom Column if statement. Instead of writing M code, you fill in a dialog with dropdown menus — pick a column, pick an operator, enter a value, enter an output. For straightforward rules with a small number of branches, it is faster and less error-prone than writing M by hand. But the dialog has real limits, and knowing exactly where those limits are — and how to break through them by editing the generated M — is what this lesson is about.

The Conditional Column Dialog

Conditional Column lives on the Add Column tab. Each row in the dialog is one if/else if branch. The final row is the "else" — what to output when no condition matches. You can add as many branches as needed using the Add Clause button.

Add Column → Conditional Column
New column name
RevenueTier
Column Name
Operator
Value
Output
If
Revenue
is greater than or equal to
1500
Platinum
×
Else if
Revenue
is greater than or equal to
1000
Gold
×
Else if
Revenue
is greater than or equal to
500
Silver
×
Else
Bronze
+ Add Clause
OK
Cancel

The M Code the Dialog Generates

Every Conditional Column step is stored as M code in the Applied Steps. Clicking the gear icon on the step reopens the dialog — but you can also click into the formula bar to see and edit the raw M. Knowing what the dialog generates lets you spot patterns and extend them when the UI is not enough.

// M generated by the Conditional Column dialog above
#"Added Conditional Column" = Table.AddColumn(
    #"Changed Type",
    "RevenueTier",
    each if [Revenue] >= 1500 then "Platinum"
         else if [Revenue] >= 1000 then "Gold"
         else if [Revenue] >= 500  then "Silver"
         else "Bronze"
)

// Note: the dialog always generates "else" at the end —
// this becomes the fallback value for any row that
// does not match any of the defined conditions.
RevenueTier column — applied to the Orders dataset
OrderID Revenue RevenueTier
10011,200Gold
1002850Silver
1003430Bronze
100495Bronze
10051,540Platinum

All Available Operators in the Dialog

Operator (as shown in dialog) Works on M equivalent
equals Text, Number, Date [Col] = value
does not equal Text, Number, Date [Col] <> value
is greater than Number, Date [Col] > value
is greater than or equal to Number, Date [Col] >= value
is less than Number, Date [Col] < value
is less than or equal to Number, Date [Col] <= value
begins with Text only Text.StartsWith([Col], value)
ends with Text only Text.EndsWith([Col], value)
contains Text only Text.Contains([Col], value)
does not contain Text only not Text.Contains([Col], value)
is null Any type [Col] = null
is not null Any type [Col] <> null

What the Dialog Cannot Do — And How to Fix It

The Conditional Column dialog is useful but deliberately limited. Six common requirements fall outside what the dialog supports — each has a workaround using the formula bar or Custom Column.

❌ Dialog limitation
Cannot compare two columns against each other. The "Value" field only accepts a typed literal — you cannot select another column from a dropdown. You cannot write "if [OrderDate] > [DueDate]" in the dialog.
✓ Fix — edit the formula bar
Click the generated step in Applied Steps → click into the formula bar → change the literal value to [DueDate]. The dialog cannot express this but M handles it perfectly.
❌ Dialog limitation
Cannot use AND / OR within a single clause. Each row of the dialog is a single condition on a single column. You cannot say "if Status = Late AND CustomerTier = Premium" in one clause.
✓ Fix — Custom Column
Use Add Column → Custom Column and write the full M expression with and / or keywords directly.
❌ Dialog limitation
Cannot output a calculated value. The "Output" field only accepts a typed literal or a column reference — it cannot contain a formula. You cannot output [Revenue] * 0.1.
✓ Fix — edit the M or use Custom Column
In the formula bar, replace the quoted output literal with an M expression: change "Discount" to [Revenue] * 0.1.
❌ Dialog limitation
Cannot handle null safely in the output. If the output value references a column that might be null, the dialog provides no try/otherwise wrapper — errors appear silently.
✓ Fix — wrap in the formula bar
Edit the step in the formula bar and wrap the output expression with try … otherwise null for any branch that does arithmetic.

Extending the Generated M in the Formula Bar

The most productive workflow is to build the basic structure in the Conditional Column dialog, click OK, then refine the generated M in the formula bar. You get the speed of the UI for the skeleton and the full power of M for the details.

// BEFORE — what the dialog generates (column comparison as literal)
each if [Revenue] >= 1000 then "High" else "Low"

// AFTER — edited in formula bar to compare two columns
each if [Revenue] >= [Target] then "On Target" else "Below Target"

// BEFORE — dialog generates a text output
each if [Status] = "Late" then "Penalty" else "None"

// AFTER — edited to calculate a numeric output
each if [Status] = "Late"
     then try [Revenue] * 0.05 otherwise null   // 5% late penalty
     else 0

// BEFORE — dialog can only check one column per clause
each if [Revenue] >= 1000 then "Flag" else ""

// AFTER — compound condition added in formula bar
each if [Revenue] >= 1000 and [CustomerTier] = "Premium"
     then "Priority Flag"
     else if [Revenue] >= 1000
     then "High Value"
     else ""
Compound condition — extended M applied to Orders dataset
OrderID Revenue CustomerTier Flag
10011,200PremiumPriority Flag
1002850Standard(blank)
1003430Premium(blank)
100495Standard(blank)
10051,540PremiumPriority Flag
Only Premium customers with Revenue ≥ 1000 get "Priority Flag" — Order 1002 is high value but Standard tier so it gets blank, not "High Value", because no Standard+high-value orders exist in this dataset

Conditional Column vs Custom Column — Decision Guide

Conditional Column (dialog) Custom Column (M code)
Best for Simple text or number categorisation — one column, fixed literal values, no arithmetic in the output Any logic involving column-to-column comparisons, AND/OR, calculated outputs, null safety, or more than 5 branches
Requires M knowledge? No — fully point-and-click Yes — must write M syntax
Column vs column compare Not directly — literal values only (workaround: edit the M after) Yes — full M expression
AND / OR conditions No — one column per clause Yes
Calculated output No — literal or column reference only Yes — any M expression
Extendable after creation? Yes — reopen dialog or edit M in formula bar Yes — edit M directly

Teacher's Note: The most useful workflow at an intermediate level is: use the Conditional Column dialog to scaffold the branch structure quickly, click OK, then immediately click into the formula bar and extend the M where the dialog fell short. You get the visual structure of the dialog without being trapped by its limitations. Treat the dialog as a code generator, not as the final editor.

Practice

Practice 1 of 3

In the Conditional Column dialog, each row of the grid represents one ___ / else if branch, and the final row is the "else" fallback that applies when no condition above it matches.

Practice 2 of 3

The Conditional Column dialog cannot compare two columns against each other — the Value field only accepts a typed literal. The fastest fix is to build the structure in the dialog, click OK, then edit the generated M in the ___ bar to replace the literal with the second column reference.

Practice 3 of 3

You need a column that outputs [Revenue] * 0.05 for late orders and 0 for all others. Because the output is a calculated expression rather than a fixed value, the Conditional Column dialog alone cannot do this — you must use a Custom Column or ___ the generated M in the formula bar.

Lesson Quiz

Quiz 1 of 3

You build a Conditional Column with four clauses — Platinum ≥ 1500, Gold ≥ 1000, Silver ≥ 500, Bronze for else — and reopen the dialog to add a new "Diamond ≥ 2000" tier. You add it as the fifth clause at the bottom, above the Bronze else row. What is wrong with this and how do you fix it?

Quiz 2 of 3

Which of the following scenarios is best handled by Conditional Column rather than Custom Column?

Quiz 3 of 3

You use the "contains" operator in the Conditional Column dialog to flag any Description column that contains the word "urgent". A row has Description = "URGENT delivery required". The flag does not appear for that row. What is the most likely cause?

Next up — Lesson 28 covers Date and Time Transformations in Power Query, including building a full Calendar table from scratch, extracting every date component needed for time intelligence, and the patterns that make DATEYTD and SAMEPERIODLASTYEAR work correctly in DAX.