Ravindra BagaleCourses & study guides मराठी Track your progress

13. DAX: Data Analysis Expressions

Power BI DAX Practice Exercise with Answer Key

Suppose we are making the Blinkit Maharashtra March report. Here are six orders (fictional practice data). Do the exercise before you open the answer key.

Order ID City Platform Order Status Amount (₹)
1 Pune Blinkit Delivered 400
2 Pune Blinkit Cancelled 0
3 Mumbai Blinkit Delivered 600
4 Mumbai Amazon Now Delivered 500
5 Nashik Blinkit Delivered 300
6 Pune Amazon Now Delivered 200

Exercise (one under the other):

  1. Load the table with Home › Enter data. Name it Orders.
  2. Write Total Sales, Total Orders, Delivered Orders.
  3. Write AOV and Cancel Rate with DIVIDE.
  4. Write Pune Sales with CALCULATE.
  5. Write % of Total with ALL.
  6. Build a matrix: Rows = City. Add a City slicer and select Mumbai. Read the Pune Sales card.

Expected result (check your numbers):

City Total Sales Total Orders Delivered AOV Cancel Rate % of Total
Pune ₹600 3 2 ₹300 33.3% 30%
Mumbai ₹1,100 2 2 ₹550 0% 55%
Nashik ₹300 1 1 ₹300 0% 15%
Total ₹2,000 6 5 ₹400 16.7% 100%

With the City slicer on Mumbai, the Pune Sales card still shows ₹600.

Answer key (open after you try)
Total Sales      = SUM(Orders[Amount])
Total Orders     = DISTINCTCOUNT(Orders[Order ID])
Delivered Orders = CALCULATE([Total Orders], Orders[Order Status] = "Delivered")
Cancelled Orders = CALCULATE([Total Orders], Orders[Order Status] = "Cancelled")
AOV              = DIVIDE([Total Sales], [Delivered Orders])
Cancel Rate      = DIVIDE([Cancelled Orders], [Total Orders])
Pune Sales       = CALCULATE([Total Sales], Orders[City] = "Pune")
% of Total       = DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Orders[City])))

Why Pune Sales stays ₹600: the City filter inside CALCULATE replaces the slicer filter on the same column.

Common mistakes:

What you see Why Fix
AOV = ₹333 You used AVERAGE(Orders[Amount]). It divides by all 6 rows, including the cancelled ₹0 row. Use DIVIDE([Total Sales], [Delivered Orders]) = 2,000 ÷ 5 = ₹400.
% of Total = 100% on every row ALL is on a different City column than the one in the matrix (for example DarkStore[City] vs Orders[City]). Use ALL on the same column you put in the rows.
Error or ∞ for a city with no orders You used /. Use DIVIDE. It returns blank.
Pune Sales is blank when the slicer is on Mumbai The slicer is on DarkStore[City] but CALCULATE filters Orders[City]. Both filters stay, and no row is Pune and Mumbai at once. Filter the same column the slicer uses.

Samajla ka? If one number does not match, do not change the formula first. First check the data and the column you used.

Thodkyaat sangaycha tar (quick recap)

Base measures first; a measure runs in the filter context; CALCULATE changes filters; use DIVIDE; and time intelligence needs a marked Date table. Got it? If not, read 13.3 and 13.8 once more – everything else stands on them. Now let us move on to visuals.