DAX Exercises
Start by opening the "DAX Exercises – Start.pbix” file in your Power BI Desktop application.
1. Add a calculated column called [Revenue] to the [Sales] table that calculates revenue amount
for each sales transaction by multiplying the number of Units from the [Sales] table by the [Unit
Price] from the [ProductDim] table. Hint: use the RELATED function.
Add a table visual to the report canvas that shows Revenue by month.
2. Add a calculated column called [COGS] to the [Sales] table that calculates the cost of goods sold
for each sales transaction by multiplying the number of Units from the [Sales] table by the [Unit
Cost] from the [ProductDim] table. Hint: use the RELATED function.
Add COGS column to the table visual you created in the previous exercise.
3. Add a measure called [Gross Profit] that calculates the gross profit by subtracting total COGS
from total Revenue. Hint: use the SUM function.
Add Gross Profit column to the table visual you created in the previous exercise.
4. Add a measure called [Revenue Last Year] by calculating revenue for the same period a year ago.
Hint: use the CALCULATE and SAMEPERIODLASTYEAR functions.
Add Revenue Last Year column to the table visual you created in the previous exercise.
5. Add a measure called [YoY Revenue Change] by calculating the difference between revenue
during any given time period and similar time period a year ago.
Add YoY Revenue Change column to the table visual you created in the previous exercise.
6. Add a measure called [YoY Revenue % Change] by calculating the % change in revenue between
any given time period and similar time period a year ago.
Add YoY Revenue % Change column to the table visual you created in the previous exercise.
7. Bonus challenge: rewrite the [Gross Profit] measure in such a way that it does require the
[Revenue] and [Sales] calculated columns to be created. Hint: use the SUMX function.
Finished Results
Your end results should resemble the following table:
Answers
1. Revenue = Sales[Units] * RELATED(ProductDim[Unit Price])
2. COGS = Sales[Units] * RELATED(ProductDim[Unit Cost])
3. Gross Profit = SUM(Sales[Revenue]) - SUM(Sales[COGS])
4. Revenue Last Year = CALCULATE(SUM(Sales[Revenue]), SAMEPERIODLASTYEAR(DateDim[Date]))
5. YoY Revenue Change = SUM(Sales[Revenue]) - [Revenue Last Year]
6. YoY Revenue % Change = DIVIDE([YoY Revenue Change], [Revenue Last Year])
7. Gross Profit - Version 2 = SUMX(Sales, Sales[Units] * RELATED(ProductDim[Unit Price]))-
SUMX(Sales, Sales[Units] * RELATED(ProductDim[Unit Cost]))