← All projects
Excel

Credit Card Fraud Analysis

An Excel analysis of 284,807 real card transactions (Kaggle, ULB Machine Learning Group). Power Query removes 1,081 duplicate rows, Power Pivot models the result with DAX, and a rule tester shows how much fraud two simple thresholds would catch.

DateDec 2026
ToolsPower Query, M, Power Pivot, DAX, CUBEVALUE, PivotTables, Slicers, SUMIFS
Credit Card Fraud Analysis
1,081 duplicate rows removed, 19 of them frauds, so fraud cases fall from 492 to 473 (0.17% of transactions)
Fraud peaks at hour 2 of the day (1.45%, nearly 9× average) and zero-amount "card tests" are 8× riskier
A two-feature rule catches 77% of fraud and €40,294 of the €58,591 lost, while flagging only 0.2% of transactions

The problem

Fraud is rare, so it hides inside the averages. Of 284,807 European card transactions over two days in September 2013, only 492 are labelled fraud. The question is where the fraud concentrates and how far a simple, explainable rule gets before a bank needs a machine-learning model.

The data is the public Credit Card Fraud Detection dataset from the Machine Learning Group at ULB (Kaggle). Most columns (V1-V28) are anonymised PCA components; only Time, Amount (EUR) and Class are in plain form.

Data cleaning (Power Query)

  • File path parameter: the 150 MB CSV is read through a FilePath parameter, with numbers typed using the en-US locale.
  • 1,081 exact duplicate rows removed with Table.Distinct across all 31 columns. 19 of them were frauds, so leaving them in would have overstated fraud by 4%.
  • No missing values, which the cleaning log confirms rather than assumes.
  • 1,808 zero-amount transactions kept in their own amount band instead of being dropped. That turned out to matter, as the insights below show.
  • New columns: Day and Hour come from “seconds since the first transaction”, and each transaction gets an amount band.
  • One query per output, each loaded only where it’s needed:
    • a 6-column table into the data model
    • feature statistics, rule bins and the cleaning log onto sheets

How it works

Data model (Power Pivot): 283,726 cleaned rows with DAX measures for fraud cases, fraud rate, fraud value, average fraud and genuine amounts, and a fraud-rate index against the overall average.

Report: slicers for day and amount band drive six CUBEVALUE tiles, four PivotCharts and a fraud-by-amount scorecard.

Feature analysis: the FeatureStats query computes, for all 28 PCA features, the mean and standard deviation of fraud and genuine transactions and Cohen’s d, which measures how far apart the two groups are.

Feature separation

Rule tester: pick two thresholds and the workbook reports fraud caught, false alarms, precision, recall, F1 and fraud value caught, plus a precision-recall sweep. It uses a pre-binned table from Power Query, so the results are exact without loading 284k rows onto a sheet.

Rule tester

Data quality log

Key insights

  • Fraud is 0.17% of transactions but 0.23% of value. Average fraud is €123.87 against €88.41 for genuine transactions.
  • Small and large at once: 45% of fraud cases are under €10, yet 66% of the money lost is in €100-1,000 transactions.
  • Night-time risk: in hour 2 of each day, 1.45% of transactions are fraud, nearly 9× the average, while genuine volume is at its lowest.
  • Zero-amount transactions are 8× riskier (1.38% fraud), consistent with fraudsters testing whether a card works.
  • Two features do most of the work. V17 and V14 separate the classes by about 8 and 7.5 standard deviations. Flagging V14 < −5 or V17 < −4 catches 364 of 473 frauds (77%) and €40,294 of value, with 62% precision.

Checking it

I recalculated every headline number independently in Python: duplicates removed, fraud counts, feature effect sizes, the rule tester at two threshold settings, and the hourly rates. The workbook matched in every case.

📊 Download the workbook (.xlsx). The data model is already loaded. To refresh from the source, download creditcard.csv from Kaggle and point the FilePath parameter at it.