---
title: Introduction to DAX - Part 5 - Bonus Contents
tags: dax-foundation-course
---
# Bonus Contents
### DAX variables
Variables offer several benefits:
- Improving the readability and maintenance of your formulas.
- Improving performance because variables are evaluated once and only when or if they're needed.
- Allowing (at design time) straightforward testing of a complex formula by returning the variable of interest.

### Use relationship effectively
:question: How to manipulate relationship in data model using DAX?
**Practice file**: Resellers Sales Model of AdventureWork.
In this example, you have to open Power Query Editor and choose 2 additional columns in Sales table:
- DueDate
- ShipDate
In the Model view, create relationships between Sales table and Date table:
- Sales | DueDate to Date | Date
- Sales | ShipDate to Date | Date

**Task 1**: Calculate total sales amount that shipped, and total sales amount that due.
```python=
Sales (Shipped) =
CALCULATE(
SUM(Sales[Sales]),
USERELATIONSHIP('Date'[Date], Sales[ShipDate]))
```
```python=
Sales (Due) =
CALCULATE(
SUM(Sales[Sales]),
USERELATIONSHIP('Date'[Date], Sales[DueDate]))
```

**Task 2**: Fix Sales Shipped measure
```python=
Sales Shipped =
CALCULATE(
SUM(Sales[Sales]),
USERELATIONSHIP('Date'[Date], Sales[ShipDate]),
FILTER(
'Date',
'Date'[Year] <> BLANK())
)
```
