12

Now do it in Power BI Desktop

Performance and enterprise: Power BI Desktop exercise

Measure first, then fix. Use Performance analyzer on your own report. You practised this in the browser; now do it in your own copy of Power BI Desktop (free from Microsoft), on the same data, and check your numbers below.

1. Get the data

In Power BI Desktop: Home → Get data → Text/CSV, pick each file, then Load. Check that numbers came in as numbers and dates as dates (Table view, column header icons).

2. The tasks

  1. 1. Rewrite a slow filter

    Replace CALCULATE([Total Sales], FILTER(financials, financials[Country] = "Canada")) with a column filter. The number must not change.

  2. 2. One variable instead of three calculations

    Write Margin Band with one VAR for the margin: Low under 10%, Medium under 30%, else High. What does it show by Segment?

  3. 3. Time it

    View → Performance analyzer → Start recording → Refresh visuals. Which visual takes longest? Copy its DAX query.

3. Check your numbers

Try every task first. Then open each answer: the numbers below come from the same data, so yours should match exactly.

1. Rewrite a slow filter
Canada Sales = CALCULATE(SUM(financials[Sales]), financials[Country] = "Canada")

Result: 24,887,654.88

2. One variable instead of three calculations
Margin Band = VAR m = DIVIDE(SUM(financials[Profit]), SUM(financials[Sales])) RETURN IF(m < 0.1, "Low", IF(m < 0.3, "Medium", "High"))
SegmentMargin Band
Channel PartnersHigh
EnterpriseLow
GovernmentMedium
MidmarketMedium
Small BusinessLow
3. Time it
  • Open DAX Studio (free) and paste the query to see the server timings.

The lessons behind this exercise