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

Chapter 4

This document discusses iterating functions in Power BI such as SUMX(), AVERAGEX(), and RANKX(). These functions allow calculations to be performed iteratively over each row of a table. Examples are provided of using SUMX() to calculate total costs by iterating over a table and summing sales minus profits at each row. RANKX() is used to rank regions by total costs. Filtering functions like FILTER() are also discussed to filter a table before an iterating calculation.

Uploaded by

rida
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)
5 views18 pages

Chapter 4

This document discusses iterating functions in Power BI such as SUMX(), AVERAGEX(), and RANKX(). These functions allow calculations to be performed iteratively over each row of a table. Examples are provided of using SUMX() to calculate total costs by iterating over a table and summing sales minus profits at each row. RANKX() is used to rank regions by total costs. Filtering functions like FILTER() are also discussed to filter a table before an iterating calculation.

Uploaded by

rida
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

Iterating functions

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

Maarten Van den Broeck


Content Developer at DataCamp
Iterating functions
Iterate over each row of a given table to perform an expression

SUMX(<table>, <expression>) AVERAGEX(<table>, <expression>)

X stands for eXpression

Allow for advanced calculations speci ed at each row

DAX FUNCTIONS IN POWER BI


Iterating functions: SUMX()
Calculated column example
Cost = Fact_Orders[Sales] - Fact_Orders[Profit]

Total Costs = SUM(Fact_Orders[Cost])

Sales Pro t Cost


$77.88 $3.89 $73.99
$22.72 $10.22 $12.50
... ... ...
Total Costs
$2,569

DAX FUNCTIONS IN POWER BI


Iterating functions: SUMX()
Calculated column example Iterating function example
Cost = Fact_Orders[Sales] - Fact_Orders[Profit] Total Costs SUMX =
SUMX(Fact_Orders,
Fact_Orders[Sales] - Fact_Orders[Profit])
Total Costs = SUM(Fact_Orders[Cost])

Total Costs SUMX


Sales Pro t Cost
$2,569
$77.88 $3.89 $73.99
$22.72 $10.22 $12.50
... ... ...
Total Costs
$2,569

DAX FUNCTIONS IN POWER BI


Filtering iterating functions
Use lter functions, such as FILTER(), to
return a ltered table

SUMX(
FILTER(
<table>,
<filter>),
<expression>)

Total Costs East SUMX =


SUMX(
FILTER(
Fact_Orders,
Fact_Orders[Region] = "East"),
Fact_Orders[Sales] - Fact_Orders[Profit])

DAX FUNCTIONS IN POWER BI


Filtering iterating functions
Use lter functions, such as FILTER(), to
return a ltered table

SUMX(
FILTER(
<table>,
<filter>), Total Costs East
Region Total Costs
<expression>)
SUMX
Central $501,239.89
Total Costs East SUMX =
East $678,781.24 $678,781.24
SUMX(
FILTER( South $391,721.91
Fact_Orders, West $725,457.82
Fact_Orders[Region] = "East"),
Fact_Orders[Sales] - Fact_Orders[Profit])
TOTAL $2,297,200.86 $678,781.24

DAX FUNCTIONS IN POWER BI


Iterating functions: RANKX()
RANKX(
<table>,
<expression>)

Rank regions by total costs

Total Costs RANKX =


RANKX(
ALL(Dim_Sales[Region]),
[Total Costs])

Use ALL() to evaluate all rows from the


dimension table

DAX FUNCTIONS IN POWER BI


Iterating functions: RANKX()
RANKX(
<table>,
<expression>)
Region Total Costs Total Costs RANKX
Rank regions by total costs
Central $725,457.82 1
Total Costs RANKX = East $678,781.24 2
RANKX( South $501,239.89 3
ALL(Dim_Sales[Region]),
West $391,721.91 4
[Total Costs])

Use ALL() to evaluate all rows from the


dimension table

DAX FUNCTIONS IN POWER BI


Operators in DAX
COMPARISON OPERATORS
Operator Meaning
= Equal to
== Strict equal to
> Greater than
< Smaller than
>= Greater than or equal to
<= Smaller than or equal to
<> Not equal to

DAX FUNCTIONS IN POWER BI


Operators in DAX
COMPARISON OPERATORS TEXT OPERATOR
Operator Meaning Operator Meaning Example
= Equal to Concatenates text [City]&", "&
&
values [State]
== Strict equal to
> Greater than
< Smaller than
>= Greater than or equal to
<= Smaller than or equal to
<> Not equal to

DAX FUNCTIONS IN POWER BI


Operators in DAX
COMPARISON OPERATORS TEXT OPERATOR
Operator Meaning Operator Meaning Example
= Equal to Concatenates text [City]&", "&
&
values [State]
== Strict equal to
> Greater than LOGICAL OPERATORS
Operator Meaning Example
< Smaller than
AND ([City] = "Bru") &&
>= Greater than or equal to &&
condition ([Return] = "Yes"))
<= Smaller than or equal to
OR ([City] = "Bru") ||
||
<> Not equal to condition ([Return] = "Yes"))

OR Product[Color] IN
IN { } condition {"Red", "Blue",
for each row "Gold"}

DAX FUNCTIONS IN POWER BI


Lesson[Knowledge]
IN {"Poor", "Great",
"Awesome!"}
DA X F U N C T I O N S I N P OW E R B I
Iterating functions in
Power BI
DA X F U N C T I O N S I N P OW E R B I

Maarten Van den Broeck


Content Developer at DataCamp
Let's practice!
DA X F U N C T I O N S I N P OW E R B I
Congratulations!
DA X F U N C T I O N S I N P OW E R B I

Carl Rosseel
Curriculum Manager
DAX stands for Data Analysis eXpressions
DAX formulas are used in: Context in DAX Formulas:

Measures Row context

Calculated columns Query context

Calculated tables Filter context

DAX FUNCTIONS IN POWER BI


DAX Toolbox
General: Data Modeling:

Implicit vs explicit measures CALENDAR()

Quick measures CALCULATE()

Variables: VAR RELATED()

FILTER()

CROSSFILTER()

DAX FUNCTIONS IN POWER BI


Enjoy iterating!
DA X F U N C T I O N S I N P OW E R B I

You might also like