A complete end-to-end data analytics project on a real-world online retail dataset. Raw transactional data is cleaned, structured, and analyzed using MySQL, then visualized through an interactive Power BI dashboard.
Online-Retail-SQL-PowerBI/
│
├── Online Retail.sql # Full SQL script: DB setup, ETL, KPIs & analysis
├── Online Retail Dashboards.pbix # Power BI dashboard file
├── Online Retail Dataset.zip # Raw dataset (CSV)
├── SQL Outputs/ # Query result screenshots / exports
└── LICENSE # MIT License
The dataset is a UK-based online retail transaction record containing all purchases between 2010 and 2011. It includes:
| Column | Description |
|---|---|
InvoiceNo |
Unique transaction identifier |
StockCode |
Product code |
Description |
Product name |
Quantity |
Units purchased per transaction |
InvoiceDate |
Date and time of transaction |
UnitPrice |
Price per unit (GBP) |
CustomerID |
Unique customer identifier |
Country |
Customer's country |
The raw CSV is provided as
Online Retail Dataset.zipin the repository.
- MySQL — Database creation, data cleaning, ETL pipeline, and analytical queries
- Power BI — Interactive dashboard and data visualization
- SQL Concepts Used — CTEs, Window Functions (
RANK,NTILE), Joins, Subqueries, Temporary Tables, Indexing, Date Functions
- Created the
ONLINE_RETAILdatabase and aRAW_DATAtable to load the CSV. - Imported data using
LOAD DATA LOCAL INFILE. - Converted
INVOICE_DATEfrom string to properDATETIMEformat usingSTR_TO_DATE. - Created indexes on
CUSTOMER_ID,INVOICE_NO,STOCK_CODE, andINVOICE_DATEfor query performance.
Normalized the raw data into four structured tables:
CUSTOMERS ──┐
├──> ORDERS ──> ORDER_ITEMS <── PRODUCTS
| Table | Key Columns |
|---|---|
CUSTOMERS |
CUSTOMER_ID, COUNTRY, REGISTRATION_DATE |
PRODUCTS |
PRODUCT_ID, PRODUCT_NAME |
ORDERS |
ORDER_ID, CUSTOMER_ID, ORDER_DATE |
ORDER_ITEMS |
ORDER_ID, PRODUCT_ID, QUANTITY, UNIT_PRICE |
Queries written to power the dashboard and answer business questions:
| Analysis | Description |
|---|---|
| Total Revenue | Overall revenue from all orders |
| Total Orders | Count of distinct invoices |
| Average Order Value | Revenue divided by total orders |
| Monthly Revenue | Revenue trend grouped by month |
| Revenue by Country | Country-wise revenue breakdown |
| Top 10 Products by Revenue | Best-selling products |
| Top Customer per Country | Highest spender in each country using RANK() OVER PARTITION BY |
| Customer Lifetime Value (CLV) | Total revenue attributed per customer |
| Repeat Customer Rate | % of customers with more than one order |
| Average Order Frequency | Average number of orders per customer |
| Customer Ranking by Revenue | Global ranking of customers by spend |
| Customer Ranking by Orders | Global ranking by number of orders |
| Cohort Analysis | Monthly retention — tracks when customers first purchased vs. when they returned |
| RFM Segmentation | Recency, Frequency, Monetary scoring using NTILE(5) + rule-based segmentation into Champions, Loyal Customers, At Risk, New Customers, and Others |
The .pbix file (Online Retail Dashboards.pbix) connects to the SQL outputs and presents:
- 📈 Revenue Trends — Monthly revenue chart
- 🌍 Geographic Analysis — Revenue by country
- 🏆 Top Products — Best-performing SKUs
- 👥 Customer Segmentation — RFM-based segments
- 🔄 Cohort Retention — Customer cohort analysis
- 💰 CLV Overview — Customer lifetime value distribution
Open the
.pbixfile in Power BI Desktop to explore or modify the dashboards.
- MySQL Server (v8.0+) with
LOCAL_INFILEenabled - Power BI Desktop (free download from Microsoft)
-
Clone the repository
git clone https://github.com/PrakharSri18-data/Online-Retail-SQL-PowerBI.git
-
Prepare the dataset
- Extract
Online Retail Dataset.zip - Place the CSV file at the path referenced in the SQL script (update the
LOAD DATApath to match your local system)
- Extract
-
Run the SQL script
- Open
Online Retail.sqlin MySQL Workbench (or any MySQL client) - Execute the full script top-to-bottom
- Tables will be created and populated automatically
- Open
-
Open the dashboard
- Open
Online Retail Dashboards.pbixin Power BI Desktop - Refresh the data source connection if needed
- Open
- RFM Segmentation identifies high-value "Champions" vs. churning "At Risk" customers — enabling targeted retention strategies.
- Cohort Analysis reveals how customer retention evolves month-over-month after the first purchase.
- Country-wise revenue highlights geographic concentration, helping prioritize marketing spend.
- Top 10 products by revenue can guide inventory and promotional decisions.
This project is licensed under the MIT License © 2026 Prakhar Srivastava.
Prakhar Srivastava
Data Scientist & Business Analyst | Machine Learning, Deep Learning & Generative AI Enthusiast
GitHub