Bird
Raised Fist0
Power BIbi_tool~15 mins

Optimizing DAX queries in Power BI - Real Business Scenario

Choose your learning style10 modes available
Scenario Mode
👤 Your Role: You are a Power BI developer at a retail company.
📋 Request: Your manager wants you to improve the performance of slow Power BI reports by optimizing the DAX queries used in key measures.
📊 Data: You have sales data with columns: Date, Product, Region, SalesAmount, Quantity, and CustomerID. The data has about 100,000 rows.
🎯 Deliverable: Create optimized DAX measures that calculate Total Sales and Average Sales per Customer efficiently, and demonstrate the performance improvement with a simple report.
Progress0 / 6 steps
Sample Data
DateProductRegionSalesAmountQuantityCustomerID
2024-01-01Widget ANorth1002C001
2024-01-02Widget BSouth1503C002
2024-01-03Widget AEast2004C001
2024-01-04Widget CWest1201C003
2024-01-05Widget BNorth1803C002
2024-01-06Widget ASouth1302C004
2024-01-07Widget CEast1703C001
2024-01-08Widget BWest1602C003
2024-01-09Widget ANorth1403C004
2024-01-10Widget CSouth1101C002
1
Step 1: Create a basic Total Sales measure using SUM.
Total Sales = SUM(Sales[SalesAmount])
Expected Result
Total Sales sums all sales amounts correctly.
2
Step 2: Create a basic Average Sales per Customer measure using AVERAGEX and VALUES.
Average Sales per Customer = AVERAGEX(VALUES(Sales[CustomerID]), CALCULATE(SUM(Sales[SalesAmount])))
Expected Result
Calculates average sales amount per unique customer.
3
Step 3: Identify performance issue: AVERAGEX with VALUES can be slow on large data.
No formula, observation based on report slowness.
Expected Result
Report refresh is slow when using Average Sales per Customer measure.
4
Step 4: Optimize Average Sales per Customer by using DIVIDE and DISTINCTCOUNT to avoid row context iteration.
Average Sales per Customer Optimized = DIVIDE([Total Sales], DISTINCTCOUNT(Sales[CustomerID]), 0)
Expected Result
Faster calculation of average sales per customer without slow iteration.
5
Step 5: Create a report table visual with columns: Region, Total Sales, Average Sales per Customer Optimized.
Configure table visual in Power BI with fields: Region, Total Sales, Average Sales per Customer Optimized.
Expected Result
Report shows sales and average sales per customer by region with improved performance.
6
Step 6: Test report refresh time before and after optimization to confirm performance improvement.
No formula, measure report refresh time in Power BI.
Expected Result
Report refresh is noticeably faster after optimization.
Final Result
-----------------------------------------
| Region | Total Sales | Avg Sales/Customer |
-----------------------------------------
| North  | 420         | 140                |
| South  | 390         | 195                |
| East   | 370         | 370                |
| West   | 280         | 280                |
-----------------------------------------
✓Using DIVIDE with DISTINCTCOUNT is faster than AVERAGEX with VALUES for average calculations.
✓Optimized DAX measures improve report refresh time significantly.
✓Total Sales by region helps identify best performing areas quickly.
Bonus Challenge

Create an optimized DAX measure to calculate the running total of sales by date.

Show Hint
Use CALCULATE with FILTER and ALLSELECTED to accumulate sales up to the current date.

Practice

(1/5)
1.

What is a simple way to improve the performance of a DAX query in Power BI?

SUM(Sales[Amount]) is slow. What should you do?

easy
A. Avoid using filters in the query
B. Add more columns to the table
C. Use complex nested IF statements
D. Use variables to store intermediate results

Solution

  1. Step 1: Understand the role of variables in DAX

    Variables store intermediate results to avoid repeated calculations, making queries faster.
  2. Step 2: Apply variables to the example

    Using variables in SUM(Sales[Amount]) can reduce repeated scans and improve speed.
  3. Final Answer:

    Use variables to store intermediate results -> Option D
  4. Quick Check:

    Variables improve performance [OK]
Hint: Use variables to avoid repeated calculations [OK]
Common Mistakes:
  • Adding unnecessary columns slows down queries
  • Using complex nested IFs increases calculation time
  • Ignoring filters can cause large data scans
2.

Which of the following is the correct syntax to define a variable in a DAX measure?

Measure = ?
easy
A. Measure = DEFINE Total = SUM(Sales[Amount]) USE Total
B. Measure = VAR Total = SUM(Sales[Amount]) RETURN Total
C. Measure = LET Total = SUM(Sales[Amount]) THEN Total
D. Measure = SET Total = SUM(Sales[Amount]) OUTPUT Total

Solution

  1. Step 1: Recall DAX variable syntax

    DAX uses VAR to declare variables and RETURN to output the result.
  2. Step 2: Match syntax with options

    Measure = VAR Total = SUM(Sales[Amount]) RETURN Total correctly uses VAR Total = SUM(Sales[Amount]) RETURN Total.
  3. Final Answer:

    Measure = VAR Total = SUM(Sales[Amount]) RETURN Total -> Option B
  4. Quick Check:

    VAR and RETURN are correct DAX keywords [OK]
Hint: Remember: VAR ... RETURN in DAX for variables [OK]
Common Mistakes:
  • Using LET or DEFINE instead of VAR
  • Forgetting RETURN keyword
  • Using SET or OUTPUT which are not DAX keywords
3.

Consider this DAX measure:

Measure =
VAR FilteredSales = FILTER(Sales, Sales[Region] = "West")
RETURN SUMX(FilteredSales, Sales[Amount])

What is the main performance issue with this measure?

medium
A. FILTER creates a filtered table and SUMX iterates over it, which can be slow if Sales is large
B. FILTER is applied before SUMX, which is efficient
C. FILTER creates a filtered table but SUMX uses the original table, causing repeated scans
D. FILTER creates a table but SUMX iterates over original Sales table

Solution

  1. Step 1: Analyze FILTER and SUMX behavior

    FILTER creates a filtered table of Sales where Region is "West". SUMX iterates over this filtered table.
  2. Step 2: Understand performance impact

    If Sales is large, creating and iterating over a filtered table can be slow. Better to filter early or use CALCULATE with SUM.
  3. Final Answer:

    FILTER creates a filtered table and SUMX iterates over it, which can be slow if Sales is large -> Option A
  4. Quick Check:

    FILTER + SUMX on large tables can slow queries [OK]
Hint: Avoid FILTER + SUMX on big tables; use CALCULATE [OK]
Common Mistakes:
  • Thinking SUMX iterates original table, not filtered
  • Assuming FILTER before SUMX is always fast
  • Ignoring table size impact on performance
4.

Identify the error in this DAX measure that aims to optimize performance:

Measure =
VAR TotalSales = SUM(Sales[Amount])
RETURN
CALCULATE(TotalSales, FILTER(Sales, Sales[Region] = "East"))
medium
A. Using FILTER inside CALCULATE is always slow
B. TotalSales should be inside FILTER function
C. TotalSales is a scalar evaluated outside CALCULATE, so the filter does not apply
D. No error; measure is optimized

Solution

  1. Step 1: Check variable type and usage

    TotalSales = SUM(Sales[Amount]) is a scalar value computed in the original filter context.
  2. Step 2: Analyze CALCULATE arguments

    CALCULATE(TotalSales, FILTER(Sales, Sales[Region]="East")) is syntactically valid, but since TotalSales is a pre-computed scalar, the modified filter context does not re-evaluate it. It returns the unfiltered total instead of East sales, defeating the performance optimization goal for filtered calculation.
  3. Final Answer:

    TotalSales is a scalar evaluated outside CALCULATE, so the filter does not apply -> Option C
  4. Quick Check:

    Scalar variable used incorrectly with CALCULATE filter [OK]
Hint: Scalar variables computed outside aren't affected by CALCULATE filters [OK]
Common Mistakes:
  • Thinking CALCULATE re-evaluates scalar variables in new context
  • Thinking FILTER inside CALCULATE is always slow
  • Not distinguishing scalar vs table types
5.

You want to optimize a DAX measure that calculates total sales for the current year only. Which approach is best for performance?

Option 1:
Measure = CALCULATE(SUM(Sales[Amount]), FILTER(Sales, YEAR(Sales[Date]) = YEAR(TODAY())))

Option 2:
Measure = CALCULATE(SUM(Sales[Amount]), Sales[Date].[Year] = YEAR(TODAY()))
hard
A. Option 2 is better because it uses column filter, not row filter
B. Option 1 is better because FILTER is more flexible
C. Both options have same performance
D. Neither option works; use SUMX instead

Solution

  1. Step 1: Compare FILTER vs direct column filter

    Option 1 uses FILTER which scans row by row, applying YEAR function, which is slow.
  2. Step 2: Understand column filter advantage

    Option 2 uses a direct filter on the date column's Year attribute, which is faster because it uses existing column indexing and avoids row-by-row evaluation.
  3. Final Answer:

    Option 2 is better because it uses column filter, not row filter -> Option A
  4. Quick Check:

    Use column filters over FILTER for better speed [OK]
Hint: Filter on columns, not rows, for faster DAX queries [OK]
Common Mistakes:
  • Using FILTER with row context unnecessarily
  • Assuming FILTER is always faster
  • Ignoring built-in column filters
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard