Now do it in Power BI Desktop
DAX basics: Power BI Desktop exercise
Write the core measures in your own model and put them in one table. 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. Profit margin
Create Total Sales, Total Profit and Profit Margin (profit divided by sales, safely). Show the margin by Segment.
2. Average units per order line
How many units does an average row sell?
3. Distinct products
How many different products does each country sell?
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. Profit margin
Profit Margin = DIVIDE(SUM(financials[Profit]), SUM(financials[Sales]))| Segment | Profit Margin |
|---|---|
| Channel Partners | 73.13% |
| Enterprise | -3.13% |
| Government | 21.69% |
| Midmarket | 27.71% |
| Small Business | 9.77% |
| Total | 14.23% |
2. Average units per order line
Avg Units = AVERAGE(financials[Units Sold])Result: 1,608.29
3. Distinct products
Products Sold = DISTINCTCOUNT(financials[Product])| Country | Products Sold |
|---|---|
| Canada | 6 |
| France | 6 |
| Germany | 6 |
| Mexico | 6 |
| United States of America | 6 |
| Total | 6 |
The lessons behind this exercise
- Your first measure: SUM
- AVERAGE, MIN and MAX
- Practice: SUM, AVERAGE, MIN, MAX
- Counting with COUNTROWS and DISTINCTCOUNT
- COUNT and COUNTA
- Profit margin with DIVIDE
- ROUND: tidy numbers
- IF: make a decision
- AND, OR and NOT: combine conditions
- SWITCH: many cases
- Blanks: ISBLANK and COALESCE
- Practice: write the measure
- Calculated columns and RELATED
- Practice: calculated columns
- Skill check: DAX basics