0% found this document useful (0 votes)
63 views18 pages

Chapter 2

The document provides an introduction to context in DAX formulas. There are three types of context: row context, filter context, and query context. Row context refers to the current row and allows calculations to use values from other columns in the same row. Filter context is a set of filters applied before a calculation runs, such as filters on attributes, slicers, or the filter pane. Calculated measures can apply filter context. The CALCULATE function allows applying additional filters to measures and calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views18 pages

Chapter 2

The document provides an introduction to context in DAX formulas. There are three types of context: row context, filter context, and query context. Row context refers to the current row and allows calculations to use values from other columns in the same row. Filter context is a set of filters applied before a calculation runs, such as filters on attributes, slicers, or the filter pane. Calculated measures can apply filter context. The CALCULATE function allows applying additional filters to measures and calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Context in DAX

Formulas
I N T R O D U C T I O N TO DA X I N P OW E R B I

Jess Ahmet
Content Developer, Datacamp
Introduction to Context
Enables dynamic analysis where results of a formula change to re ect the selected data

There are 3 types of context: row, lter and query

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

Calculated Column

Includes values from all columns within the current row

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

Calculated Column

Includes values from all columns within the current row

Item Price Tax Price_with_tax


A $ 20 25% $25
B $ 45 0% $45
C $ 100 15% $115

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

Measures

Can apply when using iterator functions which compute calculations row by row

Iterator functions can be identi ed by an X a er the function name i.e SUMX()

Syntax: SUMX(<table>, <expression>)

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

Measures

Can apply when using iterator functions which compute calculations row by row

Iterator functions can be identi ed by an X a er the function name i.e SUMX()

Syntax: SUMX(<table>, <expression>)

Item Price Tax Price_with_tax


A $ 20 25% $25
B $ 45 0% $45

INTRODUCTION TO DAX IN POWER BI


Introduction to Row Context
"The current row"

Measures

Can apply when using iterator functions which compute calculations row by row

Iterator functions can be identi ed by an X a er the function name i.e SUMX()

Syntax: SUMX(<table>, <expression>)

Item Price Tax Price_w_tax


A $ 20 25% $25
B $ 45 0% $45
Total - - $ 70
Example: SUMX(Sales, Sales[Price] + (Sales[Price] * Sales[Tax]))

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Filter context can be applied in several ways:

A ributes in a row/column

Via a slicer

Through the lter pane

In a calculated measure

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Example:

Color Quantity
Blue 1,250
Green 200
Black 4,000

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Example:

Color Quantity
Blue 1,250

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Example:

Color Quantity
Blue 1,250
Green 200
Black 4,000

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Example:

Socks Shoes T-shirt


Blue 200 800 250
Green 90 10 100
Black 2,000 800 1,200

INTRODUCTION TO DAX IN POWER BI


Introduction to Filter Context
Filter context is a set of lters that have been applied before the calculation is carried out.

Example:

Socks
Blue 200

INTRODUCTION TO DAX IN POWER BI


Calculate Function
Syntax: CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])
Expression: a measure or calculation to be evaluated. Must return a single value.

Filters:
Filters need to evaluate as a table

Filters should not clash with one another


Sales[City]="London" , Sales[Country] <> "United Kingdom"

CALCULATE() lters will always override lters from the visualization

Example: CALCULATE(SUM(Sales), Sales[Region]="EMEA")

INTRODUCTION TO DAX IN POWER BI


Let's practice!
I N T R O D U C T I O N TO DA X I N P OW E R B I
Creating DAX
Measures
I N T R O D U C T I O N TO DA X I N P OW E R B I

Jess Ahmet
Content Developer, DataCamp
Let's practice!
I N T R O D U C T I O N TO DA X I N P OW E R B I

You might also like