SlideShare una empresa de Scribd logo
1 de 30
Intro to DAX Patterns
 Eric Bragas – MCP, PSM I
 DesignMind - Business Intelligence Consultant
Agenda
 DAX
 Data Analysis Expressions
 Notation
 Functions
 Evaluation Contexts
 Measure Patterns
 Calculated Column Patterns
Data Analysis Expressions (DAX)
 What is DAX?
 DAX is a language that allows us to write dynamic expressions for relataional
constructs, using familiar functions
 Powerful dynamic data analysis tool for relational data
 Expressions can traverse relationships!
 Available in PowerPivot, PowerBI, and SSAS Tabular
 Classic “Import Mode”
 What isn’t DAX?
 NOT a programming language
DAX Notation
Table
‘Table’
Column
‘Table’[Column]
Function
fn ( <arguments> )
Measure
Measure Name := SUM ( ‘Table’[Column] )
Calculated Column
Column Name = SUM ( ‘Table’[Column] )
Measures
 A measure is a formula/expression comprising functions applied to
columns and tables
 Reusable aggregation evaluated differently, depending on how you use it
 Measures can be nested
Functions
 Logical
 IF( logical test, <value if true>, <value if false> )
 SWITCH( <expression>, <value>, <result>, … ) – evaluates an expression against a list of values, and returns the result corresponding to the first matching value
 TRUE() – returns logical true
 Aggregate
 SUM( <column> ) – adds all the numbers in a column
 DIVIDE( <numerator>, <denominator>, [, <alternateresult>] ) – basic division; optional value returned
 Statistical
 MAX( <column> ) – returns the largest numeric value in a <column>
 MIN( <column> ) – returns the smallest value in a <column>
 Text
 BLANK() – returns a blank
 Filter
 FILTER(<table>, <filter>) – returns a table representing a subset of another table or expression
 ALL( <table> | <column>) – returns all the rows in a table, ignoring any filter context
 VALUES(<table or column>) – returns one column of the distinct values from the specified column or table
 CALCULATE( <expression>, <filter1>, <filter2>, … ) – evaluates an expression in a context that is modified by the specified filters
Functions (cont’d)
 Date and Time
 TODAY() – returns the current date
 NOW() – returns the current date and time in datetime format
 Time Intelligence*
 DATESBETWEEN(<dates>, <start date>, <end date>) – returns a table of <dates> starting with the <start date> and continues
until the <end date>.
 NEXTDAY(<dates>) – returns a table that contains a column with the next dates following each of the <dates> passed
 FIRSTDATE(<dates>) – returns the first date in the context of the specified column of dates
 LASTDATE(<dates>) – returns the last date in the context of the specified column of dates
 SAMEPERIODLASTYEAR(<dates>) – returns a table with a column of dates shifted one year back for each of the <dates> specified
 LASTNONBLANK( <column>, <expression> ) – returns last value in the <column> where the <expression> returns blank
 FIRSTNONBLANK( <column>, <expression> ) – returns the first value in the <column> where the <expression> returns blank
*Requires Date Table
Evaluation Contexts
 Evaluation Contexts:
 Filter Context
 Four types of filter context:
1. Row Selection
2. Column Selection
3. Slicer Selection
4. Filter Selection
 Defines the subset of data a measure is calculated using aka “Which rows are selected based on which attribute
values?”
 Applied before anything else
 Row Context
 All the columns in the Current Row
“DAX is simple, it’s not easy, but it’s
simple”
- Alberto Ferrari
Basic Evaluation Context - Demo
TotalSales = SUM ( Sales[SalesAmount] )
Anatomy of a Filter Context -
PivotTable
Rows
Slicer
Anatomy of a Filter Context - Chart
Filter
Slicer
Measure Patterns
BASIC
CUMULATIVE
YTD
YEAR OVER YEAR
SEMI-ADDITIVE
DISCONNECTED SLICERS
Basic Measures
 SUM( ‘Sales’[SalesAmount] )
 AVERAGE( ‘Inventory’[InventoryOnHand] )
 MIN( ‘Weather’[Temp] )
 MAX ( ‘Weather’[Temp] )
 Etc.
Basic Measure Demo – PowerPivot &
PowerBI
Asia Sales :=
CALCULATE ( [Total Sales],
Geography[ContinentName] = "Asia" )
Asia Sales :=
CALCULATE (
[Total Sales],
FILTER ( 'Geography',
Geography[ContinentName] = "Asia" )
)
Boolean
Table
Cumulative Total Measures
 Aggregates values of a column for the currently selected date and all previous dates within
the specified range
 Can be used to derive balances from transactions eg.
 Inventory Stock
 Balances
 Cumulative Balances
 Does not require use of Time Intelligence functions
Cumulative Measure Demo - PowerBI
Cumulative Energy Generated (Checked) =
IF (
MIN ( 'Date'[Date] ) <= MAX ( ‘Output’[Date], ALL ( ‘Output’ ) ) ,
CALCULATE (
SUM ( 'Output'[Energy Generated] ),
FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) )
)
)
Year-to-Date Total
 TOTALYTD function applies the expression for all data from the start of the year to the
currently selected date in the filter context
Year To Date =
TOTALYTD( <expression>, <dates> [, <filter>] [, <year end date>] )
Year-to-Date Total Demo - PowerBI
Total Energy Generated YTD =
TOTALYTD ( SUM ( 'Output'[Energy Generated] ), 'Date'[Date] )
Year Over Year
 Use time intelligence to calculate an aggregate for the same period last year
 “Last Year” measure is used to compare to “Current Year” measure, and/or to derive a
measure of the change year-over-year
Year-Over-Year Demo – PowerBI
Total Energy Generated Last Year =
CALCULATE ( [Total Energy Generated], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Semi-Additive Measures
 Snapshot Fact Table with balance values, such as Inventory or
Account Balances
 These scenarios disallow us from summing across time
 The solution is to sum across all attributes except for time by
filtering for only a single point in time (eg. last date in the period)
 Several functions allow you to adjust filter context to a single
point in time, within the original context period
 FIRSTDATE / LASTDATE
 FIRSTNONBLANK / LASTNONBLANK
 OPENING… / CLOSING…
Semi-Additive Measure Demo -
PowerPivot
Total On Hand Quantity LASTNONBLANK =
CALCULATE (
SUM ( Inventory[OnHandQuantity] ),
LASTNONBLANK ( 'Date'[Date],
CALCULATE ( SUM ( Inventory[OnHandQuantity] ) ) )
)
Disconnected Slicers
Allows you to use a slicer to modify measures
 Measure Switching
 Used to switch between a set of measure values in a container measure
Disconnected Slicers Demo - PowerBI
Setup Steps:
1. Create/identify your target measures (eg. [Energy Exported] & [Energy
Generated])
2. Create disconnected table to use in slicer selection
3. Create background “value selection measure” using MAX()
• Hide this!
4. Create SWITCH measure to use in visualizations
Calculated Column
Patterns
VALUE BINNING
Value Binning
 Used to group similar values, or to bin values for
analysis aka Histograms
 Can bin values based on equality, or inequality
comparisons with the SWITCH() function
 Use Cases:
 Age groups
 Product Groups
 Any kind of frequency distributions
Value Binning Demo - PowerBI
Inventory Age (bin) =
SWITCH (
TRUE (),
'Inventory'[DaysInStock] < 20, "0-20",
'Inventory'[DaysInStock] < 50, "21-50",
'Inventory'[DaysInStock] < 80, "51-80",
'Inventory'[DaysInStock] < 100, "81-100",
"101+"
)
Summary
 DAX is dynamic because you can write measures that correctly evaluate under
their current Evaluation Context
 Filter Context
 Row Context
 Functions are the building blocks of our measures and perform a myriad of
tasks eg. altering Context, aggregating, logical operations, time intelligence,
etc
 Time Intelligence functions require a Date table to operate
 Understanding Tabular Data Modeling will go a long way towards helping your
understanding of DAX
Thanks!

Más contenido relacionado

La actualidad más candente

Microsoft power bi
Microsoft power biMicrosoft power bi
Microsoft power bitechpro360
 
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau -  Data, Graphs, Filters, Dashboards and Advanced featuresLearning Tableau -  Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced featuresVenkata Reddy Konasani
 
Tableau Visual analytics complete deck 2
Tableau Visual analytics complete deck 2Tableau Visual analytics complete deck 2
Tableau Visual analytics complete deck 2Arun K
 
What is Power BI
What is Power BIWhat is Power BI
What is Power BINaseeba P P
 
Sql server 2019 new features
Sql server 2019 new featuresSql server 2019 new features
Sql server 2019 new featuresGeorge Walters
 
Introduction to Power BI a Business Intelligence Tool by Apurva Ramteke
Introduction to Power BI a Business Intelligence Tool by Apurva RamtekeIntroduction to Power BI a Business Intelligence Tool by Apurva Ramteke
Introduction to Power BI a Business Intelligence Tool by Apurva RamtekeApurva Ramteke
 
Introduction to Power BI and Data Visualization
Introduction to Power BI and Data VisualizationIntroduction to Power BI and Data Visualization
Introduction to Power BI and Data VisualizationSwapnil Jadhav
 
Self-Service Business Intelligence with Power BI
Self-Service Business Intelligence with Power BISelf-Service Business Intelligence with Power BI
Self-Service Business Intelligence with Power BITheresa Lubelski
 
Power BI Advance Modeling
Power BI Advance ModelingPower BI Advance Modeling
Power BI Advance ModelingCCG
 

La actualidad más candente (20)

Tableau
TableauTableau
Tableau
 
Dax & sql in power bi
Dax & sql in power biDax & sql in power bi
Dax & sql in power bi
 
Microsoft power bi
Microsoft power biMicrosoft power bi
Microsoft power bi
 
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau -  Data, Graphs, Filters, Dashboards and Advanced featuresLearning Tableau -  Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
 
Tableau Visual analytics complete deck 2
Tableau Visual analytics complete deck 2Tableau Visual analytics complete deck 2
Tableau Visual analytics complete deck 2
 
Power bi
Power biPower bi
Power bi
 
What is Power BI
What is Power BIWhat is Power BI
What is Power BI
 
Sql server 2019 new features
Sql server 2019 new featuresSql server 2019 new features
Sql server 2019 new features
 
Power BI visuals
Power BI visualsPower BI visuals
Power BI visuals
 
My tableau
My tableauMy tableau
My tableau
 
Power bi components
Power bi components Power bi components
Power bi components
 
Introduction to Power BI a Business Intelligence Tool by Apurva Ramteke
Introduction to Power BI a Business Intelligence Tool by Apurva RamtekeIntroduction to Power BI a Business Intelligence Tool by Apurva Ramteke
Introduction to Power BI a Business Intelligence Tool by Apurva Ramteke
 
Introduction to Power BI and Data Visualization
Introduction to Power BI and Data VisualizationIntroduction to Power BI and Data Visualization
Introduction to Power BI and Data Visualization
 
Self-Service Business Intelligence with Power BI
Self-Service Business Intelligence with Power BISelf-Service Business Intelligence with Power BI
Self-Service Business Intelligence with Power BI
 
Power BI Advance Modeling
Power BI Advance ModelingPower BI Advance Modeling
Power BI Advance Modeling
 
Data Modeling with Power BI
Data Modeling with Power BIData Modeling with Power BI
Data Modeling with Power BI
 
Power BI Overview
Power BI Overview Power BI Overview
Power BI Overview
 
SSAS Tabular model importance and uses
SSAS  Tabular model importance and usesSSAS  Tabular model importance and uses
SSAS Tabular model importance and uses
 
Power query
Power queryPower query
Power query
 
Power bi overview
Power bi overview Power bi overview
Power bi overview
 

Similar a Intro to DAX Patterns

Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Julian Hyde
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answerRaajTech
 
Funções DAX.pdf
Funções DAX.pdfFunções DAX.pdf
Funções DAX.pdfJoao Vaz
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence PortfolioChris Seebacher
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolioguest3ea163
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineeringJulian Hyde
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to daxIke Ellis
 
2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power Tools2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power ToolsDavid Onder
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfPBIMINERADC
 
U-SQL Query Execution and Performance Tuning
U-SQL Query Execution and Performance TuningU-SQL Query Execution and Performance Tuning
U-SQL Query Execution and Performance TuningMichael Rys
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and OperatorsMohan Kumar.R
 
1.2 Zep Excel.pptx
1.2 Zep Excel.pptx1.2 Zep Excel.pptx
1.2 Zep Excel.pptxPizzaM
 

Similar a Intro to DAX Patterns (20)

Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
 
Getting power bi
Getting power biGetting power bi
Getting power bi
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Funções DAX.pdf
Funções DAX.pdfFunções DAX.pdf
Funções DAX.pdf
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power Tools2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power Tools
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdf
 
Dax en
Dax enDax en
Dax en
 
Phoenix h basemeetup
Phoenix h basemeetupPhoenix h basemeetup
Phoenix h basemeetup
 
Mastering Excel Formulas and Functions
Mastering Excel Formulas and FunctionsMastering Excel Formulas and Functions
Mastering Excel Formulas and Functions
 
U-SQL Query Execution and Performance Tuning
U-SQL Query Execution and Performance TuningU-SQL Query Execution and Performance Tuning
U-SQL Query Execution and Performance Tuning
 
Chapter.08
Chapter.08Chapter.08
Chapter.08
 
Kofi Nyanteng Introduction excel modelling
Kofi Nyanteng Introduction excel modellingKofi Nyanteng Introduction excel modelling
Kofi Nyanteng Introduction excel modelling
 
Kofi Nyanteng Introduction excel modelling
Kofi Nyanteng Introduction excel modellingKofi Nyanteng Introduction excel modelling
Kofi Nyanteng Introduction excel modelling
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
1.2 Zep Excel.pptx
1.2 Zep Excel.pptx1.2 Zep Excel.pptx
1.2 Zep Excel.pptx
 

Último

➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...amitlee9823
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...karishmasinghjnh
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachBoston Institute of Analytics
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...amitlee9823
 
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...gajnagarg
 
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...amitlee9823
 

Último (20)

➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
 
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 

Intro to DAX Patterns

  • 1. Intro to DAX Patterns
  • 2.  Eric Bragas – MCP, PSM I  DesignMind - Business Intelligence Consultant
  • 3. Agenda  DAX  Data Analysis Expressions  Notation  Functions  Evaluation Contexts  Measure Patterns  Calculated Column Patterns
  • 4. Data Analysis Expressions (DAX)  What is DAX?  DAX is a language that allows us to write dynamic expressions for relataional constructs, using familiar functions  Powerful dynamic data analysis tool for relational data  Expressions can traverse relationships!  Available in PowerPivot, PowerBI, and SSAS Tabular  Classic “Import Mode”  What isn’t DAX?  NOT a programming language
  • 5. DAX Notation Table ‘Table’ Column ‘Table’[Column] Function fn ( <arguments> ) Measure Measure Name := SUM ( ‘Table’[Column] ) Calculated Column Column Name = SUM ( ‘Table’[Column] )
  • 6. Measures  A measure is a formula/expression comprising functions applied to columns and tables  Reusable aggregation evaluated differently, depending on how you use it  Measures can be nested
  • 7. Functions  Logical  IF( logical test, <value if true>, <value if false> )  SWITCH( <expression>, <value>, <result>, … ) – evaluates an expression against a list of values, and returns the result corresponding to the first matching value  TRUE() – returns logical true  Aggregate  SUM( <column> ) – adds all the numbers in a column  DIVIDE( <numerator>, <denominator>, [, <alternateresult>] ) – basic division; optional value returned  Statistical  MAX( <column> ) – returns the largest numeric value in a <column>  MIN( <column> ) – returns the smallest value in a <column>  Text  BLANK() – returns a blank  Filter  FILTER(<table>, <filter>) – returns a table representing a subset of another table or expression  ALL( <table> | <column>) – returns all the rows in a table, ignoring any filter context  VALUES(<table or column>) – returns one column of the distinct values from the specified column or table  CALCULATE( <expression>, <filter1>, <filter2>, … ) – evaluates an expression in a context that is modified by the specified filters
  • 8. Functions (cont’d)  Date and Time  TODAY() – returns the current date  NOW() – returns the current date and time in datetime format  Time Intelligence*  DATESBETWEEN(<dates>, <start date>, <end date>) – returns a table of <dates> starting with the <start date> and continues until the <end date>.  NEXTDAY(<dates>) – returns a table that contains a column with the next dates following each of the <dates> passed  FIRSTDATE(<dates>) – returns the first date in the context of the specified column of dates  LASTDATE(<dates>) – returns the last date in the context of the specified column of dates  SAMEPERIODLASTYEAR(<dates>) – returns a table with a column of dates shifted one year back for each of the <dates> specified  LASTNONBLANK( <column>, <expression> ) – returns last value in the <column> where the <expression> returns blank  FIRSTNONBLANK( <column>, <expression> ) – returns the first value in the <column> where the <expression> returns blank *Requires Date Table
  • 9. Evaluation Contexts  Evaluation Contexts:  Filter Context  Four types of filter context: 1. Row Selection 2. Column Selection 3. Slicer Selection 4. Filter Selection  Defines the subset of data a measure is calculated using aka “Which rows are selected based on which attribute values?”  Applied before anything else  Row Context  All the columns in the Current Row “DAX is simple, it’s not easy, but it’s simple” - Alberto Ferrari
  • 10. Basic Evaluation Context - Demo TotalSales = SUM ( Sales[SalesAmount] )
  • 11. Anatomy of a Filter Context - PivotTable Rows Slicer
  • 12. Anatomy of a Filter Context - Chart Filter Slicer
  • 13. Measure Patterns BASIC CUMULATIVE YTD YEAR OVER YEAR SEMI-ADDITIVE DISCONNECTED SLICERS
  • 14. Basic Measures  SUM( ‘Sales’[SalesAmount] )  AVERAGE( ‘Inventory’[InventoryOnHand] )  MIN( ‘Weather’[Temp] )  MAX ( ‘Weather’[Temp] )  Etc.
  • 15. Basic Measure Demo – PowerPivot & PowerBI Asia Sales := CALCULATE ( [Total Sales], Geography[ContinentName] = "Asia" ) Asia Sales := CALCULATE ( [Total Sales], FILTER ( 'Geography', Geography[ContinentName] = "Asia" ) ) Boolean Table
  • 16. Cumulative Total Measures  Aggregates values of a column for the currently selected date and all previous dates within the specified range  Can be used to derive balances from transactions eg.  Inventory Stock  Balances  Cumulative Balances  Does not require use of Time Intelligence functions
  • 17. Cumulative Measure Demo - PowerBI Cumulative Energy Generated (Checked) = IF ( MIN ( 'Date'[Date] ) <= MAX ( ‘Output’[Date], ALL ( ‘Output’ ) ) , CALCULATE ( SUM ( 'Output'[Energy Generated] ), FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ) ) )
  • 18. Year-to-Date Total  TOTALYTD function applies the expression for all data from the start of the year to the currently selected date in the filter context Year To Date = TOTALYTD( <expression>, <dates> [, <filter>] [, <year end date>] )
  • 19. Year-to-Date Total Demo - PowerBI Total Energy Generated YTD = TOTALYTD ( SUM ( 'Output'[Energy Generated] ), 'Date'[Date] )
  • 20. Year Over Year  Use time intelligence to calculate an aggregate for the same period last year  “Last Year” measure is used to compare to “Current Year” measure, and/or to derive a measure of the change year-over-year
  • 21. Year-Over-Year Demo – PowerBI Total Energy Generated Last Year = CALCULATE ( [Total Energy Generated], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
  • 22. Semi-Additive Measures  Snapshot Fact Table with balance values, such as Inventory or Account Balances  These scenarios disallow us from summing across time  The solution is to sum across all attributes except for time by filtering for only a single point in time (eg. last date in the period)  Several functions allow you to adjust filter context to a single point in time, within the original context period  FIRSTDATE / LASTDATE  FIRSTNONBLANK / LASTNONBLANK  OPENING… / CLOSING…
  • 23. Semi-Additive Measure Demo - PowerPivot Total On Hand Quantity LASTNONBLANK = CALCULATE ( SUM ( Inventory[OnHandQuantity] ), LASTNONBLANK ( 'Date'[Date], CALCULATE ( SUM ( Inventory[OnHandQuantity] ) ) ) )
  • 24. Disconnected Slicers Allows you to use a slicer to modify measures  Measure Switching  Used to switch between a set of measure values in a container measure
  • 25. Disconnected Slicers Demo - PowerBI Setup Steps: 1. Create/identify your target measures (eg. [Energy Exported] & [Energy Generated]) 2. Create disconnected table to use in slicer selection 3. Create background “value selection measure” using MAX() • Hide this! 4. Create SWITCH measure to use in visualizations
  • 27. Value Binning  Used to group similar values, or to bin values for analysis aka Histograms  Can bin values based on equality, or inequality comparisons with the SWITCH() function  Use Cases:  Age groups  Product Groups  Any kind of frequency distributions
  • 28. Value Binning Demo - PowerBI Inventory Age (bin) = SWITCH ( TRUE (), 'Inventory'[DaysInStock] < 20, "0-20", 'Inventory'[DaysInStock] < 50, "21-50", 'Inventory'[DaysInStock] < 80, "51-80", 'Inventory'[DaysInStock] < 100, "81-100", "101+" )
  • 29. Summary  DAX is dynamic because you can write measures that correctly evaluate under their current Evaluation Context  Filter Context  Row Context  Functions are the building blocks of our measures and perform a myriad of tasks eg. altering Context, aggregating, logical operations, time intelligence, etc  Time Intelligence functions require a Date table to operate  Understanding Tabular Data Modeling will go a long way towards helping your understanding of DAX

Notas del editor

  1. How many people have worked with Excel formulas? How many people have worked with PowerPivot?
  2. Story: Introduced to data by my Dad (scary DBA types) Began learning Relational Databases and attending SQL Saturday’s Indexing internals – Kalen Delaney T-SQL – Kevin Boles Merge Operators – Ami Levin Developer/DBA Really interested in BI (DW) Realized my data analysis tool belt was lacking So I decided to present on DAX
  3. Introduction to DAX Introduction to Measure and Analysis concepts Introduction to Evaluation Context Introduction to Measure and Calculated Column Patterns (which happen to often alter Evaluation Context)
  4. “DAX is a language that allows us to write dynamic expressions for relational constructs, using familiar functions” What is DAX? though it shares functions with Excel formula language, it differs by being intended for analysis of relational data
  5. There are some minor differences between PowerBI and PowerPivot eg. the colon
  6. Review CALCULATE in detail
  7. We need to understand Evaluation Context so that we can begin altering it. Filter Context Row Context Iterator Functions… not going to cover these much
  8. Point out the parts of the measure syntax What sales does the measure sum? Sum of all sales Why do the numbers change when we add color to the rows? The measure still evaluates sum of all sales However now, it is operating under the context of a color, and can only sum sales for that color! The value of a formula depends on it’s context. What we put in a context filters the subset of data we can measure, and so we call it the Filter Context!
  9. Diagram View: Already setup data model ( imported tables ) Created relationships between tables; DAX can traverse these without an explicit join Data Grid: Created simple SUM Shows SUM of all Sales Add Continent to Rows; filter context changes Add ‘Product’[Product Class] to Columns; filter context changes Diagram View: Create SUM that adds Asia sales | CALCULATE ( SUM ( ‘Sales’[SalesAmount] ) [Total Sales], ‘Geography’[Continent] = “Asia” ) Show results Create SUM that only adds Asia sales; returns blank all others | CALCULATE ( [Total Sales], FILTER ( ‘Geography’, ‘Geography’[Continent] = “Asia” ) )
  10. Demo: show basic measures in PowerPivot then PowerBI Demo: CALCULATE with a simple argument against Geography
  11. To avoid calculating values for dates greater than the max date in the transactions table (‘Output’), add a check that the minimum ‘Date’[DateKey] <= maximum ‘Transactions’[Date] Can also replace the MAX(‘Transactions’[Date]) check with TODAY(), however this is not always valid as it assumes all data is “current”
  12. Paste to exclude future dates: IF ( MIN ( 'Date'[Date] ) <= CALCULATE ( MAX ( 'Output'[Date] ), ALL ( 'Output' ) ),
  13. TOTALYTD function applies the expression for all data from the start of the year to the currently selected date in the filter context
  14. TOTALYTD function applies the expression for all data from the start of the year to the currently selected date in the filter context
  15. Paste to exclude future dates: IF ( MIN ( 'Date'[Date] ) <= CALCULATE ( MAX ( 'Output'[Date] ), ALL ( 'Output' ) ), DIVIDE ( [Sales] – [Last Year Sales], [Last Year Sales] )
  16. Paste to exclude future dates: IF ( MIN ( 'Date'[Date] ) <= CALCULATE ( MAX ( 'Output'[Date] ), ALL ( 'Output' ) ),
  17. How can we alter the filter context to only a single point in time? Using CALCULATE to override the context First and Last Date will not return values - if the date a period ends on has no data * Time intelligence functions in PowerBI require the DateKey to be a Date data type * The expression argument in LASTNONBLANK must be wrapped in a CALCULATE, otherwise it will use the original filter context, and not the LASTNONBLANK column argument context
  18. Setup Target Measures ( [Energy Export] & [Energy Generated] ) User defined table ( disconnected ) Value selection measure ( MAX ( ‘disconnected_table’[id] ) ) Switching measure
  19. Demo: Inventory Aging
  20. Demo: Inventory Aging In this case, I am using the Inventory Semi-Additive Measure as well