Sei sulla pagina 1di 18

BR028

Session Agenda
 DAX definition
 DAX Calculated columns
 DAX measures
 The CALCULATE() Function
 Relationships
 Quick Measures
What is DAX?

 Data Analysis eXpressions


 Function language used to define calculations in Power BI
 Came from the Excel world, so
 matches syntax
 similar function behavior
 The main difference is Power BI is a Database, Excel is not.
What’s it for?
 Creating
 Calculated columns
 Calculated measures

 Can also be used as a Query Language*

*Out of scope for this session


Calculated columns
 Can be used to add columns to tables you’ve already
loaded from your data source
 Calculated columns always
 have a single formula for each column
 operate row-by-row in your table
 Only ever refresh on data load
 Useful for creating new columns needed for your Power BI
visuals
 E.g. You have “day of week”, but want a “weekday/weekend” column
Demo
 Adding two columns together
 Concatenating two columns
Calculated measures
 Calculations that you can put into the values area of a visual
 They are stored inside a table, but they don’t really care
 Always filtered based on where you’re using them in a visual
 They are calculated “on the fly” so don’t use up much space
 Useful for:
 Everything!
 Totals, ratio to parent, ranks, difference from average… all sorts
 Are less intuitive for Excel users than calculated columns, that’s
why you need to learn them
Demo
 Sum a column
 Use it in a visual
 Filter the visual by different things and see how it reacts
The CALCULATE() Function
 This is the secret sauce…

“evaluates an expression in a context that is modified by the


specified filters you specify in the function”

or

“Tell me the answer to this calculation, but only where…”


What is this?
CALCULATE
Examples
=CALCULATE(
[Total Sales],
[Country]=“USA”
)

=CALCULATE(
[Number of new customers],
[Year]=“2017”,
[Gender]=“M”
)
A little more complex
Difference from today =
[Unit Sales] –
CALCULATE(
[Unit Sales],
Sales[OrderDate]=DATE(2017,05,03)
)
Relationships
 The ideal table design for Power BI is exactly opposite to
what you have learnt in Excel
 Excel
 Flatten everything into a single table using VLOOKUP or
INDEX/MATCH
 Power BI
 Keep the tables separate as Lookup Tables and Data Tables
Demo
 Look at the alternate design
 Everything still works
Quick Measures
 New feature released in April 2017
 Kinda like the menus in Get Data
 Allows you to pick from a menu
 It actually creates a real measure
 You can learn by editing the measure after it is created
Demo
https://aka.ms/mdis17schedule

Potrebbero piacerti anche