Creating Conditional Columns: If-Then Logic Without Code
You have an orders table with a revenue column. Your manager wants each order labeled as "High", "Medium", or "Low" value. In a spreadsheet you'd write a nested IF formula. In SQL you'd write a CASE WHEN. In most BI tools you'd open an expression editor and hope you get the syntax right.
The underlying logic is dead simple: if revenue is above 10,000, it's high. Above 1,000, it's medium. Everything else is low. The hard part has always been the tooling, not the thinking.
ExploreMyData lets you build this kind of conditional logic visually, using a condition builder that generates the SQL for you.
The problem: you need buckets
This comes up constantly. A few real examples:
- Categorize orders by revenue: "High" (> $10,000), "Medium" (> $1,000), "Low" (everything else)
- Flag customers as "Active" or "Churned" based on their last purchase date
- Label shipping as "Domestic" or "International" based on country code
- Mark scores as "Pass" or "Fail" based on a threshold
All of these follow the same pattern: look at a value, check it against one or more conditions, and assign a label. It's if-then logic.
Add a conditional column with the condition builder
Open the toolbar and select Add Column from the Columns group. Give your new column a name (e.g., "tier"). Then switch the mode to Condition Builder.
The condition builder lets you define multiple rows of logic:
- First condition: when
revenue > 10000, set the value to "High". - Second condition: when
revenue > 1000, set the value to "Medium". - Default (all remaining rows): set the value to "Low".
| Condition | Output value |
|---|---|
| revenue > 10000 | High |
| revenue > 1000 | Medium |
| Default (all other rows) | Low |
Conditions are evaluated top to bottom - the first match wins. The new column is named tier.
Click Apply. A new "tier" column appears with the correct label for every row.
Order matters here. Conditions are evaluated top to bottom, and the first match wins. That's why "revenue > 10000" comes before "revenue > 1000" - an order with $15,000 in revenue matches both conditions, but it should be labeled "High", not "Medium".
What the SQL looks like
Open the pipeline to see the generated SQL. The condition builder creates a standard
CASE WHEN expression:
CASE WHEN revenue > 10000 THEN 'High' WHEN revenue > 1000 THEN 'Medium' ELSE 'Low' END AS tier
This is the same SQL you'd write by hand. The difference is you didn't have to worry about syntax, quoting, or forgetting the END keyword.
Updating existing values with conditions
Sometimes you don't need a new column - you need to change values in an existing one. Maybe you have a "status" column with numeric codes (1, 2, 3) and you want to replace them with readable labels.
Use Update Values from the Transform group. Select the column, then enter a CASE WHEN expression directly:
CASE WHEN status = 1 THEN 'Pending' WHEN status = 2 THEN 'Shipped' WHEN status = 3 THEN 'Delivered' ELSE status END
The ELSE status at the
end means any value that doesn't match your conditions keeps its original value. You won't
accidentally wipe out data you didn't account for.
| order_id | revenue | tier | status (before) | status (after) |
|---|---|---|---|---|
| 2001 | 15200 | High | 2 | Shipped |
| 2002 | 3400 | Medium | 1 | Pending |
| 2003 | 480 | Low | 3 | Delivered |
| 2004 | 22800 | High | 2 | Shipped |
Two CASE WHEN steps applied: one adds the tier column, another replaces numeric status codes with readable labels.
Combining multiple columns in conditions
Conditions don't have to reference a single column. You can combine them:
revenue > 10000 AND region = 'US'- high-value domestic ordersquantity > 0 AND shipped_date IS NULL- orders that should have shipped but haven'tscore >= 90 OR extra_credit = true- students who passed by either path
Each condition row in the builder supports full SQL boolean logic, so you can express anything you could write in a WHERE clause.
Common patterns
A few conditional column recipes that come up repeatedly:
Date-based flags:
CASE WHEN last_order_date >= CURRENT_DATE - INTERVAL '90 days' THEN 'Active' WHEN last_order_date >= CURRENT_DATE - INTERVAL '365 days' THEN 'At Risk' ELSE 'Churned' END
Numeric ranges for histograms:
CASE WHEN age < 18 THEN 'Under 18' WHEN age < 35 THEN '18-34' WHEN age < 55 THEN '35-54' ELSE '55+' END
NULL handling:
CASE WHEN email IS NOT NULL THEN 'Has Email' ELSE 'Missing Email' END
Why this matters
Conditional columns turn raw data into analysis-ready categories. Once you have a "tier" column, you can group by it, filter by it, count it, and pivot on it. You go from "I have 50,000 rows of revenue numbers" to "I have 12,000 high-value orders, 28,000 medium, and 10,000 low" in a few clicks.
Every condition you build becomes a visible step in your pipeline. You can edit the thresholds later, reorder conditions, or delete the step entirely. The SQL is always visible, so you know exactly what's happening to your data.