---
title: Review DAX
tags: dax-foundation-course, pbionline
---
:::info
[datapot.vn](datapot.vn), 2022.
:::
# Review DAX
## Part 1: DAX theories
**Contents**:
- Context in Power BI: Row context and Filter context
- Model objects (mostly) related to DAX: Measures and Calculated Columns
- Common functions: `CALCULATE`, `USERELATIONSHIP`, `FILTER`, `KEEPFILTER`, `REMOVEFILTER`, `VALUE`, Time Intelligence functions, Iterator functions, Aggregation function (`SUM`, `DIVIDE`, `MIN`, `MAX`, etc.)
## Part 2: DAX Practices
Link download practice file: [DAX-Practice](https://datapotanalytic.sharepoint.com/:u:/s/PL300Template/EQcU39k9x-FGk1yjTeNMBuUBBAR98DDS0UCJTfSl0LK0zg?e=K8wzK2)
**AdventureWorks InternetSales**

### I - CALCULATE function
**Question 1**: Calculate % revenue of red bikes to total revenue.
Present the result as follows:
(`Country` field is from `Customer` table)

**Question 2**: Calculate % revenue of all customer from United States (`Country` column, `Customer` table) or from London (`City` column, `Customer` table) to total revenue.
Present the result as follows:
(`Country` field is from `Customer` table)

**Question 3**: Calculate number of orders buying Bikes with `UnitPrice` (`InternetSales` table) less than $1000.
Present the result as follows:

### II - Conditional functions
**Question 4**: Use "Data Groups" feature, create a new group from `Standard Cost` column, `Product` table, with bin size $100. Create the following visual:

(Don't forget to sort columns by `Standard Cost (bins)`)
**Question 5**: Based on the above result, create a new column with `IF` function that classifies `Standard Cost` as:
- Standard Cost < $200 -> "Group 1"
- Standard Cost >= 200 and < 600 -> "Group 2"
- Standard Cost >= 600 and < 1000 -> "Group 3"
- Standard Cost >= 1000 -> "Group 4"
Create another visual to present result:

**Question 6**: Use `SWITCH` function to solve question 5.
**Comment**: You can also create `Age Group` for Age column in Customer table.
### III - Time Intelligence functions
**Question 7**: Calculate PY Revenue with 3 different ways using the following functions: `SAMPEPERIODLASTYEAR`, `DATEADD`, `PARALLELPERIOD`.
Create the following visual:

**Question 8**: Calculate accumulation of profit margin for the fiscal year of AdventureWork.

**Question 9**: Calculate a cummulative revenue that sums up all revenue up to certain date, depends on current filter context to date table.

**Question 10**: Calculate total revenue at the end of each period.

### IV - Iterator functions
**Question 11**: Calculate average profit and average profit margin per order.

**Question 12**: Create a measure to rank product according to their quantity.
