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):
- Load the table with Home › Enter data. Name it
Orders. - Write
Total Sales,Total Orders,Delivered Orders. - Write
AOVandCancel RatewithDIVIDE. - Write
Pune SaleswithCALCULATE. - Write
% of TotalwithALL. - 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.
Base measures आधी, measure filter context मध्ये चालतो, CALCULATE filters बदलतो, DIVIDE वापरा, आणि time intelligence साठी marked Date table हवा. समजलं का? नसेल तर 13.3 आणि 13.8 पुन्हा एकदा वाचा – बाकी सगळं त्यावर उभं आहे. आता पुढे जाऊया visuals कडे.
Base measures पहले, measure filter context में चलता है, CALCULATE filters बदलता है, DIVIDE इस्तेमाल कीजिए, और time intelligence के लिए marked Date table चाहिए. समझ आया? नहीं तो 13.3 और 13.8 एक बार फिर पढ़िए – बाक़ी सब उन्हीं पर खड़ा है. अब आगे बढ़ते हैं visuals की ओर.