10/21/25, 11:29 AM Basic Transaction Data Analytics
Basic Transaction Data Analytics
Professor Karsten T. Hansen
University of California, San Diego
[Link] 1/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Welcome
Goal: Show how transaction data powers insight → action across industries.
Focus: Data structures, analytics patterns, case examples, and in-class exercises.
Stack: Python + Polars for examples, plus light plotting.
[Link] 2/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
What is Transaction Data?
Atomic records of exchanges (e.g., a sale, a charge, a booking, a usage event).
Always time-stamped; often linked to customer, product, location.
Combines events (transactions) with dimensions (products, customers, stores).
Enables fine-grained slicing: by day/week, SKU, region, cohort, channel.
Typical fields: transaction_id, timestamp, customer_id, product_id, quantity, unit_price,
unit_cost, discount_pct, store_id/channel.
[Link] 3/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Why Transaction Data Matters
“Transaction data is the behavioral fingerprint of your business.”
Mirrors real customer behavior (revealed preferences).
Scales to millions of observations → robust signals.
Connects strategy (pricing, promo, assortment) to execution (what actually sold).
Produces continuous feedback loops for test → measure → iterate.
[Link] 4/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Sources & Examples (Retail/E-comm)
POS receipts, online orders, returns/exchanges.
Loyalty program swipes, coupon redemptions.
Click-to-cart and checkout step events.
Product + category + brand metadata; real-time pricing.
Decisions: Price points, promo timing, shelf space, inventory, cross-merchandising.
[Link] 5/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Sources & Examples (Finance/Telecom/Healthcare/More)
Banking: Card swipes, ACH transfers, ATM; fraud detection, CLV, offer targeting.
Telecom: Call/data records; churn prediction, bundle design, network load.
Healthcare/Insurance: Claims, prescriptions, policy payments; risk adjustment, leakage,
fraud.
Travel/Hospitality: Bookings, occupancy, spend-per-stay; dynamic pricing, upsell.
Energy/Transport/Media: Metering, ticketing, ad impressions; demand forecasting,
personalization.
[Link] 6/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Sources & Examples (Non-profit, Government etc.)
Non-profit: Donations, donor requests, donor communication, mailing history
Education: Student enrollments, course completions, event attendance
Public Sector: Service requests, permit applications, tax filings
Utilities: Consumption records, billing transactions, service requests
[Link] 7/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Data Model: Core Tables
Transactions (fact): receipt_id, product_id, customer_id, store_id, quantity,
unit_price, unit_cost, discount_pct, timestamp.
Products (dim): category, subcategory, brand, list_price.
Customers (dim): age, gender, income_band, loyalty_status, home_region.
Stores (dim): region, format, square_feet.
[Link] 8/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Analytical Lenses
1. Descriptive: What happened and why?
Trends, performance metrics, basket composition, comparative performance.
Shopping patterns
Root causes: promos, stockouts, weather, cannibalization patterns.
2. Predictive: What will happen next?
Forecast, churn/propensity, fraud, price sensitivity modeling.
3. Prescriptive: What should we do?
Markdown timing, price optimization, inventory targets, next-best-action.
[Link] 9/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Standard Performance Indicators
Total revenue, gross margin $, gross margin %, revenue per basket.
Units per transaction (basket size), category/brand shares.
New vs repeat customer mix, RFM (Recency, Frequency, Monetary) snapshots.
Store/region/format comparisons; weekday & seasonality.
[Link] 10/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Diagnostic Patterns to Look For
Margin leakage (lines below cost), price execution errors.
Promo dependency (only sells on discount?), cannibalization.
Shopping behaviors by segment (e.g., “deal hunters”, “brand loyalists”).
Microseasonality by day-of-week/time-of-day.
[Link] 11/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Case Set
We’ll work through these (select) cases:
1. Calculating Performance Indicators
2. Revenue Breakdown by Week, Category and Store
3. Margin Leakage Analysis
4. Price Elasticity
5. Store Format Role
6. Dashboarding with Transaction Data
7. Simple Predictive Analysis
[Link] 12/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Case 1: Calculating Performance Indicators
Let q be quantity sold, p be price, d discounts, c be cost, then:
Revenue (also “dollar sales”): r = (p − d) × q
Cost (also “cost of goods sold”): cogs = c × q
Gross Margin: m = r − cogs
Promotional investment: promo_inv = d × q
Margin Percentage: mp =
m
r
× 100%
These quantities can be computed at any aggregation level (SKU, category, store, day,
etc).
[Link] 13/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Case 3: Price Elasticity
Price elasticity of demand (PED) measures how quantity demanded responds to price
changes.
ΔQ/Q
Formula: P ED
%ΔQ
= =
%ΔP ΔP /P
Interpretation:
|P ED| > 1 : Elastic demand (sensitive to price changes)
|P ED| < 1 : Inelastic demand (less sensitive to price changes)
Applications: Pricing strategies, promotional planning, revenue optimization.
Best practice:
Market Experiments (A/B tests)
Predictive Models (control for confounding factors)
If we ignore other factors, we can get quick and easy elasticities by simply comparing
average sales across different price points
[Link] 14/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Simple Example: Calculating PED
Let p 1 = 10 q1 = 100, (initial price and quantity)
Let p 2 ,
= 8 q2 = 150 (new price and quantity)
Calculate percentage changes:
p −p 8−10
2 1
%ΔP = × 100% = × 100% = −20%
p 10
1
q −q 150−100
2 1
%ΔQ = × 100% = × 100% = 50%
q 100
1
Calculate PED:
%ΔQ 50%
P ED = = = −2.5
%ΔP −20%
[Link] 15/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Why are price elasticities important?
Pricing Strategy: Helps set optimal prices to maximize revenue and profit.
Intution: Profit is Π(p) = (p − c) × Q(p) where c is cost and Q(p) is quantity sold at
price p. A small change in price, then leads to
dΠ dQ
= Q(p) + (p − c) × = Q(p) (1 + m × PED) ,
dp dp
m = margin percentage. Then
If PED < −1/m , decreasing price increases profit.
If PED > −1/m , increasing price increases profit.
[Link] 16/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Simple Predictive Analytics with Transaction Data
Goal: Predict customer spend per month during the three months October - December
2024 using only the data observed before October 2024.
Data: Transaction data from January 2023 - September 2024.
You will want to train a predictive model for this task.
We will do that later. Let’s do something simpler for now
[Link] 17/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
The Target
Customer ID Holdout Spend per month Prediction
1 $12.3 ?
2 $27.2 ?
3 $0 ?
4 $137 ?
. . .
. . .
[Link] 18/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Evaluation of Predictions
−−−−−−−−−−−− −
N
1
2
^ )
RM S E = ∑(yi − y
i
⎷N
i=1
N
1
M AE = ^ |
∑ |yi − y
i
N
i=1
[Link] 19/20
10/21/25, 11:29 AM Basic Transaction Data Analytics
Making Predictions
Suppose we know nothing about the customers EXCEPT what income group they belong
to
Then we can group customers by income group and compute the average spend per
month in each income group in the training data (January 2023 - September 2024)
In this case, the predictions for each customer in the hold-out period is simply the
average spend per month for their income group in the training period
If we only know their loyalty level we can do the same grouping by loyalty level
Or we can try groups of both income group and loyalty level
Basic Transaction Data Analytics
Speaker notes
[Link] 20/20