SlideShare a Scribd company logo
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
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

More Related Content

What's hot

Power BI Zero to Hero by Rajat Jaiswal
Power BI Zero to Hero by Rajat JaiswalPower BI Zero to Hero by Rajat Jaiswal
Power BI Zero to Hero by Rajat Jaiswal
Indiandotnet
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdf
VishnuGone
 
Sql server 2019 new features
Sql server 2019 new featuresSql server 2019 new features
Sql server 2019 new features
George Walters
 
Power BI: From the Basics
Power BI: From the BasicsPower BI: From the Basics
Power BI: From the Basics
Nikkia Carter
 
Tableau online training
Tableau online trainingTableau online training
Tableau online training
suresh
 
Power bi
Power biPower bi
Power bi
jainema23
 
Tableau
TableauTableau
Tableau
TableauTableau
Data Modeling with Power BI
Data Modeling with Power BIData Modeling with Power BI
Data Modeling with Power BI
Raul Martin Sarachaga Diaz
 
Tableau Presentation
Tableau PresentationTableau Presentation
Tableau Presentation
Andrea Bissoli
 
Basic introduction to power query
Basic introduction to power queryBasic introduction to power query
Basic introduction to power query
disha parmar
 
Azure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data FlowsAzure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data Flows
Thomas Sykes
 
How to Improve Data Analysis Through Visualization in Tableau
How to Improve Data Analysis Through Visualization in TableauHow to Improve Data Analysis Through Visualization in Tableau
How to Improve Data Analysis Through Visualization in Tableau
Edureka!
 
Power BI vs Tableau
Power BI vs TableauPower BI vs Tableau
Power BI vs Tableau
Don Hyun
 
Data Visualization Techniques in Power BI
Data Visualization Techniques in Power BIData Visualization Techniques in Power BI
Data Visualization Techniques in Power BI
Angel Abundez
 
Power of power BI
Power of power BI Power of power BI
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQL
Tony Tam
 
Power BI Overview
Power BI OverviewPower BI Overview
Power BI Overview
James Serra
 
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
 

What's hot (20)

Power BI Zero to Hero by Rajat Jaiswal
Power BI Zero to Hero by Rajat JaiswalPower BI Zero to Hero by Rajat Jaiswal
Power BI Zero to Hero by Rajat Jaiswal
 
Power BI Data Modeling.pdf
Power BI Data Modeling.pdfPower BI Data Modeling.pdf
Power BI Data Modeling.pdf
 
Sql server 2019 new features
Sql server 2019 new featuresSql server 2019 new features
Sql server 2019 new features
 
Power BI: From the Basics
Power BI: From the BasicsPower BI: From the Basics
Power BI: From the Basics
 
Tableau online training
Tableau online trainingTableau online training
Tableau online training
 
Power bi
Power biPower bi
Power bi
 
Tableau
TableauTableau
Tableau
 
Tableau
TableauTableau
Tableau
 
Data Modeling with Power BI
Data Modeling with Power BIData Modeling with Power BI
Data Modeling with Power BI
 
Tableau Presentation
Tableau PresentationTableau Presentation
Tableau Presentation
 
Basic introduction to power query
Basic introduction to power queryBasic introduction to power query
Basic introduction to power query
 
Azure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data FlowsAzure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data Flows
 
How to Improve Data Analysis Through Visualization in Tableau
How to Improve Data Analysis Through Visualization in TableauHow to Improve Data Analysis Through Visualization in Tableau
How to Improve Data Analysis Through Visualization in Tableau
 
Power BI vs Tableau
Power BI vs TableauPower BI vs Tableau
Power BI vs Tableau
 
Data Visualization Techniques in Power BI
Data Visualization Techniques in Power BIData Visualization Techniques in Power BI
Data Visualization Techniques in Power BI
 
Pivot Tables
Pivot TablesPivot Tables
Pivot Tables
 
Power of power BI
Power of power BI Power of power BI
Power of power BI
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQL
 
Power BI Overview
Power BI OverviewPower BI Overview
Power BI Overview
 
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
 

Similar to Introduction to DAX Language

Dax en
Dax enDax en
Dax en
Marco Pozzan
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
MARasheed3
 
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 JoinsAshwin Dinoriya
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
Soham Kulkarni
 
Programming in R
Programming in RProgramming in R
Programming in R
Smruti Sarangi
 
Working with shapes
Working with shapesWorking with shapes
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_sqlpgolhar
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
NalinaKumari2
 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSEL
Joel Falcou
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
Megha V
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniquesaabaap
 

Similar to Introduction to DAX Language (20)

Dax en
Dax enDax en
Dax en
 
Variables
VariablesVariables
Variables
 
Excel.useful fns
Excel.useful fnsExcel.useful fns
Excel.useful fns
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
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
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
 
Sql
SqlSql
Sql
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Working with shapes
Working with shapesWorking with shapes
Working with shapes
 
MSAvMySQL.pptx
MSAvMySQL.pptxMSAvMySQL.pptx
MSAvMySQL.pptx
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSEL
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniques
 

More from Antonios Chatzipavlis

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
 

More from Antonios Chatzipavlis (20)

Data virtualization using polybase
Data virtualization using polybaseData virtualization using polybase
Data virtualization using polybase
 
SQL server Backup Restore Revealed
SQL server Backup Restore RevealedSQL server Backup Restore Revealed
SQL server Backup Restore Revealed
 
Migrate SQL Workloads to Azure
Migrate SQL Workloads to AzureMigrate SQL Workloads to Azure
Migrate SQL Workloads to Azure
 
Machine Learning in SQL Server 2019
Machine Learning in SQL Server 2019Machine Learning in SQL Server 2019
Machine Learning in SQL Server 2019
 
Workload Management in SQL Server 2019
Workload Management in SQL Server 2019Workload Management in SQL Server 2019
Workload Management in SQL Server 2019
 
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)
 
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
 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
 
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
 
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
 
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
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
Sqlschool 2017 recap - 2018 plans
Sqlschool 2017 recap - 2018 plansSqlschool 2017 recap - 2018 plans
Sqlschool 2017 recap - 2018 plans
 
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
 
Microsoft SQL Family and GDPR
Microsoft SQL Family and GDPRMicrosoft SQL Family and GDPR
Microsoft SQL Family and GDPR
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
Introduction to Azure Data Lake
Introduction to Azure Data LakeIntroduction to Azure Data Lake
Introduction to Azure Data Lake
 
Azure SQL Data Warehouse
Azure SQL Data Warehouse Azure SQL Data Warehouse
Azure SQL Data Warehouse
 
Introduction to azure document db
Introduction to azure document dbIntroduction to azure document db
Introduction to azure document db
 
Introduction to Machine Learning on Azure
Introduction to Machine Learning on AzureIntroduction to Machine Learning on Azure
Introduction to Machine Learning on Azure
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 

Introduction to DAX Language

  • 1.
  • 2.
  • 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
  • 7.
  • 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