0% found this document useful (0 votes)
18 views

Chapter 2

The document discusses best practices for creating measures in DAX for Power BI. It recommends writing measures explicitly using DAX functions rather than relying on implicit measures, as explicit measures are more clear, reusable, and sustainable to maintain. It provides examples of writing measures to calculate total sales and sales by region. The document also recommends structuring measures together, formatting measures with comments and indentation for readability, and using variables to store intermediate results and improve performance and readability of formulas.

Uploaded by

rida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Chapter 2

The document discusses best practices for creating measures in DAX for Power BI. It recommends writing measures explicitly using DAX functions rather than relying on implicit measures, as explicit measures are more clear, reusable, and sustainable to maintain. It provides examples of writing measures to calculate total sales and sales by region. The document also recommends structuring measures together, formatting measures with comments and indentation for readability, and using variables to store intermediate results and improve performance and readability of formulas.

Uploaded by

rida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Methods to create

DAX measures
DA X F U N C T I O N S I N P OW E R B I

Carl Rosseel
Curriculum Manager
Implicit vs explicit measures
Implicit Explicit

Automatically created by Power BI Writing measures in an explicit way

Comes directly from the Database E.g.: Total Sales = SUM(Orders[Sales])

E.g.: If we drag Sales to values of a table, O er exibility


Power BI will automatically sum it

Using a dropdown menu we can de ne the


aggregation: sum, average, count, ...

DAX FUNCTIONS 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, ... ?)

Reusable within other measures


Total Sales East = CALCULATE([Total Sales],Orders[Region] = 'East')

Can be given a custom name to explain its functionality

Makes maintenance of complex models more sustainable

DAX FUNCTIONS 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 FUNCTIONS 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 FUNCTIONS 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

Use the variable in a formula

Sales growth = [Sales] - SALESPRIORYEAR

DAX FUNCTIONS 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

Sales growth = [Sales] - SALESPRIORYEAR

DAX FUNCTIONS IN POWER BI


Let's practice!
DA X F U N C T I O N S I N P OW E R B I
DAX and Measures
DA X F U N C T I O N S I N P OW E R B I

Carl Rosseel
Curriculum Manager
Let's practice!
DA X F U N C T I O N S I N P OW E R B I

You might also like