Project Hub

Project · Power BI report fix

Rebuilding a sales report as a star schema, checked number by number

The problem

The sales report takes ages to open, some totals look wrong, and people go back to Excel because they stopped trusting it.

The solution

The slow report's flat model rebuilt as a star schema with a date table, its slow DAX rewritten, and every number checked against SQL before and after. Handed over with a build guide and a change log.

How it works

  • Measure: One timing method for every page, before and after: Performance Analyzer and DAX Studio from a cold cache
  • Model: The flat table rebuilt as a star schema with a proper date table
  • DAX: Slow measures rewritten with variables and filter context done right
  • Check: Every card, chart and table checked against SQL, the same in both reports
  • Hand over: Both reports, a step-by-step build guide and a note of every change

A closer look

How it works in five steps: time every slow page and visual, rebuild the flat table as a star schema, rewrite the slow measures with variables, compare every number before and after, and hand over the report with the timings.
Measure, rebuild, check, hand over.
Before and after: one flat sales table with calculated columns and hidden date tables, rebuilt as a star schema with date, customer and product dimensions and simpler DAX, held to the same check numbers.
The model before and after the rebuild.
Data flow: one box per step, in run order, from the input files to the report.
The steps, in run order.
The Power BI model before and after: the Bronze layer file loaded as it is, 2,098,633 order lines in one flat table of 41 columns, rebuilt as a star schema of 17 columns with 88,063 customers, 2,517 products and 3,653 dates.
41 columns in one table become 17 in the star schema.

The code

overview = q('''
SELECT count(*)                       AS sales_rows,
       count(DISTINCT order_key)      AS orders,
       count(DISTINCT customer_key)   AS customers,
       count(DISTINCT product_key)    AS products,
       min(order_date)                AS first_order,
       max(order_date)                AS last_order,
       round(sum(quantity * net_price)) AS sales_all_years
FROM sales
''')
analysis/analysis.ipynb

The impact

  • A lean model: each name stored once, no hidden date tables, no calculated columns.
  • Totals that add up, checked against the source.
  • Every change listed in a note, with a step-by-step build guide for the next developer.

The result

2,098,633 sales rows: a 35-column table rebuilt as a 4-table star schema, every check number worked out in SQL so both reports match.

Built with

  • Power BI
  • DAX
  • Power Query
  • DAX Studio
  • Python
  • SQL