01 / 21

Creating
Derived Variables

Transform raw data into powerful new features that unlock deeper insights and drive smarter business decisions.

Business Analytics

What Are Derived Variables?

A derived variable is a new column created by applying a transformation, calculation, or logical rule to one or more existing columns in your dataset. Instead of collecting new data, you engineer features from what you already have.

Why Derived Variables Matter

★ Richer Insights
Raw data alone rarely tells the full story. Derived variables surface hidden relationships.
★ Better Models
Feature engineering is often the single biggest driver of predictive model accuracy.
★ Business Value
Metrics like profit margin, customer lifetime value, and growth rate are all derived variables.

The Transformation Pipeline

Raw Data Revenue, Units, Date, Cost Transformation Math, Logic, Aggregation, Text Parsing Derived Variable Profit Margin, Growth Rate

Core Formula Types

1
Arithmetic: Combine columns using \( +, -, \times, \div \). Example: \(\text{Profit} = \text{Revenue} - \text{Cost}\)
2
Ratio / Percentage: Express relationships as proportions. Example: \(\text{Margin} = \frac{\text{Profit}}{\text{Revenue}} \times 100\)
3
Conditional / Logical: Use \(\text{IF/THEN}\) rules to categorize. Example: IF \(\text{Score} \geq 90\), THEN "A"
4
Aggregation: Summarize groups with \(\text{SUM}\), \(\text{AVG}\), \(\text{COUNT}\). Example: \(\text{Avg Order} = \frac{\sum \text{Orders}}{n}\)
5
Date / Text Extraction: Parse components from dates or strings. Example: Extract "Month" from a date column

Derived vs. Raw Variables

Raw Variable Derived Variable
Source Collected directly Calculated from raw data
Example Revenue, Date, Units Sold Profit Margin, Day of Week
Storage Original dataset Added as new column
Updates Changes when new data arrives Must be recalculated
Purpose Record observations Enhance analysis power

What Are Feature Columns?

In machine learning and predictive analytics, a feature column (or simply feature) is any input variable used by a model to make predictions. Derived variables become feature columns when they are fed into an analytical model.

Raw Feature
Using an existing column directly as model input: e.g., "Age" or "Income".
Engineered Feature
A derived variable created specifically to improve model performance: e.g., "Income per Household Member".

How to Create Derived Variables

1
Identify the business question. What insight or metric do you need that isn't already in your data?
2
Select input columns. Determine which raw variables contain the information you need.
3
Choose the operation. Arithmetic? Logical? Aggregation? Match the formula type to the question.
4
Write and apply the formula. Calculate the new variable for every row (or group).
5
Validate the result. Check for errors, edge cases (division by zero), and reasonableness.

Example 1: Profit Margin

Product Revenue Cost Margin % Widget A $500 $300 40% Widget B $800 $600 25% Widget C $1200 $400 66.7%
\(\text{Margin\%} = \frac{\text{Revenue} - \text{Cost}}{\text{Revenue}} \times 100\)

Example 2: Growth Rate

A retail chain wants to know how each store's sales changed from last year to this year. We derive a year-over-year growth rate.

Store Last Year This Year Growth % Downtown $200K $240K +20% Mall $150K $135K -10% Suburb $300K $330K +10%
\(\text{Growth\%} = \frac{\text{This Year} - \text{Last Year}}{\text{Last Year}} \times 100\)

Example 3: Conditional Categories

A marketing team wants to label customers as High, Medium, or Low value based on their total spending. This creates a categorical derived variable.

\( \text{IF Spending} > \$1000 \)
"High Value"
\( \text{ELSE IF Spending} > \$500 \)
"Medium Value" ELSE → "Low Value"

Example 4: Date Extraction

A single date column like "2024-03-15" can yield multiple derived features that reveal seasonality and timing patterns.

2024-03-15 Year 2024 Month March Day of Week Friday Quarter Q1 Is Weekend? FALSE

Text-Based Derivations

Text columns hold valuable information that can be extracted using string operations: splitting, searching, counting, and transforming.

Extract Domain
From "user@gmail.com" derive Email Provider: "gmail.com"
Word Count
From a product review, derive Review Length as number of words
Contains Keyword
From support tickets, derive Is Urgent: TRUE if text contains "ASAP" or "urgent"

Combining Multiple Derivations

Real-world analytics often chains several derived variables together. Each derived column can serve as input for the next.

Step 1
\( \text{Profit} = \)
\( \text{Rev} - \text{Cost} \)
Step 2
\( \text{Margin\%} = \)
\( \frac{\text{Profit}}{\text{Rev}} \)
Step 3
\( \text{Tier} = \text{IF} \)
\( \text{Margin\%} > 40\% \)
"Premium Product"

Common Mistakes to Avoid

✕ Division by Zero
Calculating ratios without checking if the denominator can be zero. Always add a safeguard.
✕ Wrong Order of Operations
Forgetting parentheses: \(\text{Rev} - \text{Cost} / \text{Rev}\) is not the same as \((\text{Rev} - \text{Cost}) / \text{Rev}\).
✕ Ignoring Missing Data
If a raw column has blank or null values, the derived column inherits them. Clean data first.
✕ Unit Mismatch
Mixing dollars and euros, or years and months, without converting. Units must match before operations.

Summary: Derivation Techniques

Technique Operation Example Output
Arithmetic \( A + B \), \( A - B \), \( A \times B \) Profit, Total Cost
Ratio \( \frac{A}{B} \times 100 \) Margin %, Growth %
Conditional \(\text{IF/ELSE}\) logic Tier Label, Risk Flag
Aggregation \(\text{SUM}\), \(\text{AVG}\), \(\text{COUNT}\) per group Avg Order Value
Date Parsing Extract year, month, day Quarter, Is Weekend
Text Parsing Split, search, count Domain, Word Count

Question 1 of 5

A company has columns for Revenue and Cost. Which formula correctly computes the profit margin percentage?

Question 2 of 5

Extracting the day of the week from a date column is an example of which derivation technique?

Question 3 of 5

Store A had $400K in sales last year and $500K this year. What is the year-over-year growth rate?

Question 4 of 5

Which of the following is a derived variable rather than a raw variable?

Question 5 of 5

A dataset has a "Revenue" column where some rows contain \( \$0 \). You want to calculate \( \text{Cost} / \text{Revenue} \). What is the primary risk?