SlideShare a Scribd company logo
Introduction to DAX Language
Introduction to DAX Language
Please mute
your mic
Antonios Chatzipavlis
Data Solutions Consultant & Trainer
Since 1999
30+Years in a Field
20+
Experience with
60+
Certifications
SQLschool.gr
Founder
A community for Greek professionals who use the
Microsoft Data Platform
Connect / Explore / Learn
@antoniosch - @sqlschool
./sqlschoolgr - ./groups/sqlschool
yt/c/SqlschoolGr
SQLschool.gr Group
help@sqlschool.gr
Join us
Articles
SQL Saturday Nights
SQL Server in Greek
Webcasts
News
Resources
Connect / Explore / Learn
V.102010-2020
Introduction to DAX Language
Presentation Content
Introduction to
DAX
Language
• Overview
• Language Fundamentals
• Context
• Queries
Overview
• DAX is the programming language of Microsoft Power BI,
Microsoft Analysis Services, and Microsoft Power Pivot for
Excel.
- Created in 2010, with the first release of PowerPivot for Microsoft Excel
2010
• DAX has been designed to enhance data modeling,
reporting, and analytics.
• DAX is described as a functional language
- Calculations primarily use functions to generate results.
• Unlike T-SQL, there is no concept of INSERT, UPDATE, or
DELETE for manipulating data in a data model.
What is DAX?
Data Analysis eXpressions
A data model is a collection of data,
calculations, and formatting rules that
combine to create an object that can be
used to explore, query, and better
understand an existing dataset.
What is a Data Model?
FACT
MEASURES
DIMENSION
DIMENSION
DIMENSIONDIMENSION
DIMENSION
Components of a DAX Data Model
Data Tables Columns Relationships Measures Hierarchies
Language Fundamentals
• DAX formulas start with the equal
sign (=) followed by an expression
• Expressions can contain functions,
operators, constants, and references
to columns
• Measure names must be enclosed in
brackets
• Table names containing spaces must
be enclosed in single quotation
marks
• Column references
- 'table name'[column name]
- [column name]
DAX Syntax
CALCULATE [Total Sales] 'Channel'[ChannelName] “Store”
Comments in DAX
= 'Channel'[ChannelPrice] * 'Channel'[ChannelDisc] -– Single line comment
= 'Channel'[ChannelPrice] - 'Channel'[ChannelTax] // Single line comment
= IF ( 'Channel'[ChannelDisc] > 0 ,
/*
Multi-line
comment
*/
“Has discount”
)
DAX Data Types
DAX
Data Type
Power BI
Data Type
Analysis Services
Data Type
SQL Server
Data Type Stored as
Integer Whole Number Whole Number INT 64-bit integer
Decimal Decimal Number Decimal Number FLOAT 64-bit double floating
Currency Fixed Decimal Number Currency MONEY 64-bit integer / 10.000
DateTime DateTime, Date, Time Date DATETIME 64-bit double floating
Boolean True/False True/False BIT Boolean
String Text Text NVARCHAR(MAX) Unicode string
Variant - - -
Binary Binary Binary VARBINARY(MAX) Binary
DAX Operators
Operator Type Symbol Use Example
Parenthesis ( ) Precedence order and grouping of arguments (5+2)*3
Text concatenation & Concatenation of strings “Athens” & [Country]
Arithmetic
+ Addition 4+3
- Subtraction / Negation 5-3 / -3
* Multiplication 4*3
/ Division 4/2
^ Exponents 2^6
Comparison
= Equal to [Country] = “Greece”
<> Not equal to [Country] <> “Greece”
> Greater than [Amount] > 100
>= Greater than or equal to [Amount] >= 100
< Less than [Amount] < 100
<= Less than or equal to [Amount] <= 100
Logical
&& AND condition between two Boolean expressions [Country]=“Greece” && [Amount]>0
|| OR condition between two Boolean expressions [Country]=“Greece” || [Amount]>0
IN Inclusion of an element in a list [Country] IN {“Greece” , ”Cyprus”}
NOT Boolean negation NOT [Amount] > 100
• Variables are used to store results from DAX expressions.
• Variables can be used in any type of DAX calculation
including calculated columns, measures, and tables.
• Variables are not strictly typed and can represent any type
of object in DAX.
• Variables automatically assume the type of the object being
assigned.
• You must use a RETURN statement to close a layer of
variable scope.
• You can declare multiple variables within the same layer of
scope and you can use them with a single RETURN
statement.
• Nested variables can initialize a new layer of scope when
you use them anywhere within an expression, but all layers
of scope are ended when you use a RETURN statement.
DAX Variable
VAR varname = expression
RETURN expression
VAR myVar1 = 1
VAR myVar2 = myVar1 + 2
RETURN myVar2 * 2
Nested Measure =
VAR Level1a = 10
VAR Level1b =
VAR level2a = Level1a
VAR Leval2b = level2a * 3
RETURN Leval2b
RETURN Level1b
DAX Table constructors
Define anonymous tables directly in the code.
{ “Red”, “Blue”, “Green” }
Or
{ (“Red”), (“Blue”), (“Green”) }
Single Column
{
( 1,“Red” ),
( 2,“Blue” ),
( 3,“Green” )
}
Multi Column
DAX Conditional Statements
IF ( 20 < 30, "second", "third" ) -> "second"
IF ( 20 < 15, "second", BLANK() ) -> BLANK()
IF ( 20 < 15, "second" ) -> BLANK()
IF ( Customer[Status] = "A", "Platinum",
IF ( Customer[Status] = "B", "Gold",
IF ( Customer[Status] = "C", "Silver",
IF ( Customer[Status] = "D", "White", "None" )
)
)
)
SWITCH
(
Customer[Status],
"A", "Platinum",
"B", "Gold",
"C", "Silver",
"D", "White",
"None"
)
SWITCH
(
TRUE (),
Products[UnitPrice] < 10, "LOW",
Products[UnitPrice] < 50, "MEDIUM",
Products[UnitPrice] < 100, "HIGH",
"VERY HIGH"
)
Error Handling in DAX Expression
Conversion Errors
DAX automatically converts
values between strings and
numbers whenever the
operator requires it
Arithmetical
Operations Errors
DAX detects this errors and it
blocks any further
computation of the expression
and raises an error.
Empty or Missing
Values
DAX handles missing values,
blank values, or empty cells in
the same way, using the value
BLANK.
• BLANK value assigned to a column when
the data source contains a NULL value
• The BLANK value is automatically
converted in case it is compared with
other values
- In a numeric expression, a blank is automatically
converted into 0
- In a string expression, a blank is automatically
converted into an empty string
• ISBLANK() function checks whether a
value is blank and returns TRUE or FALSE
BLANK Function
BLANK is not the T-SQL NULL
Sample Result
BLANK()=0 TRUE
BLANK() =“” TRUE
BLANK()-10 -10
BLANK()+18 18
5 / BLANK() INFINITY
0 / BLANK() NaN
BLANK() * 8 Blank value
BLANK() / 8 Blank value
BLANK() || BLANK() FALSE
BLANK() && BLANK() FALSE
( BLANK() = BLANK() ) TRUE
( BLANK() = TRUE ) FALSE
( BLANK() = FALSE ) TRUE
IFERROR Function
Evaluates an expression and returns a specified value if the expression returns an error;
otherwise returns the value of the expression itself.
IFERROR ( <Value> , <ValueIfError> )
IFERROR ( A, B )
Equivalent of
IF ( ISERROR ( A ), B , A )
ISERROR Function
Checks whether a value is an error, and returns TRUE or FALSE.
IFERROR ( <Value> )
IF ( ISERROR ( A ), B , A )
Equivalent of
IFERROR ( A, B )
• Date and time functions
• Time-intelligence functions (DAX)
• Filter functions
• Information functions
• Logical functions
• Math and Trigonometry functions
• Other functions
• Parent and Child functions
• Statistical functions
• Text functions
DAX Functions
More than 200 functions in several categories
• DAX provides several functions
• Functions operate according to the filter context.
• Function with X suffix are suitable to aggregate the results of a more
complex expression
• Function with A suffix exist only for maintaining the Excel syntax
DAX Functions
How to use DAX Functions
<FunctionName> ( Table[Column] )
<FunctionNameX> ( Table, <expression )
<FunctionNameA> ( Table, <expression )
Context
Cardinality Cross Filter Directions
• Many to One (*:1)
• One to One (1:1)
• One to Many (1:*)
• Single
• Both
Relationships in Data Model
The Cornerstone of context
Relationships exist to join tables together so that you can work with them
as if they were one
Calculated Columns Measures
Calculated columns defined within tables
in the data model by adding new columns.
The expression assigned to a calculated
column is evaluated for every row of the
table
A measure is a DAX expression that is
evaluated in a context made by a set of
rows of the data model.
Context Calculations
Sales[GrossMargin] =
Sales[SalesAmount] -
Sales[TotalProductCost]
Sales[Total Sales] =
SUM ( Sales[SalesAmount] )
Context is the layer of filtering that is
applied to calculations, often dynamically
to produce a result specific to every value
in a pivot table or visual, including row
and column totals.
Context
Row
Transition
Filter
Filter Context
The filter context filter
Row Context
The Row Context iterates
Row Context and Relationships
Products[NumberOrders] = COUNTROWS ( RELATEDTABLE ( Sales ) )
Products[ListAmount] = SUMX ( RELATEDTABLE ( Sales ),
Sales[OrderQuantity] * Products[ListPrice]
Sales[ListAmount] = Sales[OrderQuantity] * RELATED (Products[ListPrice])
Sales[ListAmount] = Sales[OrderQuantity] * Products[ListPrice]
RELATED Function
RELATEDTABLE Function
Context Transition
Context transition performed in a filter context under which it evaluates its expression.
Queries
EVALUATE Statement
DEFINE MEASURE
VAR
EVALUATE
ORDER BY
START AT
Relationship Queries
For SQL Developers
Search Queries
For SQL Developers
Any
questions
Thank you!
@antoniosch - @sqlschool
./sqlschoolgr - ./groups/sqlschool
./c/SqlschoolGr
SQLschool.gr Group
Antonios Chatzipavlis
Data Solutions Consultant & Trainer
A community for Greek professionals who use the Microsoft Data Platform
Copyright © SQLschool.gr. All right reserved. PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION
Ad

More Related Content

What's hot (20)

Intro to DAX Patterns
Intro to DAX PatternsIntro to DAX Patterns
Intro to DAX Patterns
Eric Bragas
 
Data Analysis Expressions (DAX) Training
Data Analysis Expressions (DAX) TrainingData Analysis Expressions (DAX) Training
Data Analysis Expressions (DAX) Training
Arocom IT Solutions Pvt. Ltd
 
Introduction to DAX - Part 1
Introduction to DAX - Part 1Introduction to DAX - Part 1
Introduction to DAX - Part 1
Alan Koo
 
Tableau Prep.pptx
Tableau Prep.pptxTableau Prep.pptx
Tableau Prep.pptx
Venneladonthireddy1
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdf
VishnuGone
 
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Edureka!
 
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
Ryan Sleeper
 
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
 
Visualization using Tableau
Visualization using TableauVisualization using Tableau
Visualization using Tableau
Girija Muscut
 
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
 
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!
 
Power bi
Power biPower bi
Power bi
jainema23
 
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
Edureka!
 
What is Power BI
What is Power BIWhat is Power BI
What is Power BI
Naseeba P P
 
Tableau And Data Visualization - Get Started
Tableau And Data Visualization - Get StartedTableau And Data Visualization - Get Started
Tableau And Data Visualization - Get Started
Spotle.ai
 
Power BI Dataflows
Power BI DataflowsPower BI Dataflows
Power BI Dataflows
Bent Nissen Pedersen
 
Improve power bi performance
Improve power bi performanceImprove power bi performance
Improve power bi performance
Annie Xu
 
Basic introduction to power query
Basic introduction to power queryBasic introduction to power query
Basic introduction to power query
disha parmar
 
Power BI vs Tableau: Which One is Best For Business Intelligence
Power BI vs Tableau: Which One is Best For Business IntelligencePower BI vs Tableau: Which One is Best For Business Intelligence
Power BI vs Tableau: Which One is Best For Business Intelligence
Stat Analytica
 
Intro to DAX Patterns
Intro to DAX PatternsIntro to DAX Patterns
Intro to DAX Patterns
Eric Bragas
 
Introduction to DAX - Part 1
Introduction to DAX - Part 1Introduction to DAX - Part 1
Introduction to DAX - Part 1
Alan Koo
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdf
VishnuGone
 
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Tableau Tutorial For Beginners | Tableau Training For Beginners | Tableau Cer...
Edureka!
 
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
Ryan Sleeper
 
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
 
Visualization using Tableau
Visualization using TableauVisualization using Tableau
Visualization using Tableau
Girija Muscut
 
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
 
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!
 
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | ...
Edureka!
 
What is Power BI
What is Power BIWhat is Power BI
What is Power BI
Naseeba P P
 
Tableau And Data Visualization - Get Started
Tableau And Data Visualization - Get StartedTableau And Data Visualization - Get Started
Tableau And Data Visualization - Get Started
Spotle.ai
 
Improve power bi performance
Improve power bi performanceImprove power bi performance
Improve power bi performance
Annie Xu
 
Basic introduction to power query
Basic introduction to power queryBasic introduction to power query
Basic introduction to power query
disha parmar
 
Power BI vs Tableau: Which One is Best For Business Intelligence
Power BI vs Tableau: Which One is Best For Business IntelligencePower BI vs Tableau: Which One is Best For Business Intelligence
Power BI vs Tableau: Which One is Best For Business Intelligence
Stat Analytica
 

Similar to Introduction to DAX Language (20)

Dax en
Dax enDax en
Dax en
Marco Pozzan
 
From 0 to DAX…………………………………………………………..pdf
From 0 to DAX…………………………………………………………..pdfFrom 0 to DAX…………………………………………………………..pdf
From 0 to DAX…………………………………………………………..pdf
VaibhavChawla26
 
Variables
VariablesVariables
Variables
Jesus Obenita Jr.
 
Excel.useful fns
Excel.useful fnsExcel.useful fns
Excel.useful fns
Rahul Singhal
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
MARasheed3
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
vijay venkatash
 
Pandas csv
Pandas csvPandas csv
Pandas csv
Devashish Kumar
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
Debasish Ghosh
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
Dieudonne Nahigombeye
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
R You Ready? An I/O Psychologist's Guide to R and Rstudio
R You Ready? An I/O Psychologist's Guide to R and RstudioR You Ready? An I/O Psychologist's Guide to R and Rstudio
R You Ready? An I/O Psychologist's Guide to R and Rstudio
sijan492614
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
Soham Kulkarni
 
DP080_Lecture_2 SQL related document.pdf
DP080_Lecture_2 SQL related document.pdfDP080_Lecture_2 SQL related document.pdf
DP080_Lecture_2 SQL related document.pdf
MinhTran394436
 
Sql
SqlSql
Sql
Diana Diana
 
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
BASICS OF STRUCTURED QUEERY LANGUAGE.PPTBASICS OF STRUCTURED QUEERY LANGUAGE.PPT
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
Uma Kakarlapudi
 
Programming in R
Programming in RProgramming in R
Programming in R
Smruti Sarangi
 
Working with shapes
Working with shapesWorking with shapes
Working with shapes
NAXUTL, StratGlobal, Nature Acoustical
 
MSAvMySQL.pptx
MSAvMySQL.pptxMSAvMySQL.pptx
MSAvMySQL.pptx
MattMarino13
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
pgolhar
 
From 0 to DAX…………………………………………………………..pdf
From 0 to DAX…………………………………………………………..pdfFrom 0 to DAX…………………………………………………………..pdf
From 0 to DAX…………………………………………………………..pdf
VaibhavChawla26
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
MARasheed3
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
Debasish Ghosh
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
R You Ready? An I/O Psychologist's Guide to R and Rstudio
R You Ready? An I/O Psychologist's Guide to R and RstudioR You Ready? An I/O Psychologist's Guide to R and Rstudio
R You Ready? An I/O Psychologist's Guide to R and Rstudio
sijan492614
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
Soham Kulkarni
 
DP080_Lecture_2 SQL related document.pdf
DP080_Lecture_2 SQL related document.pdfDP080_Lecture_2 SQL related document.pdf
DP080_Lecture_2 SQL related document.pdf
MinhTran394436
 
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
BASICS OF STRUCTURED QUEERY LANGUAGE.PPTBASICS OF STRUCTURED QUEERY LANGUAGE.PPT
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
Uma Kakarlapudi
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
pgolhar
 
Ad

More from Antonios Chatzipavlis (20)

Data virtualization using polybase
Data virtualization using polybaseData virtualization using polybase
Data virtualization using polybase
Antonios Chatzipavlis
 
SQL server Backup Restore Revealed
SQL server Backup Restore RevealedSQL server Backup Restore Revealed
SQL server Backup Restore Revealed
Antonios Chatzipavlis
 
Migrate SQL Workloads to Azure
Migrate SQL Workloads to AzureMigrate SQL Workloads to Azure
Migrate SQL Workloads to Azure
Antonios Chatzipavlis
 
Machine Learning in SQL Server 2019
Machine Learning in SQL Server 2019Machine Learning in SQL Server 2019
Machine Learning in SQL Server 2019
Antonios Chatzipavlis
 
Workload Management in SQL Server 2019
Workload Management in SQL Server 2019Workload Management in SQL Server 2019
Workload Management in SQL Server 2019
Antonios Chatzipavlis
 
Loading Data into Azure SQL DW (Synapse Analytics)
Loading Data into Azure SQL DW (Synapse Analytics)Loading Data into Azure SQL DW (Synapse Analytics)
Loading Data into Azure SQL DW (Synapse Analytics)
Antonios Chatzipavlis
 
Building diagnostic queries using DMVs and DMFs
Building diagnostic queries using DMVs and DMFs Building diagnostic queries using DMVs and DMFs
Building diagnostic queries using DMVs and DMFs
Antonios Chatzipavlis
 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
Antonios Chatzipavlis
 
Designing a modern data warehouse in azure
Designing a modern data warehouse in azure   Designing a modern data warehouse in azure
Designing a modern data warehouse in azure
Antonios Chatzipavlis
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
Antonios Chatzipavlis
 
Designing a modern data warehouse in azure
Designing a modern data warehouse in azure   Designing a modern data warehouse in azure
Designing a modern data warehouse in azure
Antonios Chatzipavlis
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
Antonios Chatzipavlis
 
Sqlschool 2017 recap - 2018 plans
Sqlschool 2017 recap - 2018 plansSqlschool 2017 recap - 2018 plans
Sqlschool 2017 recap - 2018 plans
Antonios Chatzipavlis
 
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018 Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Antonios Chatzipavlis
 
Microsoft SQL Family and GDPR
Microsoft SQL Family and GDPRMicrosoft SQL Family and GDPR
Microsoft SQL Family and GDPR
Antonios Chatzipavlis
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
Antonios Chatzipavlis
 
Introduction to Azure Data Lake
Introduction to Azure Data LakeIntroduction to Azure Data Lake
Introduction to Azure Data Lake
Antonios Chatzipavlis
 
Azure SQL Data Warehouse
Azure SQL Data Warehouse Azure SQL Data Warehouse
Azure SQL Data Warehouse
Antonios Chatzipavlis
 
Introduction to azure document db
Introduction to azure document dbIntroduction to azure document db
Introduction to azure document db
Antonios Chatzipavlis
 
Introduction to Machine Learning on Azure
Introduction to Machine Learning on AzureIntroduction to Machine Learning on Azure
Introduction to Machine Learning on Azure
Antonios Chatzipavlis
 
Workload Management in SQL Server 2019
Workload Management in SQL Server 2019Workload Management in SQL Server 2019
Workload Management in SQL Server 2019
Antonios Chatzipavlis
 
Loading Data into Azure SQL DW (Synapse Analytics)
Loading Data into Azure SQL DW (Synapse Analytics)Loading Data into Azure SQL DW (Synapse Analytics)
Loading Data into Azure SQL DW (Synapse Analytics)
Antonios Chatzipavlis
 
Building diagnostic queries using DMVs and DMFs
Building diagnostic queries using DMVs and DMFs Building diagnostic queries using DMVs and DMFs
Building diagnostic queries using DMVs and DMFs
Antonios Chatzipavlis
 
Designing a modern data warehouse in azure
Designing a modern data warehouse in azure   Designing a modern data warehouse in azure
Designing a modern data warehouse in azure
Antonios Chatzipavlis
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
Antonios Chatzipavlis
 
Designing a modern data warehouse in azure
Designing a modern data warehouse in azure   Designing a modern data warehouse in azure
Designing a modern data warehouse in azure
Antonios Chatzipavlis
 
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018 Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Antonios Chatzipavlis
 
Introduction to Machine Learning on Azure
Introduction to Machine Learning on AzureIntroduction to Machine Learning on Azure
Introduction to Machine Learning on Azure
Antonios Chatzipavlis
 
Ad

Recently uploaded (20)

fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 

Introduction to DAX Language

  • 4. Antonios Chatzipavlis Data Solutions Consultant & Trainer Since 1999 30+Years in a Field 20+ Experience with 60+ Certifications SQLschool.gr Founder
  • 5. A community for Greek professionals who use the Microsoft Data Platform Connect / Explore / Learn @antoniosch - @sqlschool ./sqlschoolgr - ./groups/sqlschool yt/c/SqlschoolGr SQLschool.gr Group help@sqlschool.gr Join us Articles SQL Saturday Nights SQL Server in Greek Webcasts News Resources
  • 6. Connect / Explore / Learn V.102010-2020
  • 8. Presentation Content Introduction to DAX Language • Overview • Language Fundamentals • Context • Queries
  • 10. • DAX is the programming language of Microsoft Power BI, Microsoft Analysis Services, and Microsoft Power Pivot for Excel. - Created in 2010, with the first release of PowerPivot for Microsoft Excel 2010 • DAX has been designed to enhance data modeling, reporting, and analytics. • DAX is described as a functional language - Calculations primarily use functions to generate results. • Unlike T-SQL, there is no concept of INSERT, UPDATE, or DELETE for manipulating data in a data model. What is DAX? Data Analysis eXpressions
  • 11. A data model is a collection of data, calculations, and formatting rules that combine to create an object that can be used to explore, query, and better understand an existing dataset. What is a Data Model? FACT MEASURES DIMENSION DIMENSION DIMENSIONDIMENSION DIMENSION
  • 12. Components of a DAX Data Model Data Tables Columns Relationships Measures Hierarchies
  • 14. • DAX formulas start with the equal sign (=) followed by an expression • Expressions can contain functions, operators, constants, and references to columns • Measure names must be enclosed in brackets • Table names containing spaces must be enclosed in single quotation marks • Column references - 'table name'[column name] - [column name] DAX Syntax CALCULATE [Total Sales] 'Channel'[ChannelName] “Store”
  • 15. Comments in DAX = 'Channel'[ChannelPrice] * 'Channel'[ChannelDisc] -– Single line comment = 'Channel'[ChannelPrice] - 'Channel'[ChannelTax] // Single line comment = IF ( 'Channel'[ChannelDisc] > 0 , /* Multi-line comment */ “Has discount” )
  • 16. DAX Data Types DAX Data Type Power BI Data Type Analysis Services Data Type SQL Server Data Type Stored as Integer Whole Number Whole Number INT 64-bit integer Decimal Decimal Number Decimal Number FLOAT 64-bit double floating Currency Fixed Decimal Number Currency MONEY 64-bit integer / 10.000 DateTime DateTime, Date, Time Date DATETIME 64-bit double floating Boolean True/False True/False BIT Boolean String Text Text NVARCHAR(MAX) Unicode string Variant - - - Binary Binary Binary VARBINARY(MAX) Binary
  • 17. DAX Operators Operator Type Symbol Use Example Parenthesis ( ) Precedence order and grouping of arguments (5+2)*3 Text concatenation & Concatenation of strings “Athens” & [Country] Arithmetic + Addition 4+3 - Subtraction / Negation 5-3 / -3 * Multiplication 4*3 / Division 4/2 ^ Exponents 2^6 Comparison = Equal to [Country] = “Greece” <> Not equal to [Country] <> “Greece” > Greater than [Amount] > 100 >= Greater than or equal to [Amount] >= 100 < Less than [Amount] < 100 <= Less than or equal to [Amount] <= 100 Logical && AND condition between two Boolean expressions [Country]=“Greece” && [Amount]>0 || OR condition between two Boolean expressions [Country]=“Greece” || [Amount]>0 IN Inclusion of an element in a list [Country] IN {“Greece” , ”Cyprus”} NOT Boolean negation NOT [Amount] > 100
  • 18. • Variables are used to store results from DAX expressions. • Variables can be used in any type of DAX calculation including calculated columns, measures, and tables. • Variables are not strictly typed and can represent any type of object in DAX. • Variables automatically assume the type of the object being assigned. • You must use a RETURN statement to close a layer of variable scope. • You can declare multiple variables within the same layer of scope and you can use them with a single RETURN statement. • Nested variables can initialize a new layer of scope when you use them anywhere within an expression, but all layers of scope are ended when you use a RETURN statement. DAX Variable VAR varname = expression RETURN expression VAR myVar1 = 1 VAR myVar2 = myVar1 + 2 RETURN myVar2 * 2 Nested Measure = VAR Level1a = 10 VAR Level1b = VAR level2a = Level1a VAR Leval2b = level2a * 3 RETURN Leval2b RETURN Level1b
  • 19. DAX Table constructors Define anonymous tables directly in the code. { “Red”, “Blue”, “Green” } Or { (“Red”), (“Blue”), (“Green”) } Single Column { ( 1,“Red” ), ( 2,“Blue” ), ( 3,“Green” ) } Multi Column
  • 20. DAX Conditional Statements IF ( 20 < 30, "second", "third" ) -> "second" IF ( 20 < 15, "second", BLANK() ) -> BLANK() IF ( 20 < 15, "second" ) -> BLANK() IF ( Customer[Status] = "A", "Platinum", IF ( Customer[Status] = "B", "Gold", IF ( Customer[Status] = "C", "Silver", IF ( Customer[Status] = "D", "White", "None" ) ) ) ) SWITCH ( Customer[Status], "A", "Platinum", "B", "Gold", "C", "Silver", "D", "White", "None" ) SWITCH ( TRUE (), Products[UnitPrice] < 10, "LOW", Products[UnitPrice] < 50, "MEDIUM", Products[UnitPrice] < 100, "HIGH", "VERY HIGH" )
  • 21. Error Handling in DAX Expression Conversion Errors DAX automatically converts values between strings and numbers whenever the operator requires it Arithmetical Operations Errors DAX detects this errors and it blocks any further computation of the expression and raises an error. Empty or Missing Values DAX handles missing values, blank values, or empty cells in the same way, using the value BLANK.
  • 22. • BLANK value assigned to a column when the data source contains a NULL value • The BLANK value is automatically converted in case it is compared with other values - In a numeric expression, a blank is automatically converted into 0 - In a string expression, a blank is automatically converted into an empty string • ISBLANK() function checks whether a value is blank and returns TRUE or FALSE BLANK Function BLANK is not the T-SQL NULL Sample Result BLANK()=0 TRUE BLANK() =“” TRUE BLANK()-10 -10 BLANK()+18 18 5 / BLANK() INFINITY 0 / BLANK() NaN BLANK() * 8 Blank value BLANK() / 8 Blank value BLANK() || BLANK() FALSE BLANK() && BLANK() FALSE ( BLANK() = BLANK() ) TRUE ( BLANK() = TRUE ) FALSE ( BLANK() = FALSE ) TRUE
  • 23. IFERROR Function Evaluates an expression and returns a specified value if the expression returns an error; otherwise returns the value of the expression itself. IFERROR ( <Value> , <ValueIfError> ) IFERROR ( A, B ) Equivalent of IF ( ISERROR ( A ), B , A )
  • 24. ISERROR Function Checks whether a value is an error, and returns TRUE or FALSE. IFERROR ( <Value> ) IF ( ISERROR ( A ), B , A ) Equivalent of IFERROR ( A, B )
  • 25. • Date and time functions • Time-intelligence functions (DAX) • Filter functions • Information functions • Logical functions • Math and Trigonometry functions • Other functions • Parent and Child functions • Statistical functions • Text functions DAX Functions More than 200 functions in several categories
  • 26. • DAX provides several functions • Functions operate according to the filter context. • Function with X suffix are suitable to aggregate the results of a more complex expression • Function with A suffix exist only for maintaining the Excel syntax DAX Functions How to use DAX Functions <FunctionName> ( Table[Column] ) <FunctionNameX> ( Table, <expression ) <FunctionNameA> ( Table, <expression )
  • 28. Cardinality Cross Filter Directions • Many to One (*:1) • One to One (1:1) • One to Many (1:*) • Single • Both Relationships in Data Model The Cornerstone of context Relationships exist to join tables together so that you can work with them as if they were one
  • 29. Calculated Columns Measures Calculated columns defined within tables in the data model by adding new columns. The expression assigned to a calculated column is evaluated for every row of the table A measure is a DAX expression that is evaluated in a context made by a set of rows of the data model. Context Calculations Sales[GrossMargin] = Sales[SalesAmount] - Sales[TotalProductCost] Sales[Total Sales] = SUM ( Sales[SalesAmount] )
  • 30. Context is the layer of filtering that is applied to calculations, often dynamically to produce a result specific to every value in a pivot table or visual, including row and column totals. Context Row Transition Filter
  • 31. Filter Context The filter context filter
  • 32. Row Context The Row Context iterates
  • 33. Row Context and Relationships Products[NumberOrders] = COUNTROWS ( RELATEDTABLE ( Sales ) ) Products[ListAmount] = SUMX ( RELATEDTABLE ( Sales ), Sales[OrderQuantity] * Products[ListPrice] Sales[ListAmount] = Sales[OrderQuantity] * RELATED (Products[ListPrice]) Sales[ListAmount] = Sales[OrderQuantity] * Products[ListPrice] RELATED Function RELATEDTABLE Function
  • 34. Context Transition Context transition performed in a filter context under which it evaluates its expression.
  • 40. Thank you! @antoniosch - @sqlschool ./sqlschoolgr - ./groups/sqlschool ./c/SqlschoolGr SQLschool.gr Group Antonios Chatzipavlis Data Solutions Consultant & Trainer
  • 41. A community for Greek professionals who use the Microsoft Data Platform Copyright © SQLschool.gr. All right reserved. PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION
  翻译: