Context in DAX-formules

Introductie tot DAX in Power BI

Jess Ahmet

Content Developer, DataCamp

Introductie tot context

  • Maakt dynamische analyse mogelijk waarbij de uitkomst van een formule mee verandert met de geselecteerde data
  • Er zijn 3 soorten context: rij, filter en query
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"

Berekende kolom

  • Bevat waarden uit alle kolommen binnen de huidige rij
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"

Berekende kolom

  • Bevat waarden uit alle kolommen binnen de huidige rij
Item Prijs Belasting Prijs_met_belasting
A $ 20 25% $25
B $ 45 0% $45
C $ 100 15% $115
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"

Maten

  • Kunnen gelden bij gebruik van iteratorfuncties die rij-voor-rij rekenen
  • Iteratorfuncties herken je aan een X na de functienaam, bijv. SUMX()
  • Syntaxis: SUMX(<table>, <expression>)
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"

Maten

  • Kunnen gelden bij gebruik van iteratorfuncties die rij-voor-rij rekenen
  • Iteratorfuncties herken je aan een X na de functienaam, bijv. SUMX()
  • Syntaxis: SUMX(<table>, <expression>)
Item Prijs Belasting Prijs_met_belasting
A $ 20 25% $25
B $ 45 0% $45
Introductie tot DAX in Power BI

Introductie tot rijcontext

  • "De huidige rij"

Maten

  • Kunnen gelden bij gebruik van iteratorfuncties die rij-voor-rij rekenen
  • Iteratorfuncties herken je aan een X na de functienaam, bijv. SUMX()
  • Syntaxis: SUMX(<table>, <expression>)
Item Prijs Belasting Prijs_z_belast
A $ 20 25% $25
B $ 45 0% $45
Totaal - - $ 70
  • Voorbeeld: SUMX(Sales, Sales[Price] + (Sales[Price] * Sales[Tax]))
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Filtercontext kan op meerdere manieren worden toegepast:

  • Attributen in een rij/kolom
  • Via een slicer
  • Via het filtervenster
  • In een berekende maat
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Voorbeeld:

Kleur Aantal
Blauw 1.250
Groen 200
Zwart 4.000
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Voorbeeld:

Kleur Aantal
Blauw 1.250
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Voorbeeld:

Kleur Aantal
Blauw 1.250
Groen 200
Zwart 4.000
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Voorbeeld:

Sokken Schoenen T-shirt
Blauw 200 800 250
Groen 90 10 100
Zwart 2.000 800 1.200
Introductie tot DAX in Power BI

Introductie tot filtercontext

Filtercontext is een set filters die is toegepast vóór de berekening.

Voorbeeld:

Sokken
Blauw 200
Introductie tot DAX in Power BI

CALCULATE-functie

  • Syntaxis: CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])
    • Expressie: een maat of berekening om te evalueren. Moet één waarde teruggeven.
    • Filters:
      • Filters moeten evalueren tot een tabel
      • Filters mogen niet met elkaar in strijd zijn
        • Sales[City]="London", Sales[Country] <> "United Kingdom"
      • CALCULATE()-filters overschrijven altijd filters uit de visualisatie
  • Voorbeeld: CALCULATE(SUM(Sales), Sales[Region]="EMEA")
Introductie tot DAX in Power BI

Laten we oefenen!

Introductie tot DAX in Power BI

Preparing Video For Download...