Project 01 — Full-Stack BI

Sales Intelligence Dashboard

End-to-end BI project built on a normalized SQLite schema, powered by 10 analytical SQL queries featuring CTEs, window functions, and YoY analysis — visualized with Chart.js.

SQL SQLite Node.js Express JavaScript Chart.js Window Functions CTEs
Key Performance Indicators
Total Revenue
$86.7k
2023 – 2024
Total Profit
$17.9k
All orders
Profit Margin
20.6%
Blended avg
Total Orders
57
2023 – 2024
Customers
15
Unique
Monthly Revenue — Year over Year
2023 vs 2024  ·  CTE + conditional aggregation
▸ Query powering this chart
WITH monthly AS (
  SELECT
    strftime('%Y', o.order_date)  AS yr,
    strftime('%m', o.order_date)  AS mo,
    ROUND(SUM(oi.sales), 2)       AS revenue
  FROM orders o
  JOIN order_items oi ON o.order_id = oi.order_id
  GROUP BY yr, mo
)
SELECT
  mo AS month,
  MAX(CASE WHEN yr = '2023' THEN revenue END) AS revenue_2023,
  MAX(CASE WHEN yr = '2024' THEN revenue END) AS revenue_2024
FROM monthly
GROUP BY mo ORDER BY mo
Revenue by Category
Aggregation + JOIN
▸ Query powering this chart
SELECT
  p.category,
  ROUND(SUM(oi.sales), 2)   AS revenue,
  ROUND(SUM(oi.profit), 2)  AS profit,
  ROUND(SUM(oi.profit) /
    SUM(oi.sales) * 100, 1) AS margin_pct
FROM order_items oi
JOIN products p
  ON oi.product_id = p.product_id
GROUP BY p.category
ORDER BY revenue DESC
Revenue by Region
Multi-table JOIN
▸ Query powering this chart
SELECT
  c.region,
  ROUND(SUM(oi.sales), 2)  AS revenue,
  ROUND(SUM(oi.profit), 2) AS profit,
  ROUND(SUM(oi.profit) /
    SUM(oi.sales) * 100, 1)
                           AS margin_pct
FROM orders o
JOIN order_items oi
  ON o.order_id = oi.order_id
JOIN customers c
  ON o.customer_id = c.customer_id
GROUP BY c.region
ORDER BY revenue DESC
Customer Segments
Avg order value
▸ Query powering this chart
SELECT
  c.segment,
  COUNT(DISTINCT o.order_id)  AS orders,
  ROUND(SUM(oi.sales), 2)      AS revenue,
  ROUND(SUM(oi.profit) /
    SUM(oi.sales) * 100, 1)    AS margin_pct,
  ROUND(SUM(oi.sales) /
    COUNT(DISTINCT o.order_id),
    2)                         AS avg_order_value
FROM orders o
JOIN order_items oi
  ON o.order_id = oi.order_id
JOIN customers c
  ON o.customer_id = c.customer_id
GROUP BY c.segment
Discount Impact on Margin
CASE bucketing
▸ Query powering this chart
SELECT
  CASE
    WHEN discount = 0      THEN 'No Discount'
    WHEN discount <= 0.10  THEN '1–10%'
    WHEN discount <= 0.20  THEN '11–20%'
    ELSE                         '20%+'
  END                    AS discount_tier,
  ROUND(SUM(profit) /
    SUM(sales) * 100, 1) AS margin_pct
FROM order_items
GROUP BY discount_tier
Sales Rep Leaderboard
RANK() OVER window function
▸ Query powering this table
WITH rep_totals AS (
  SELECT
    sr.rep_name, sr.region,
    ROUND(SUM(oi.sales), 2)  AS revenue,
    ROUND(SUM(oi.profit) /
      SUM(oi.sales)*100, 1)  AS margin_pct,
    COUNT(DISTINCT
      o.order_id)            AS total_orders
  FROM orders o
  JOIN order_items oi ON o.order_id=oi.order_id
  JOIN sales_reps sr  ON o.rep_id=sr.rep_id
  GROUP BY sr.rep_id
)
SELECT
  RANK() OVER (ORDER BY revenue DESC) AS rank,
  rep_name, region, revenue,
  margin_pct, total_orders
FROM rep_totals ORDER BY rank
#RepRegionRevenueMarginOrders
1Kevin WrightSouth$35,375
20%
16
2Marcus LeeWest$23,600
21.2%
21
3Sarah JohnsonEast$14,520
22.2%
9
4Diana TorresCentral$13,254
19.4%
11
Top Products by Revenue
CTE + RANK() window function
▸ Query powering this table
WITH product_totals AS (
  SELECT
    p.product_name, p.category,
    ROUND(SUM(oi.sales), 2)    AS revenue,
    ROUND(SUM(oi.profit) /
      SUM(oi.sales)*100, 1)    AS margin_pct
  FROM order_items oi
  JOIN products p
    ON oi.product_id = p.product_id
  GROUP BY p.product_id
)
SELECT
  RANK() OVER
    (ORDER BY revenue DESC) AS rank,
  product_name, category,
  revenue, margin_pct
FROM product_totals
ORDER BY rank LIMIT 8
#ProductCategoryRevenueMargin
1MacBook Pro 16"Technology$35,600
20%
2Dell Monitor 27"Technology$11,600
29.4%
3Canon EOS CameraTechnology$9,500
20%
4Conference TableFurniture$9,000
17.2%
5Ergonomic ChairFurniture$5,730
18.4%
6Standing DeskFurniture$5,490
19.5%
7Bookcases OakFurniture$3,630
11.8%
8HP LaserJet PrinterTechnology$3,180
14.9%