Conditional Column
Add a new column whose value is set by IF/THEN rules evaluated top-to-bottom. First matching rule wins. Else value for unmatched rows. No code needed.
Conditional Column adds a new column to your dataset whose value is determined by a set of IF/THEN rules you define. Rules are evaluated top-to-bottom - the first rule that matches a row sets that row's value. Rows that match no rule receive the Else value (or null if left empty). The source columns are unchanged.
Each rule can have one or more conditions combined with AND or OR logic. You can stack as many rules as needed in one operation.
When to Use Conditional Column
- Customer segmentation. Label rows as
"Enterprise","Growth", or"Starter"based onrevenuethresholds. - Discount flag. Mark rows where
discount_pctis null as"No Discount"and non-null rows as"Discounted". - Regional grouping. Map
regionvalues to broader buckets -"EMEA","Americas","APAC". - Risk scoring. Assign
"High","Medium", or"Low"risk based on multiple conditions across revenue, tier, and nulls. - Return classification. Flag rows where
return_flag = trueandrevenue > 10000as"High-value return".
Sample Dataset
The examples in this doc use the Edilitics sample orders dataset. Download it to follow along in your own workspace.
edilitics_sample_orders.csv
Sample orders dataset for hands-on practice · 500 rows
Relevant columns for Conditional Column examples:
Prop
Type
How Rules Work
Rules are evaluated top-to-bottom. The first rule that matches a row sets that row's output value. Subsequent rules are not evaluated for that row. Order your rules from most specific to least specific.
Each rule has three parts:
- IF - one or more conditions. Each condition tests a column against an operator and a value.
- AND / OR - when a rule has more than one condition, toggle AND (all conditions must match) or OR (any condition must match). AND/OR applies within one rule only - different rules always operate independently.
- THEN - the value to assign when the rule matches.
After all rules, an optional Else value handles any row that matched no rule. Leave it empty and unmatched rows receive null.
Operators by Column Type
Operators available depend on the column type selected in the condition.
Numerical and Datetime columns:
| Operator | Symbol | Needs a value? |
|---|---|---|
| Equal to | = | Yes |
| Not equal to | ≠ | Yes |
| Greater than | > | Yes |
| Greater than or equal to | ≥ | Yes |
| Less than | < | Yes |
| Less than or equal to | ≤ | Yes |
| Is null | - | No |
| Is not null | - | No |
String (categorical) columns:
| Operator | Needs a value? |
|---|---|
| Equal to | Yes |
| Not equal to | Yes |
| Contains | Yes |
| Not contains | Yes |
| Starts with | Yes |
| Ends with | Yes |
| Is null | No |
| Is not null | No |
Is null and Is not null hide the value input field - no comparison value is needed.
How to Apply Conditional Column
Open the Conditional Column operation
In your Transform pipeline, click Add Operation and select Conditional Column from the operation list.
Name the new column
Type a name in the New column name field. This becomes the new column added to your dataset.
The name must:
- Contain only letters, numbers, and underscores
- Not start with
__or a number - Not already exist in the dataset
Configure the first rule
Each rule starts with one condition. For the condition:
- Column - choose any column from your dataset (numerical, string, or datetime).
- Operator - choose from the operators available for that column's type.
- Value - type the comparison value. Hidden for Is null / Is not null.
In the THEN field, type the value to assign when this rule matches.
Add conditions to a rule (optional)
Click the + icon next to a condition to add another condition to the same rule. An AND / OR toggle appears. AND requires all conditions to match. OR requires any condition to match.
Example: revenue > 10000 AND product_tier = "Enterprise" → "High Value Enterprise".
Add more rules (optional)
Click Add another rule to add a second IF/THEN block. Rules are evaluated in the order they appear. Drag to reorder if needed - the topmost matching rule wins.
Set the Else value (optional)
In the Else value field, type the value for rows that match no rule. Leave it empty and those rows receive null in the new column.
Click Save & Preview
Click Save & Preview. Edilitics evaluates all rules row-by-row and adds the new column. The success toast confirms: "Conditional column column_name added."
Verify in the preview
Check the new column. Rows showing null matched no rule. If unexpected rows are null, check whether your rules cover all expected cases or whether the Else value was left empty.
Before and After
Three rules applied to create a revenue_tier column:
- IF
revenue ≥ 20000→"High" - IF
revenue ≥ 5000→"Mid" - IF
revenue < 5000→"Low"
Else: null
Input:
| order_id | region | revenue | discount_pct |
|---|---|---|---|
| ORD-2024-0001 | North America | 12450.00 | null |
| ORD-2024-0047 | Europe | 8320.50 | 0.10 |
| ORD-2024-0099 | Asia Pacific | 83841.00 | 0.20 |
| ORD-2024-0312 | Latin America | 3750.75 | null |
Output:
| order_id | region | revenue | discount_pct | revenue_tier |
|---|---|---|---|---|
| ORD-2024-0001 | North America | 12450.00 | null | Mid |
| ORD-2024-0047 | Europe | 8320.50 | 0.10 | Mid |
| ORD-2024-0099 | Asia Pacific | 83841.00 | 0.20 | High |
| ORD-2024-0312 | Latin America | 3750.75 | null | Low |
Source columns unchanged. One new column added.
Code Equivalent
-- Compatible with PostgreSQL, BigQuery, Snowflake, Redshift, DuckDB
SELECT
*,
CASE
WHEN revenue >= 20000 THEN 'High'
WHEN revenue >= 5000 THEN 'Mid'
WHEN revenue < 5000 THEN 'Low'
ELSE NULL
END AS revenue_tier
FROM orders;import polars as pl
df = df.with_columns(
pl.when(pl.col("revenue") >= 20000)
.then(pl.lit("High"))
.when(pl.col("revenue") >= 5000)
.then(pl.lit("Mid"))
.when(pl.col("revenue") < 5000)
.then(pl.lit("Low"))
.otherwise(pl.lit(None))
.alias("revenue_tier")
)After Save & Preview, the pipeline shows a DQ delta badge on this step - green if the table score improved, red if it dropped. See Data Quality Scoring for how scores are calculated.
After Save & Preview, the pipeline shows a DQ delta badge on this step - green if the table score improved, red if it dropped. See Data Quality Scoring for how scores are calculated.
Operation Reference
Prop
Type
Frequently Asked Questions
Next Steps
Filter
Filter rows using the new conditional column as a criterion.
Group By
Group and aggregate by the new label or segment column.
Cast Data Types
Cast the new string column to numeric or boolean if the values support it.
Manage Nulls
Handle null values in source columns before building conditions.
Need help? Email support@edilitics.com with your workspace, job ID, and context. We reply within one business day.
Last updated on
String Extract
Extract substrings from a text column using regex capture groups. Each capture group becomes a new string column. Preset patterns for email, URL, phone, date, and number. No code needed.
Column Aggregations
Create new numeric columns using row-wise math: add, subtract, multiply, divide, modulus, exponent, logarithm, or percentages across columns and constants.