Edilitics | Data to Decisions

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 on revenue thresholds.
  • Discount flag. Mark rows where discount_pct is null as "No Discount" and non-null rows as "Discounted".
  • Regional grouping. Map region values 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 = true and revenue > 10000 as "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

Download

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:

  1. IF - one or more conditions. Each condition tests a column against an operator and a value.
  2. 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.
  3. 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:

OperatorSymbolNeeds a value?
Equal to=Yes
Not equal toYes
Greater than>Yes
Greater than or equal toYes
Less than<Yes
Less than or equal toYes
Is null-No
Is not null-No

String (categorical) columns:

OperatorNeeds a value?
Equal toYes
Not equal toYes
ContainsYes
Not containsYes
Starts withYes
Ends withYes
Is nullNo
Is not nullNo

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:

  1. IF revenue ≥ 20000"High"
  2. IF revenue ≥ 5000"Mid"
  3. IF revenue < 5000"Low"

Else: null

Input:

order_idregionrevenuediscount_pct
ORD-2024-0001North America12450.00null
ORD-2024-0047Europe8320.500.10
ORD-2024-0099Asia Pacific83841.000.20
ORD-2024-0312Latin America3750.75null

Output:

order_idregionrevenuediscount_pctrevenue_tier
ORD-2024-0001North America12450.00nullMid
ORD-2024-0047Europe8320.500.10Mid
ORD-2024-0099Asia Pacific83841.000.20High
ORD-2024-0312Latin America3750.75nullLow

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

Need help? Email support@edilitics.com with your workspace, job ID, and context. We reply within one business day.

Last updated on

On this page