Business Analytics • Data Wrangling and Querying

Creating Derived Variables — Create derived variables and feature columns

Transform raw data into powerful analytic features that drive better business decisions and predictive models.

A rising analytics chart supported by a business case and data store.
Inside this lesson 10 sections 5 questions 9 figures

SECTION 1

Historical Context & Motivation

The practice of creating derived variables — new data columns computed from existing ones — has roots that stretch back to the earliest days of systematic business record-keeping. Long before the era of digital spreadsheets, accountants and analysts routinely computed ratios, percentages, and aggregates from raw ledger entries to gain deeper operational insight. What has changed dramatically over the past century is the scale, speed, and sophistication with which organizations can perform these transformations, as well as the range of downstream applications — from descriptive dashboards to machine-learning models — that consume the resulting features.

Understanding this historical trajectory helps explain why feature engineering — the modern discipline of creating and selecting derived variables — is widely regarded as the single most impactful step in any analytics workflow. A well-chosen derived variable can reveal patterns invisible in the raw data, whereas a poorly conceived one can introduce noise and misleading conclusions. The milestones below trace how the concept evolved from manual bookkeeping ratios to automated feature pipelines.

1494 • Pacioli's Double-Entry Bookkeeping

Luca Pacioli codified double-entry bookkeeping, establishing the earliest systematic framework for computing derived financial figures such as profit margins and account balances from raw transaction records.

1920s • DuPont Analysis & Financial Ratios

The DuPont Corporation popularized decomposing Return on Equity into derived components — profit margin, asset turnover, and leverage — pioneering ratio-based derived variables in corporate finance.

1979 • VisiCalc & the Spreadsheet Revolution

The first electronic spreadsheet enabled business users to create computed columns interactively, making derived variable creation accessible to non-programmers and accelerating ad-hoc analysis.

2001 • Pandas & Programmatic Data Wrangling

The Python pandas library (released publicly in 2008, rooted in earlier work) gave analysts a code-based toolkit for rapid column transformations, enabling reproducible feature engineering at scale.

2010s–Present • Automated Feature Engineering

Tools like Featuretools and cloud-based ML platforms introduced automated feature engineering, generating hundreds of derived variables algorithmically and selecting those with the highest predictive power.

The central question this lesson addresses is deceptively simple: given a raw dataset, how do you decide which new columns to create, and how do you implement them reliably? As we will see, the answer draws on domain knowledge, mathematical transformations, and thoughtful validation — skills every business analyst needs.

SECTION 2

Core Principles & Definitions

A derived variable (also called a computed column or feature column) is any new field in a dataset whose values are calculated from one or more existing fields rather than collected directly from an original data source. The term feature originates in machine learning and refers to any input variable fed into a model; when that feature is derived rather than raw, we call the creation process feature engineering. In practice, business analysts create derived variables for reports, dashboards, and predictive models alike, so the skill transcends any single tool or framework.

1

Arithmetic Derivation

Combine existing columns through addition, subtraction, multiplication, or division to produce ratios, margins, or totals. Example: profit_margin = net_income / revenue.
2

Temporal Extraction

Parse date or timestamp fields to extract components such as day of the week, month, quarter, or time since a reference event. These features capture seasonality and recency effects.
3

Categorical Encoding

Convert text-based categories into numerical representations — including one-hot encoding, label encoding, or binning continuous values into ordinal groups — so models can process them.
4

Aggregation & Window Functions

Compute rolling averages, cumulative sums, or group-level statistics and attach them back to each row. Example: a customer's average purchase amount over the last 90 days.
5

Interaction & Polynomial Terms

Multiply two features together (interaction) or raise a feature to a power (polynomial) to capture non-linear relationships. Example: ad_spend × conversion_rate.
✦

KEY TAKEAWAY

Think of raw data as crude ingredients in a kitchen. A column of timestamps is like a bag of unpeeled potatoes — useful, but not ready to serve. Derived variables are the prepped ingredients: diced, seasoned, and combined in ways that make the final dish (your analysis or model) far more flavorful and digestible. The better your prep, the better your results.

SECTION 3

Visual Explanation — From Raw Data to Derived Features

Raw Data → Transformation → Derived VariablesRaw Datasetorder_date2024-01-152024-03-222024-07-04revenue$12,500$8,200$15,800cost$7,500$5,100$9,400regionEastWestTransformations① Extract quarterquarter = Q(order_date)② Compute marginmargin = (rev − cost)/rev③ One-hot encodeis_east = 1 if East④ InteractionDerived ColumnsquarterQ1Q1Q3profit_margin0.400.380.41is_east100margin × is_east0.400.00
The diagram shows a three-stage pipeline. On the left, the raw dataset contains order dates, revenue, cost, and region. In the center, four transformations — temporal extraction, arithmetic ratio, one-hot encoding, and interaction — produce the derived columns on the right.

Notice how each transformation addresses a distinct analytical need. The quarter extraction converts a granular timestamp into a categorical seasonality feature, enabling group-by analyses or seasonal dummies in regression. The profit margin normalizes the relationship between revenue and cost into a unit-free ratio, making comparisons across differently sized product lines meaningful. The one-hot indicator translates a categorical label into a binary numeric form consumable by regression and classification algorithms. Finally, the interaction term captures the joint effect of region and profitability — something neither variable reveals on its own.

SECTION 4

Mathematical Framework for Derived Variables

While many derived variables arise from business intuition, formalizing the most common transformations helps you communicate precisely with data engineers and ensures reproducibility. Below are the key mathematical patterns you will encounter across virtually all business analytics projects.

RATIO / MARGIN

Margin=(Revenue−Cost)/RevenueMargin = (Revenue − Cost) / Revenue

Where Revenue is the top-line sales figure and Cost represents the direct costs. The result is a unit-free proportion typically expressed as a percentage.

GROWTH RATE

GrowthRate=(Xt−Xt−1)/Xt−1Growth Rate = (Xₜ − Xₜ₋₁) / Xₜ₋₁

Where Xₜ is the metric value in the current period and Xₜ₋₁ is the same metric in the prior period. This is also called period-over-period change.

LOGARITHMIC TRANSFORM

X′=ln(X+1)X' = ln(X + 1)

Adding 1 avoids taking the log of zero. This transformation is widely used in business analytics to reduce right skew in variables like transaction amounts or web traffic counts, stabilizing variance for regression models.

INTERACTION TERM

Xinteraction=X1×X2X_interaction = X₁ × X₂

An interaction term captures the combined effect of two features. For instance, multiplying a binary is_premium_customer flag by discount_pct creates a feature measuring the discount impact specifically for premium customers.

Each formula above generates a new column in your dataset. In SQL, these appear as expressions in a SELECT clause; in Python's pandas library, they are vectorized operations on DataFrame columns. The underlying mathematical logic is identical regardless of tool — mastering the formula ensures you can implement it anywhere.

SECTION 5

Detailed Breakdown — Categories of Derived Variables

In business analytics practice, derived variables can be organized into a taxonomy that guides the analyst in deciding which transformation to reach for given the data type and the analytical objective. The diagram below maps the most common categories and provides representative examples drawn from marketing, finance, and operations data.

Taxonomy of Derived Variable TypesDerived VariableArithmeticTemporalEncodingAggregate / Windowprofit = rev − costmargin = profit/revROI = gain/investln(revenue + 1)day_of_weekfiscal_quarterdays_since_signupis_weekend (flag)one-hot regionlabel encode tierbin age → groupinteraction X₁×X₂rolling_avg_30dcumulative_sumgroup_meanrank_within_grpWhen to Use Each CategoryArithmetic→ Normalizing scale, computing KPIs, enabling cross-comparisonTemporal→ Capturing seasonality, recency, and lifecycle effectsEncoding→ Preparing categorical data for algorithms and non-linear effectsAggregate→ Adding group-level context, smoothing noise, creating baselines
This taxonomy organizes derived variables into four families. Arithmetic transformations produce ratios and KPIs. Temporal features capture time-based patterns. Encoding converts categories to numeric form. Aggregate / Window functions inject group-level statistics into row-level data.
CategoryInput TypeOutput TypeBusiness Example
ArithmeticNumeric columnsNumeric (ratio, difference, log)Customer Lifetime Value = Total Revenue − Total Cost per customer
TemporalDate / timestampInteger or categoricalDays since last purchase (recency in RFM analysis)
EncodingCategorical / textBinary or ordinal numericOne-hot encode product category for logistic regression
Aggregate / WindowNumeric + grouping keyNumeric (mean, sum, rank)Rolling 7-day average order value per store
InteractionTwo or more columnsNumeric productAd spend × click-through rate to capture joint campaign intensity

Summary of derived variable categories, their input/output types, and representative business examples.

SECTION 6

Worked Example — Building a Customer-Level Feature Set

Suppose you work as an analyst at an e-commerce retailer and need to create a feature-rich dataset for a churn prediction model. Your raw orders table contains customer_id, order_date, order_total, discount_pct, and product_category. The reference date is 2024-09-01. We will derive five new features using SQL.

Deriving Customer Features for Churn Prediction

  1. 1

    Step 1 — Compute Recency (Temporal)

    Calculate the number of days between the customer's most recent order and the reference date. In SQL: DATEDIFF('2024-09-01', MAX(order_date)) AS days_since_last_order. A higher value signals that the customer has been inactive for longer, a strong churn indicator.
    Customer A: last order 2024-08-10 → days_since_last_order = 22
  2. 2

    Step 2 — Compute Frequency (Aggregation)

    Count the total number of orders per customer: COUNT(*) AS total_orders. This captures the frequency dimension of the classic RFM (Recency, Frequency, Monetary) framework.
    Customer A placed 14 orders → total_orders = 14
  3. 3

    Step 3 — Compute Average Order Value (Arithmetic)

    Divide total revenue by order count: SUM(order_total) / COUNT(*) AS avg_order_value. This derived variable normalizes monetary spend so that a big spender with few large orders is distinguished from a frequent low-value buyer.
    Customer A: total spend $1,820 ÷ 14 orders → avg_order_value = $130.00
  4. 4

    Step 4 — Compute Discount Sensitivity (Arithmetic Ratio)

    Calculate the proportion of orders where a discount was applied: SUM(CASE WHEN discount_pct > 0 THEN 1 ELSE 0 END) / COUNT(*) AS pct_discounted_orders. Customers who predominantly buy on discount may churn when promotions end.
    Customer A: 10 of 14 orders had discounts → pct_discounted_orders = 0.714
  5. 5

    Step 5 — Create Interaction Feature

    Multiply recency by discount sensitivity to capture the idea that an inactive, discount-dependent customer is the highest churn risk: days_since_last_order × pct_discounted_orders AS recency_discount_interaction. This interaction term will surface customers who are both dormant and price-sensitive.
    Customer A: 22 × 0.714 → recency_discount_interaction = 15.71
💡

Putting It All Together in SQL

All five features can be computed in a single SELECT statement grouped by customer_id. Wrapping the query in a Common Table Expression (CTE) or a view makes it reusable across multiple downstream analyses. In pandas, the equivalent uses .groupby('customer_id').agg(...) followed by column arithmetic for the interaction term.

SECTION 7

Strengths, Limitations & Common Pitfalls

Creating derived variables is one of the most impactful steps in any analytics workflow, but it also introduces risks. Poorly designed features can leak future information into a model, inflate dimensionality, or obscure interpretability. The table below contrasts the strengths of feature engineering with its common pitfalls, followed by practical mitigation strategies.

StrengthsLimitations / Pitfalls
Captures domain knowledge that raw data alone cannot express (e.g., profit margin vs. raw revenue and cost separately)Data leakage: using information from the future or the target variable to create features, invalidating model results
Improves model accuracy often more than algorithm selection; a simple model on great features beats a complex model on raw dataMulticollinearity: derived columns that are linear combinations of existing ones can destabilize regression coefficients
Enables comparability across different business units or time periods through normalization and ratiosCurse of dimensionality: creating too many features without pruning increases noise and training time
Makes reports and dashboards more intuitive by presenting KPIs rather than raw figuresDivision by zero / missing values: ratio-based derivations require guardrails when denominators can be zero or null
Reproducible when coded (SQL, Python) rather than manual; serves as documentation of business logicOver-engineering: excessively complex transformations reduce interpretability and may not generalize to new data

Strengths vs. limitations of creating derived variables in business analytics.

✦

KEY TAKEAWAY

Feature engineering is like seasoning a dish: the right amount transforms a bland meal into something exceptional, but too much overwhelms the palate. Always ask two questions before adding a derived variable: Does this feature genuinely encode new information? and Could this feature introduce leakage or redundancy? If you cannot answer both confidently, pause and validate before proceeding.

SECTION 8

Connection to Advanced Feature Engineering & Machine Learning Pipelines

The manual derived-variable techniques covered in this lesson form the foundation of more advanced, automated approaches used in production machine-learning systems. As organizations scale their analytics, they move from ad-hoc SQL expressions to feature stores — centralized repositories that compute, version, and serve derived features consistently across training and inference. Understanding manual feature creation is prerequisite knowledge for working effectively with these systems, because you still need to define the transformation logic and validate its business meaning.

AspectManual Feature Engineering (This Lesson)Automated / Advanced Pipelines
Feature DiscoveryAnalyst uses domain knowledge to hypothesize and create features one at a timeTools like Featuretools generate hundreds of candidate features via Deep Feature Synthesis
Feature SelectionManual review of correlations, VIF, and business logicAutomated selection via mutual information, LASSO regularization, or recursive elimination
ReproducibilityDepends on well-documented SQL/Python scripts or viewsFeature stores version transformations and guarantee train-serve consistency
ScalabilitySuitable for small to medium datasets; analyst effort is the bottleneckDistributed compute (Spark, Dask) handles billions of rows with scheduled pipelines
InterpretabilityHigh — analyst understands each feature's business meaningCan be lower for auto-generated features; requires SHAP/LIME for explanation

Manual vs. automated feature engineering approaches.

As you advance through your analytics coursework, you will encounter techniques like Principal Component Analysis (PCA) for dimensionality reduction, target encoding for high-cardinality categorical variables, and embedding layers in deep learning that learn feature representations automatically. All of these are sophisticated forms of derived-variable creation. The intuition you build now — asking what information a transformation adds and whether it could introduce bias — transfers directly to those advanced contexts.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

A colleague suggests adding a column total_cost = unit_cost × quantity to a sales dataset. Explain why total_cost qualifies as a derived variable rather than a raw variable. What category of derivation does it belong to, and why might this feature be more useful than keeping unit_cost and quantity separate?
Show answer
The column total_cost is derived because its values are computed from two existing columns rather than collected from an external data source. It belongs to the arithmetic derivation category (specifically, a product of two numeric fields). This single feature is often more useful than the two raw inputs for downstream analysis because it represents the actual monetary impact per line item, which is what managers care about when evaluating profitability. Keeping the two raw columns is still advisable for flexibility, but the derived total enables direct aggregation, ratio computation (e.g., cost-to-revenue), and more interpretable model coefficients.

Question 2: BASIC CALCULATION

A product had revenue of $48,000 and cost of goods sold (COGS) of $30,000 in Q1. Compute the gross profit margin as a derived variable. Express it as both a decimal and a percentage. Then compute the log-transformed revenue using ln(Revenue + 1).
Show answer
Gross profit margin = (Revenue − COGS) / Revenue = ($48,000 − $30,000) / $48,000 = $18,000 / $48,000 = 0.375, or 37.5%. For the log-transformed revenue: ln(48,000 + 1) = ln(48,001) ≈ 10.779. The margin formula normalizes profitability to a unit-free ratio, enabling comparison across products of different sizes. The log transformation compresses the scale of revenue, reducing the influence of extreme values in regression models and making the distribution more symmetric.

Question 3: INTERMEDIATE

You have an orders table with columns customer_id, order_date, and order_total. Write a SQL query that creates three derived columns for each customer: (a) order_count, (b) avg_order_value, and (c) days_since_last_order (assuming today is '2024-09-01'). Identify which derivation category each column belongs to.
Show answer
SQL: SELECT customer_id, COUNT(*) AS order_count, SUM(order_total)/COUNT(*) AS avg_order_value, DATEDIFF('2024-09-01', MAX(order_date)) AS days_since_last_order FROM orders GROUP BY customer_id; The column order_count is an aggregation-based derivation (counting rows per group). The avg_order_value combines aggregation (SUM, COUNT) with arithmetic (division), making it both an aggregate and an arithmetic derivation. The days_since_last_order is a temporal derivation that combines aggregation (MAX) with date arithmetic, capturing recency. Together these three features correspond to the R, F, and M components of RFM analysis.

Question 4: APPLIED

A marketing team provides you with a dataset containing campaign_name (categorical, 8 unique values), ad_spend, impressions, and conversions. They want to predict conversion rate using a linear regression model. Propose at least four derived features you would create, explain the transformation for each, and flag any potential pitfalls (e.g., leakage or multicollinearity).
Show answer
Proposed features: (1) cost_per_impression = ad_spend / impressions (arithmetic ratio capturing spending efficiency); (2) one-hot encoded campaign dummies — seven binary columns (drop one to avoid the dummy variable trap) from the categorical encoding family; (3) ln(ad_spend + 1) — log-transformed spend to reduce right skew; (4) spend_per_conversion = ad_spend / conversions. Pitfall: spend_per_conversion uses the target variable (conversions) in its construction, which constitutes data leakage — it must be excluded from features predicting conversion rate. Additionally, cost_per_impression and ln(ad_spend) are both functions of ad_spend and may be correlated; check the Variance Inflation Factor (VIF) and drop one if multicollinearity is detected.

Question 5: CRITICAL THINKING

An automated feature engineering tool generates 500 derived variables from a dataset of 2,000 customer records. Your colleague argues that more features always improve model accuracy. Critically evaluate this claim. In your response, discuss (a) the curse of dimensionality, (b) the risk of overfitting, (c) how feature selection techniques can mitigate these risks, and (d) why interpretability matters in a business context.
Show answer
(a) With 500 features and only 2,000 observations, the feature-to-sample ratio is 1:4, which pushes the model into sparse high-dimensional space where distance metrics lose meaning (the curse of dimensionality). Many algorithms degrade in performance when confronted with large numbers of irrelevant features because noise overwhelms signal. (b) A model with far more parameters than justified by the training data will memorize noise — overfitting — and perform poorly on new customers. (c) Feature selection techniques such as LASSO regression (L1 regularization, which drives coefficients to zero), mutual-information scoring, and recursive feature elimination can prune the 500 candidates down to a manageable, high-signal subset. Validation using k-fold cross-validation ensures selected features generalize. (d) In a business setting, stakeholders need to understand and act on model outputs. A churn model that says 'Feature_347 is the top predictor' is useless if no one knows what Feature_347 represents. Maintaining interpretable, domain-grounded features builds trust, facilitates regulatory compliance, and enables actionable recommendations — the ultimate goal of business analytics.

SUMMARY

Lesson Summary

Summary

Derived variables are new columns computed from existing data, and they are the cornerstone of effective feature engineering in business analytics. The five major categories are arithmetic derivations (ratios, margins, log transforms), temporal extractions (day of week, recency, seasonality flags), categorical encodings (one-hot, label, binning), aggregate and window functions (rolling averages, cumulative sums, group-level statistics), and interaction terms (products of two or more features). Mastering these categories equips you to transform raw transactional data into insight-rich feature sets.

Key formulas include the margin ratio (Revenue − Cost) / Revenue, the growth rate (Xₜ − Xₜ₋₁) / Xₜ₋₁, and the log transform ln(X + 1). When creating derived variables, always guard against data leakage, multicollinearity, and the curse of dimensionality. The best derived variables are those grounded in domain knowledge, validated through statistical testing, and interpretable to business stakeholders — ultimately transforming data wrangling from a chore into the most creative and impactful stage of any analytics project.

Varsity Tutors • Business Analytics • Creating Derived Variables — Create derived variables and feature columns