SlideShare a Scribd company logo
Introduction to DAX
Ike Ellis, MVP
Crafting Bytes
@ike_ellis
ike@craftingbytes.com
www.ikeellis.com
Do you know DAX?
What do you need to know in order to say yes, I know DAX?
1. You need to know these functions:
• SUM, AVERAGE, MIN, MAX
• COUNT, COUNTROWS
• CALCULATE
• FILTER
• IF/VARIABLES
2. You need to know about Contexts
• Row Context
• Filter Context
3. Some other things:
• Formatting
• White space
• Time intelligence
• Best Practices
• X vs nonX functions(SUM vs SUMX)
• DAX Studio
• Basic Troubleshooting
So how will you learn it?
• Go in order:
• This slide deck
• This Power BI Project
• Practice, practice, practice
And how will you use it?
• Works in Excel
• Works in Power BI
• Works in SQL Server Analysis Services (SSAS) Tabular
This presentation
• Simplifies the complexity
• Might not tell you the whole truth for the sake of simplicity
• Is not seeking to be comprehensive, but instead, seeks to allow you to
answer the question, yes, I know DAX in that job interview
Your first DAX expression
• Check Power BI Desktop tab “Your First DAX Expression”
• It’s a calculated column called Order Line Total
• Meant to add a column to every record in a table.
Order Line Total = 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice]
Your Second DAX Expression
• Check Power BI Desktop tab “Your Second DAX Expression”
• This is a measure
• Meant to perform an aggregation that we can slice & dice
Total Sales = SUM('Sales OrderDetails'[Order Line Total])
How can we verify this?
select sum(Sales.OrderDetails.unitprice * Sales.OrderDetails.qty)
from sales.OrderDetails
DAX Expression Breakdown
Name the
measure.
You’ll use
that in the
visualization
Built in DAX formula
Table name
Column nameEquals sign separates
expression name from
expression formula
Total Sales = SUM('Sales OrderDetails'[Order Line Total])
All kinds of easy to use DAX formulas that you can learn
quickly
• SUM
• AVERAGE
• MIN
• MAX
• COUNT
• COUNTROWS
• DATEDIFF
• DATEADD
• Look at tab “Easy DAX built-in formulas”
• Look under the Orders table for the calculated column “Days to Ship”
• Look under Orders table for measure “Average Days to Ship
Days To Ship = DATEDIFF('Sales Orders'[orderdate], 'Sales Orders'[shippeddate],DAY)
Play again: AVERAGE and DATEDIFF
Average Days to Ship = AVERAGE('Sales Orders'[Days To Ship])
Your Third DAX expression: Calculated Table
• Look at the Dates table. It was built with a DAX expression
• Created a Dates table with a date per day between the specified
range
• Also created a Dates hierarchy
Dates = CALENDAR("1/1/2000", "12/31/2016")
Now on to Contexts!
• Two different contexts:
• Row Context
• Filter Context
Row Context
• We already know how this works! We’ve been using it for all of our calculated
columns. Let’s revisit our first DAX Expression
• Notice we expect a value per row in a table
• This runs at import and gets stored
• Might increase file size
Order Line Total = 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice]
Filter Context
• Easy to show with measures
• Look at Filter Context 1, 2, 3 in the Power BI Desktop file (PBIX).
Filter Context 1
• We see it filtered by year and optionally by product category
• The measure is only defined once, and the DAX engine takes care of doing
the calculations on the fly
• The calculations are not stored, but created and retrieved at query time
Filter Context 2
Total Sales by year and with a page filter.
Filter Context 3
• Visuals can impact each other and change context
Now that we understand context, we can answer
this: Measures vs Calculated Columns
Measures Calculated Columns
Different functions Uses Row Contex
Doesn’t take up space Mostly text
Less space Executes at the point data is read into the model and
saved (value is static)
Filter Context
Executed at the time it is used
CALCULATE: Breaking out of the filter context
Beverages Total Sales = CALCULATE
(
SUM('Sales OrderDetails'[Order Line Total])
, 'Production Categories'[categoryname] = "Beverages"
)
AGGREGATION
FILTER
Look at the tab CALCULATE
FILTER
Number of Orders = COUNT('Sales Orders'[orderid])
Number of US Orders = CALCULATE
(
COUNT
(
'Sales OrderDetails'[orderid]
)
, FILTER
(
'Sales Customers'
, 'Sales Customers'[country] = "USA"
)
)
VARIABLES & RETURN
Total Sales For Customers with Minimum Order Count =
VAR MinimumOrderCount = 5
VAR CustomersWithMinimumOrders = CALCULATE
(
sum('Sales OrderDetails'[Order Line Total])
, FILTER('Sales Customers', [Number of Orders] > MinimumOrderCount)
)
RETURN CustomersWithMinimumOrders
Variables
VAR myVar = 1
Data Type Variable
Name
Variable
Value
RETURN myVar + 25
Expressions must use RETURN to return a value
Debugging using variables
• RETURN does not need to return the last variable
• In a multi-step formula, you can return an earlier value to
troubleshoot it
• Simplifies the reading of code, rather than endlessly nesting values
over and over again.
Time Intelligence: TOTALYTD
YTD Total Sales = TOTALYTD
(
SUM('Sales OrderDetails'[Order Line Total])
, Dates[Date].[Date]
)
Time Intelligence: PREVIOUSMONTH
Total Sales Previous Month = CALCULATE
(
sum('Sales OrderDetails'[Order Line Total])
, PREVIOUSMONTH(Dates[Date])
)
X vs nonX functions(SUM vs SUMX)
• SUM is an aggregator function. It works like a measure, calculating
based on the current filter context.
• SUMX is an iterator function. It works row by row. SUMX has
awareness of rows in a table, hince can reference the intersection of
each row with any columns in the table.
SUM vs SUMX Example
Total Sales SUMX = SUMX(
'Sales OrderDetails'
, 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice]
)
Total Sales = SUM('Sales OrderDetails'[Order Line Total])
Best Practice: Organize your code
• Keep measures together
• Organize them by type
• Simple aggregation
• Time variance
• Ratios and differences
• Business-specific calculations
Best Practice: Naming Columns & Measures
• Feel free to use spaces
• Avoid acronyms
• Make names terse, but descriptive
• Makes Q & A easier to use
• In formulas, reference table names for calculated columns and do not
reference table names for measures, so you’ll know the difference
Best Practice: Formatting
• DAX Expressions can have lots of parentheses and square brackets
• Please use white space to control this
• Here’s an example of a properly formatted calculated column
Days To Ship = DATEDIFF
(
'Sales Orders'[orderdate]
, 'Sales Orders'[shippeddate]
, DAY
)
Basic Troubleshooting
• A lot of things can go wrong, but the problem is usually one of two things:
1. A relationship is misconfigured or the data is wrong in the model.
2. Wrong data type
Data types
• Numeric
• String
• Bool
• DateTime
• If a function is expecting a numeric, but gets a string, it won’t work.
Clean up the model and watch it start working.
• Uses less space and memory with your model
• Improves performance
Relationships
Manipulating the relationships
Total Sales By Ship Year = CALCULATE
(
SUM('Sales OrderDetails'[Order Line Total])
, USERELATIONSHIP('Sales Orders'[shippeddate], Dates[Date])
)
Only one active relationship at a time
DAX Studio
• Parses
• Formats
• Shows execution plan
• Connects to SSAS Tabular or
Power BI Desktop
Other Resources
Contact Me!
http://www.craftingbytes.com
http://blog.ikeellis.com
http://www.ikeellis.com
YouTube
http://www.youtube.com/user/IkeEllisData
San Diego Tech Immersion Group
http://www.sdtig.com
Twitter: @ike_ellis
619.922.9801
ike@craftingbytes.com

More Related Content

What's hot

DAX and Power BI Training - 001 Overview
DAX and Power BI Training -  001 OverviewDAX and Power BI Training -  001 Overview
DAX and Power BI Training - 001 Overview
Will Harvey
 
Power BI Advance Modeling
Power BI Advance ModelingPower BI Advance Modeling
Power BI Advance Modeling
CCG
 
Dax & sql in power bi
Dax & sql in power biDax & sql in power bi
Dax & sql in power bi
Berkovich Consulting
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
Ike Ellis
 
Power BI vs Tableau
Power BI vs TableauPower BI vs Tableau
Power BI vs Tableau
Don Hyun
 
Power bi
Power biPower bi
Power bi
vishal choudhary
 
Power BI: From the Basics
Power BI: From the BasicsPower BI: From the Basics
Power BI: From the Basics
Nikkia Carter
 
Five Things I Wish I Knew the First Day I Used Tableau
Five Things I Wish I Knew the First Day I Used TableauFive Things I Wish I Knew the First Day I Used Tableau
Five Things I Wish I Knew the First Day I Used TableauRyan Sleeper
 
Microsoft Power BI | Brief Introduction | PPT
Microsoft Power BI | Brief Introduction | PPTMicrosoft Power BI | Brief Introduction | PPT
Microsoft Power BI | Brief Introduction | PPT
Sophia Smith
 
Data Modeling with Power BI
Data Modeling with Power BIData Modeling with Power BI
Data Modeling with Power BI
Raul Martin Sarachaga Diaz
 
Understanding Power BI Data Model
Understanding Power BI Data ModelUnderstanding Power BI Data Model
Understanding Power BI Data Model
HARIHARAN R
 
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
Edureka!
 
Calculated Fields in Tableau
Calculated Fields in TableauCalculated Fields in Tableau
Calculated Fields in Tableau
Kanika Nagpal
 
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
Swapnil Jadhav
 
Skillshare - Creating Excel Dashboards
Skillshare - Creating Excel DashboardsSkillshare - Creating Excel Dashboards
Skillshare - Creating Excel Dashboards
School of Data
 
DAX and Power BI Training - 004 Power Query
DAX and Power BI Training - 004 Power QueryDAX and Power BI Training - 004 Power Query
DAX and Power BI Training - 004 Power Query
Will Harvey
 
Power pivot intro
Power pivot introPower pivot intro
Power pivot intro
asantaballa
 
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
Venkata Reddy Konasani
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
SSAS Tabular model importance and uses
SSAS  Tabular model importance and usesSSAS  Tabular model importance and uses
SSAS Tabular model importance and uses
Lakshmi Prasanna Kottagorla
 

What's hot (20)

DAX and Power BI Training - 001 Overview
DAX and Power BI Training -  001 OverviewDAX and Power BI Training -  001 Overview
DAX and Power BI Training - 001 Overview
 
Power BI Advance Modeling
Power BI Advance ModelingPower BI Advance Modeling
Power BI Advance Modeling
 
Dax & sql in power bi
Dax & sql in power biDax & sql in power bi
Dax & sql in power bi
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
Power BI vs Tableau
Power BI vs TableauPower BI vs Tableau
Power BI vs Tableau
 
Power bi
Power biPower bi
Power bi
 
Power BI: From the Basics
Power BI: From the BasicsPower BI: From the Basics
Power BI: From the Basics
 
Five Things I Wish I Knew the First Day I Used Tableau
Five Things I Wish I Knew the First Day I Used TableauFive Things I Wish I Knew the First Day I Used Tableau
Five Things I Wish I Knew the First Day I Used Tableau
 
Microsoft Power BI | Brief Introduction | PPT
Microsoft Power BI | Brief Introduction | PPTMicrosoft Power BI | Brief Introduction | PPT
Microsoft Power BI | Brief Introduction | PPT
 
Data Modeling with Power BI
Data Modeling with Power BIData Modeling with Power BI
Data Modeling with Power BI
 
Understanding Power BI Data Model
Understanding Power BI Data ModelUnderstanding Power BI Data Model
Understanding Power BI Data Model
 
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
Power BI Interview Questions and Answers | Power BI Certification | Power BI ...
 
Calculated Fields in Tableau
Calculated Fields in TableauCalculated Fields in Tableau
Calculated Fields in Tableau
 
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
 
Skillshare - Creating Excel Dashboards
Skillshare - Creating Excel DashboardsSkillshare - Creating Excel Dashboards
Skillshare - Creating Excel Dashboards
 
DAX and Power BI Training - 004 Power Query
DAX and Power BI Training - 004 Power QueryDAX and Power BI Training - 004 Power Query
DAX and Power BI Training - 004 Power Query
 
Power pivot intro
Power pivot introPower pivot intro
Power pivot intro
 
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
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SSAS Tabular model importance and uses
SSAS  Tabular model importance and usesSSAS  Tabular model importance and uses
SSAS Tabular model importance and uses
 

Similar to Introduction to DAX

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence PortfolioChris Seebacher
 
Introduction-to-DAX-2017-01-12.pptx
Introduction-to-DAX-2017-01-12.pptxIntroduction-to-DAX-2017-01-12.pptx
Introduction-to-DAX-2017-01-12.pptx
Kishor kumar M
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
Sayed Ahmed
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
Sayed Ahmed
 
Getting power bi
Getting power biGetting power bi
Getting power bi
Umakant Bhardwaj
 
IT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptxIT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptx
ReneeClintGortifacio
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
guest3ea163
 
Dimensional model | | Fact Tables | | Types
Dimensional model | | Fact Tables | | TypesDimensional model | | Fact Tables | | Types
Dimensional model | | Fact Tables | | Types
umair saeed
 
Basics+of+Datawarehousing
Basics+of+DatawarehousingBasics+of+Datawarehousing
Basics+of+Datawarehousingtheextraaedge
 
Introduction to MS Excel
Introduction to MS ExcelIntroduction to MS Excel
Introduction to MS Excel
Tarek Dib
 
Excel tips
Excel tipsExcel tips
Excel tips
laxmiraj01
 
Excel Tips 101
Excel Tips 101Excel Tips 101
Excel Tips 101
Andre Pereira
 
Excel Tips.pptx
Excel Tips.pptxExcel Tips.pptx
Excel Tips.pptx
SumitPaul80
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
Ramachandram Jangili
 
Excel tips%20simple%20tax%20india%20dot%20org
Excel tips%20simple%20tax%20india%20dot%20orgExcel tips%20simple%20tax%20india%20dot%20org
Excel tips%20simple%20tax%20india%20dot%20orgSeshasalam Murugesan
 
35 excel tips
35 excel tips35 excel tips
35 excel tipsumar farooq
 
Excel tips
Excel tipsExcel tips
Excel tips
MOHAMMAD ATIF ALI
 
BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2
Kelvin Chan
 

Similar to Introduction to DAX (20)

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Introduction-to-DAX-2017-01-12.pptx
Introduction-to-DAX-2017-01-12.pptxIntroduction-to-DAX-2017-01-12.pptx
Introduction-to-DAX-2017-01-12.pptx
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
 
Getting power bi
Getting power biGetting power bi
Getting power bi
 
IT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptxIT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptx
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Dimensional model | | Fact Tables | | Types
Dimensional model | | Fact Tables | | TypesDimensional model | | Fact Tables | | Types
Dimensional model | | Fact Tables | | Types
 
Basics+of+Datawarehousing
Basics+of+DatawarehousingBasics+of+Datawarehousing
Basics+of+Datawarehousing
 
Introduction to MS Excel
Introduction to MS ExcelIntroduction to MS Excel
Introduction to MS Excel
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Excel Tips 101
Excel Tips 101Excel Tips 101
Excel Tips 101
 
Excel Tips.pptx
Excel Tips.pptxExcel Tips.pptx
Excel Tips.pptx
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
 
Excel tips%20simple%20tax%20india%20dot%20org
Excel tips%20simple%20tax%20india%20dot%20orgExcel tips%20simple%20tax%20india%20dot%20org
Excel tips%20simple%20tax%20india%20dot%20org
 
35 excel tips
35 excel tips35 excel tips
35 excel tips
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Excel tips
Excel tipsExcel tips
Excel tips
 
BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2
 

More from Ike Ellis

Storytelling with Data with Power BI
Storytelling with Data with Power BIStorytelling with Data with Power BI
Storytelling with Data with Power BI
Ike Ellis
 
Storytelling with Data with Power BI.pptx
Storytelling with Data with Power BI.pptxStorytelling with Data with Power BI.pptx
Storytelling with Data with Power BI.pptx
Ike Ellis
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
Ike Ellis
 
Data Modeling on Azure for Analytics
Data Modeling on Azure for AnalyticsData Modeling on Azure for Analytics
Data Modeling on Azure for Analytics
Ike Ellis
 
Migrate a successful transactional database to azure
Migrate a successful transactional database to azureMigrate a successful transactional database to azure
Migrate a successful transactional database to azure
Ike Ellis
 
Data modeling trends for analytics
Data modeling trends for analyticsData modeling trends for analytics
Data modeling trends for analytics
Ike Ellis
 
Data modeling trends for Analytics
Data modeling trends for AnalyticsData modeling trends for Analytics
Data modeling trends for Analytics
Ike Ellis
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applications
Ike Ellis
 
Power bi premium
Power bi premiumPower bi premium
Power bi premium
Ike Ellis
 
Move a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloudMove a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloud
Ike Ellis
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You Think
Ike Ellis
 
Pass the Power BI Exam
Pass the Power BI ExamPass the Power BI Exam
Pass the Power BI Exam
Ike Ellis
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATE
Ike Ellis
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018
Ike Ellis
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
Ike Ellis
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
Ike Ellis
 
Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017
Ike Ellis
 
A lap around microsofts business intelligence platform
A lap around microsofts business intelligence platformA lap around microsofts business intelligence platform
A lap around microsofts business intelligence platform
Ike Ellis
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data Landscape
Ike Ellis
 
11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers
Ike Ellis
 

More from Ike Ellis (20)

Storytelling with Data with Power BI
Storytelling with Data with Power BIStorytelling with Data with Power BI
Storytelling with Data with Power BI
 
Storytelling with Data with Power BI.pptx
Storytelling with Data with Power BI.pptxStorytelling with Data with Power BI.pptx
Storytelling with Data with Power BI.pptx
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
 
Data Modeling on Azure for Analytics
Data Modeling on Azure for AnalyticsData Modeling on Azure for Analytics
Data Modeling on Azure for Analytics
 
Migrate a successful transactional database to azure
Migrate a successful transactional database to azureMigrate a successful transactional database to azure
Migrate a successful transactional database to azure
 
Data modeling trends for analytics
Data modeling trends for analyticsData modeling trends for analytics
Data modeling trends for analytics
 
Data modeling trends for Analytics
Data modeling trends for AnalyticsData modeling trends for Analytics
Data modeling trends for Analytics
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applications
 
Power bi premium
Power bi premiumPower bi premium
Power bi premium
 
Move a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloudMove a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloud
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You Think
 
Pass the Power BI Exam
Pass the Power BI ExamPass the Power BI Exam
Pass the Power BI Exam
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATE
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017
 
A lap around microsofts business intelligence platform
A lap around microsofts business intelligence platformA lap around microsofts business intelligence platform
A lap around microsofts business intelligence platform
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data Landscape
 
11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers
 

Recently uploaded

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 

Recently uploaded (20)

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 

Introduction to DAX

  • 1. Introduction to DAX Ike Ellis, MVP Crafting Bytes @ike_ellis ike@craftingbytes.com www.ikeellis.com
  • 2. Do you know DAX?
  • 3. What do you need to know in order to say yes, I know DAX? 1. You need to know these functions: • SUM, AVERAGE, MIN, MAX • COUNT, COUNTROWS • CALCULATE • FILTER • IF/VARIABLES 2. You need to know about Contexts • Row Context • Filter Context 3. Some other things: • Formatting • White space • Time intelligence • Best Practices • X vs nonX functions(SUM vs SUMX) • DAX Studio • Basic Troubleshooting
  • 4. So how will you learn it? • Go in order: • This slide deck • This Power BI Project • Practice, practice, practice
  • 5. And how will you use it? • Works in Excel • Works in Power BI • Works in SQL Server Analysis Services (SSAS) Tabular
  • 6. This presentation • Simplifies the complexity • Might not tell you the whole truth for the sake of simplicity • Is not seeking to be comprehensive, but instead, seeks to allow you to answer the question, yes, I know DAX in that job interview
  • 7. Your first DAX expression • Check Power BI Desktop tab “Your First DAX Expression” • It’s a calculated column called Order Line Total • Meant to add a column to every record in a table. Order Line Total = 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice]
  • 8. Your Second DAX Expression • Check Power BI Desktop tab “Your Second DAX Expression” • This is a measure • Meant to perform an aggregation that we can slice & dice Total Sales = SUM('Sales OrderDetails'[Order Line Total])
  • 9. How can we verify this? select sum(Sales.OrderDetails.unitprice * Sales.OrderDetails.qty) from sales.OrderDetails
  • 10. DAX Expression Breakdown Name the measure. You’ll use that in the visualization Built in DAX formula Table name Column nameEquals sign separates expression name from expression formula Total Sales = SUM('Sales OrderDetails'[Order Line Total])
  • 11. All kinds of easy to use DAX formulas that you can learn quickly • SUM • AVERAGE • MIN • MAX • COUNT • COUNTROWS • DATEDIFF • DATEADD
  • 12. • Look at tab “Easy DAX built-in formulas” • Look under the Orders table for the calculated column “Days to Ship” • Look under Orders table for measure “Average Days to Ship Days To Ship = DATEDIFF('Sales Orders'[orderdate], 'Sales Orders'[shippeddate],DAY) Play again: AVERAGE and DATEDIFF Average Days to Ship = AVERAGE('Sales Orders'[Days To Ship])
  • 13. Your Third DAX expression: Calculated Table • Look at the Dates table. It was built with a DAX expression • Created a Dates table with a date per day between the specified range • Also created a Dates hierarchy Dates = CALENDAR("1/1/2000", "12/31/2016")
  • 14. Now on to Contexts! • Two different contexts: • Row Context • Filter Context
  • 15. Row Context • We already know how this works! We’ve been using it for all of our calculated columns. Let’s revisit our first DAX Expression • Notice we expect a value per row in a table • This runs at import and gets stored • Might increase file size Order Line Total = 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice]
  • 16. Filter Context • Easy to show with measures • Look at Filter Context 1, 2, 3 in the Power BI Desktop file (PBIX).
  • 17. Filter Context 1 • We see it filtered by year and optionally by product category • The measure is only defined once, and the DAX engine takes care of doing the calculations on the fly • The calculations are not stored, but created and retrieved at query time
  • 18. Filter Context 2 Total Sales by year and with a page filter.
  • 19. Filter Context 3 • Visuals can impact each other and change context
  • 20. Now that we understand context, we can answer this: Measures vs Calculated Columns Measures Calculated Columns Different functions Uses Row Contex Doesn’t take up space Mostly text Less space Executes at the point data is read into the model and saved (value is static) Filter Context Executed at the time it is used
  • 21. CALCULATE: Breaking out of the filter context Beverages Total Sales = CALCULATE ( SUM('Sales OrderDetails'[Order Line Total]) , 'Production Categories'[categoryname] = "Beverages" ) AGGREGATION FILTER Look at the tab CALCULATE
  • 22. FILTER Number of Orders = COUNT('Sales Orders'[orderid]) Number of US Orders = CALCULATE ( COUNT ( 'Sales OrderDetails'[orderid] ) , FILTER ( 'Sales Customers' , 'Sales Customers'[country] = "USA" ) )
  • 23. VARIABLES & RETURN Total Sales For Customers with Minimum Order Count = VAR MinimumOrderCount = 5 VAR CustomersWithMinimumOrders = CALCULATE ( sum('Sales OrderDetails'[Order Line Total]) , FILTER('Sales Customers', [Number of Orders] > MinimumOrderCount) ) RETURN CustomersWithMinimumOrders
  • 24. Variables VAR myVar = 1 Data Type Variable Name Variable Value RETURN myVar + 25 Expressions must use RETURN to return a value
  • 25. Debugging using variables • RETURN does not need to return the last variable • In a multi-step formula, you can return an earlier value to troubleshoot it • Simplifies the reading of code, rather than endlessly nesting values over and over again.
  • 26. Time Intelligence: TOTALYTD YTD Total Sales = TOTALYTD ( SUM('Sales OrderDetails'[Order Line Total]) , Dates[Date].[Date] )
  • 27. Time Intelligence: PREVIOUSMONTH Total Sales Previous Month = CALCULATE ( sum('Sales OrderDetails'[Order Line Total]) , PREVIOUSMONTH(Dates[Date]) )
  • 28. X vs nonX functions(SUM vs SUMX) • SUM is an aggregator function. It works like a measure, calculating based on the current filter context. • SUMX is an iterator function. It works row by row. SUMX has awareness of rows in a table, hince can reference the intersection of each row with any columns in the table.
  • 29. SUM vs SUMX Example Total Sales SUMX = SUMX( 'Sales OrderDetails' , 'Sales OrderDetails'[qty] * 'Sales OrderDetails'[unitprice] ) Total Sales = SUM('Sales OrderDetails'[Order Line Total])
  • 30. Best Practice: Organize your code • Keep measures together • Organize them by type • Simple aggregation • Time variance • Ratios and differences • Business-specific calculations
  • 31. Best Practice: Naming Columns & Measures • Feel free to use spaces • Avoid acronyms • Make names terse, but descriptive • Makes Q & A easier to use • In formulas, reference table names for calculated columns and do not reference table names for measures, so you’ll know the difference
  • 32. Best Practice: Formatting • DAX Expressions can have lots of parentheses and square brackets • Please use white space to control this • Here’s an example of a properly formatted calculated column Days To Ship = DATEDIFF ( 'Sales Orders'[orderdate] , 'Sales Orders'[shippeddate] , DAY )
  • 33. Basic Troubleshooting • A lot of things can go wrong, but the problem is usually one of two things: 1. A relationship is misconfigured or the data is wrong in the model. 2. Wrong data type
  • 34. Data types • Numeric • String • Bool • DateTime • If a function is expecting a numeric, but gets a string, it won’t work. Clean up the model and watch it start working. • Uses less space and memory with your model • Improves performance
  • 36. Manipulating the relationships Total Sales By Ship Year = CALCULATE ( SUM('Sales OrderDetails'[Order Line Total]) , USERELATIONSHIP('Sales Orders'[shippeddate], Dates[Date]) ) Only one active relationship at a time
  • 37. DAX Studio • Parses • Formats • Shows execution plan • Connects to SSAS Tabular or Power BI Desktop
  • 39. Contact Me! http://www.craftingbytes.com http://blog.ikeellis.com http://www.ikeellis.com YouTube http://www.youtube.com/user/IkeEllisData San Diego Tech Immersion Group http://www.sdtig.com Twitter: @ike_ellis 619.922.9801 ike@craftingbytes.com