Chapter 1
Chapter 1
Carl Rosseel
Curriculum Manager at DataCamp
DAX stands for data analysis expressions
DAX is a formula expression language used in multiple Microso analytics tools
DAX formulas include functions, operators and values to perform advanced calculations
Calculated columns
Calculated tables
Row-level security
DAX IN POWER BI
The power of DAX
It opens up new capabilities:
Joins, lters, measures and calculated elds become part of your toolbox
DAX IN POWER BI
Measures vs calculated columns
Calculated Columns:
DAX IN POWER BI
Measures vs calculated columns
Calculated Columns: Measures:
DAX IN POWER BI
Context allows you to perform dynamic analysis
There are three types of context: row, query and lter context
DAX IN POWER BI
Context allows you to perform dynamic analysis
There are three types of context: row, query and lter context
DAX IN POWER BI
Context allows you to perform dynamic analysis
There are three types of context: row, query and lter context
DAX IN POWER BI
Context allows you to perform dynamic analysis
Query context: (2) Query context: (2)
Example: Filter data by Region. Example: Filter data by State.
DAX IN POWER BI
Context allows you to perform dynamic analysis
There are three types of context: row, query and lter context
By using arguments to a formula or by using report lters on row and column headings
DAX IN POWER BI
Context allows you to perform dynamic analysis
There are three types of context: row, query and lter context.
DAX IN POWER BI
Context in a nutshell
DAX IN POWER BI
World wide importers dataset
A ctitious wholesaler who imports and
distributes novelty goods
Customers
Cities
Employees
Stock Items
DAX IN POWER BI
Let's practice!
DA X I N P OW E R B I
DAX for calculated
tables and columns
DA X I N P OW E R B I
Carl Rosseel
Curriculum Manager
Let's practice!
DA X I N P OW E R B I
Methods to create
DAX measures
DA X I N P OW E R B I
Carl Rosseel
Curriculum Manager
Implicit vs explicit measures
Implicit Explicit
DAX IN POWER BI
Why explicit measures are preferred
Reduces confusion of what a measure is or does
Total Sales = SUM(Orders[Sales])
Total Sales is more clear than Sales (SUM, AVG, MIN, ... ?)
DAX IN POWER BI
Best practices
Keep DAX measures grouped together: Format and comment with DAX:
Measures are free to move to any table Use indentations to increase
understanding
This is in contrast with calculated
Shi Enter to start a new line
columns, which belong to a speci c table
Tab to indent
Add comments a er a //
DAX IN POWER BI
Use variables to improve your formulas
Stores the result of an expression as a Syntax:
named variable
VAR <name> = <expression>
Can be used as an argument to other
Name = The name of the variable
measure expressions
A DAX expression which returns a scalar
Four main advantages:
or table value
Improve performance
Followed by a RETURN statement
Improve readability
Simplify debugging
Reduce complexity
DAX IN POWER BI
Use variables to improve your formulas - example
Calculate the sales from last year and store it as a variable
VAR
SALESPRIORYEAR = CALCULATE([SALES],SAMEPERIODLASTYEAR('DATE'))
RETURN
DAX IN POWER BI
Use variables to improve your formulas - example
All together it would look like this:
Sales growth =
VAR
SALESPRIORYEAR = CALCULATE([SALES],SAMEPERIODLASTYEAR('DATE'))
RETURN
DAX IN POWER BI
Let's practice!
DA X I N P OW E R B I
DAX and measures
DA X I N P OW E R B I
Carl Rosseel
Curriculum Manager
Let's practice!
DA X I N P OW E R B I