Iterating functions

DAX Functions in Power BI

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 specified 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 Profit 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
Cost = Fact_Orders[Sales] - Fact_Orders[Profit]
Total Costs = SUM(Fact_Orders[Cost])
Sales Profit Cost
$77.88 $3.89 $73.99
$22.72 $10.22 $12.50
... ... ...
Total Costs
$2,569
Iterating function example
Total Costs SUMX = 
SUMX(Fact_Orders,
     Fact_Orders[Sales] - Fact_Orders[Profit])
Total Costs SUMX
$2,569
DAX Functions in Power BI

Filtering iterating functions

  • Use filter functions, such as FILTER(), to return a filtered 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 filter functions, such as FILTER(), to return a filtered table
SUMX(
    FILTER(
        <table>,
        <filter>),
    <expression>)
Total Costs East SUMX = 
SUMX(
    FILTER(
        Fact_Orders,
        Fact_Orders[Region] = "East"),
    Fact_Orders[Sales] - Fact_Orders[Profit])

$$ $$ $$ $$ $$ $$

Region Total Costs Total Costs East SUMX
Central $501,239.89
East $678,781.24 $678,781.24
South $391,721.91
West $725,457.82
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>)
  • 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

$$ $$ $$

Region Total Costs Total Costs RANKX
Central $725,457.82 1
East $678,781.24 2
South $501,239.89 3
West $391,721.91 4
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
Operator Meaning
= Equal to
== Strict equal to
> Greater than
< Smaller than
>= Greater than or equal to
<= Smaller than or equal to
<> Not equal to
Text operator
Operator Meaning Example
& Concatenates text values [City]&", "&[State]
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
Text operator
Operator Meaning Example
& Concatenates text values [City]&", "&[State]
Logical operators
Operator Meaning Example
&& AND condition ([City] = "Bru") && ([Return] = "Yes"))
|| OR condition ([City] = "Bru") || ([Return] = "Yes"))
IN { } OR condition for each row Product[Color] IN {"Red", "Blue", "Gold"}
DAX Functions in Power BI

Lesson[Knowledge] IN {"Poor", "Great", "Awesome!"}

DAX Functions in Power BI

Preparing Video For Download...