SlideShare a Scribd company logo
1 of 32
DAX (DATA ANALYSIS EXPRESSIONS)
FROM ZERO TO HERO

Frederik Vandeputte
Partner @Kohera
President @SQLUG.BE
frederik.vandeputte@kohera.be
AGENDA
• What’s DAX
• Calculated columns
• Calculated measures
• Some common DAX functions
• Working with DAX and Dates
• Define security in the model
• Query the BI Semantic Model
DAX - DATA ANALYSIS EXPRESSION
• Introduced in PowerPivot v1
• DAX = Data Analysis Expressions
• DAX goals
    • Make data analysis really easy
    • Uses relationships defined in PowerPivot/BISM model (no need for VLOOKUP)
•   Excel like Syntax
•   Support for +/- 80 Excel function
•   35 Built in Time Intelligence functions
•   + Additional function
•   SQL Server 2012 – Analysis Services Tabular Models
BI SEMANTIC MODEL: ARCHITECTURE
       Third-party     Reporting                               SharePoint
                                         Excel   PowerPivot
       applications     Services                                Insights




        Databases     LOB Applications   Files   OData Feeds   Cloud Services
WHAT CAN WE DO WITH DAX
• Create calculated columns
• Create (calculated) measures
• Define security in the model
• Query the BI Semantic Model
4 IMPORTANT CONCEPTS

      Calculated       Calculated
       Columns         Measures

         Row             Filter
        Context         Context
CALCULATED COLUMNS
•   Just another column in a table
•   Similar to named calculations in SSAS OLAP Datasource views
•   Calculated after data has been loaded (cube processing)
•   Can be placed in colums, rows, filters and slicers
•   Evaluated in row context
•   Examples
    • [Amount] =[Qty] *[Price]
    • [Full Name]     = [First Name] & “ “ & [Last Name]
CALCULATED MEASURES
• Created in the measure grid
• Calculated “on the fly”
• Can only be placed in values area of PivotTables
• Evaluated in filter context
 • Rows/Columns/filters/Slicers
• Examples
 • [Sales]     = SUM (Sales[Amount])
 • [Average Sale] = AVERAGEX ( Sales, Sales[Amount])
FILTER CONTEXT
• Filter Context = cell in PivotTable




                                            [CalendarYear] = 2008
                                           [ChannelName]=”Store”
                                        [ContinentName]=”Europe”
                                 [RegionCountryName] = “Germany”
MEASURES MUST BE EXPLICITELY CREATED

• PowerPivot will create implicit measures when you drag a column
  to the values area in a pivot table
• Not possible in BISM (No_ measure defined)
• Like in SSAS OLAP – measures must be created explicitely
• Eeasiest way: AutoSum in SQL Data Tools
SOME COMMON DAX FUNCTIONS
• DISTINCTCOUNT()
• RELATED()
• CALCULATE()
RELATED(COLUMN) AND RELATEDTABLE(TABLE)


    • More powerfull than VLOOKUP
      • VLOOKUP only returns 1st match
      • Relies on relationships in PowerPivot
      • Follows many to one relationship
RELATED(COLUMN)

                                            FactSales   • Storekey


• Travels many to one direction
• Can travel multiple relationships                                   •Geograpghy
                                                        DimStore
• Add calculated columns to FactSales
                                                                       Key


  • =RELATED(DimStore[StoreName])
  • =RELATED(DimGeography[ContinentName])
                                                                     DimGeography
CALCULATE(EXPRESSION, SETFILTER1, SETFILTER2, …)
• CALCULATE more complex than previous functions, but
  very powerful
• CALCULATE is the Queen Of DAX
• CALCUATE
 • Using the SetFilter arguments, modify the Filter Context
 • If there is a Row Context, move that Row Context onto the Filter Context
 • Evaluate the Expression in the newly modified Filter Context
DAX AND TIME INTELLIGENCE
• +/- 35 DAX time intelligence functions
• DAX helps you when calculating with dates
• But you must follow the rules
THE GOLDEN RULES WHEN WORKING WITH DATES
• Always create a separate Date table.
• Make sure your date table has a continues date range
• Create relationships between fact tables and the Date
  table.
• Never use the datetime column from the fact table in time
  functions.
• The datetime column in the Date table should be at day
  granularity (without fractions of a day).
• Mark the Date table as a Date Table and set the Date
  column.
IF YOU DON’T HAVE A SEPERATE TIME TABLE  ERRORS
IF YOU HAVE A SEPERATE TIME TABLE  CORRECT VALUES
DATE CALCULATIONS
• TOTALYTD function
  • Calculated Year To Date Values
  • SalesAmtYTD:=TOTALYTD(SUM(AutoSales[SalesAmount]);Dates[Date])




                                             WRONG RESULTS
CREATE A DATE DIMENSION
•   Mark Time Dimension Table as Date
•   Use data column from Time dimension in Calculations
•   Sort Columns By key column
•   Create Hierarchies (in Diagram view)


                        CORRECT RESULTS
CREATE THE PERFECT DATE DIMENSION
• Follow the golden rules
• Sort Columns By key column
• Create Hierarchies
TIME INTELLIGENCE EXAMPLES FOR SALES

     Time Period                Formula
     Current Period             =SUM([SalesAmount])
     MTD                        = CALCULATE(SUM(SalesAmount), DATESMTD(Dates[Date]))


     QTD                        = CALCULATE(SUM(SalesAmount), DATESQTD(Dates[Date]))


     YTD                        = CALCULATE(SUM(SalesAmount), DATESYTD(Dates[Date]))


     Current Period Last Year   = CALCULATE(SUM(SalesAmount), DATEADD(Dates[Date],-1,YEAR))


     PriorYearMTD               = CALCULATE(SUM(SalesAmount),
                                DATEADD(DATESMTD(Dates[Date]),-1,YEAR))
     PriorYearQTD               = CALCULATE(SUM(SalesAmount),
                                DATEADD(DATESQTD(Dates[Date]),-1,YEAR))
     PriorYearYTD               = CALCULATE(SUM(SalesAmount),
                                DATEADD(DATESYTD(Dates[Date]),-1,YEAR))
DAX EDITOR
• Code highlighting
• No intellisense
• Free download at http://daxeditor.codeplex.com/
WHAT CAN WE DO WITH DAX
• Create calculated columns
• Create (calculated) measures
• Define security in the model
• Query the BI Semantic Model
ADD SECURITY TO YOUR MODEL USING DAX
WHAT CAN WE DO WITH DAX
• Create calculated columns
• Create (calculated) measures
• Define security in the model
• Query the BI Semantic Model
DAX QUERIES
[DEFINE { MEASURE <tableName>[<name>] = <expression> }

EVALUATE <table>
[ORDER BY {<expression> [{ASC | DESC}]}[, …]
  [START AT {<value>|<parameter>} [, …]]]
DAX QUERIES IN REPORTING SERVICES (SQL DATA TOOLS)
• Create SSAS DataSource
• Create Dataset
• In Query Designer
  • Switch to Command Type DMX
  • Switch to Design Mode
  • Define Parameters
DAX QUERIES IN REPORT BUILDER
•   Query designer does not support DMX!!
•   Create OLEDB Datasource
•   Create Dataset
•   Write the query as an expression
    and concatenate using
    Parameters.ParamName.Value
SO, WHAT CAN WE DO WITH DAX
• Create calculated columns
• Create (calculated) measures
• Define security in the model
• Query the BI Semantic Model

• DAX is Simple, but it’s not always Easy
SOME RESOURCES
• Blogs
  •   http://www.vandeputte.org (Frederik Vandeputte)
  •   http://www.powerpivotblog.nl/ (Kasper De Jonge)
  •   http://sqlblog.com/blogs/marco_russo/ (Marco Russo)
  •   http://sqlblog.com/blogs/alberto_ferrari/ (Alberto Ferrari)
  •   http://cwebbbi.wordpress.com/ (Chriss Webb)
  •   http://javierguillen.wordpress.com/ (Javier Guillén)
• Sites
  • http://social.technet.microsoft.com/wiki/contents/articles/277.powerpivot-
    overview.aspx (PowerPivot Wiki)
  • http://www.powerpivot-info.com/
  • http://www.ssas-info.com
  • www.sqlug.be
  • www.kohera.be
THANK YOU

More Related Content

What's hot

Introduction of ssis
Introduction of ssisIntroduction of ssis
Introduction of ssis
deepakk073
 

What's hot (20)

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 query
Power queryPower query
Power query
 
My tableau
My tableauMy tableau
My tableau
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure Databricks
 
Power BI: From the Basics
Power BI: From the BasicsPower BI: From the Basics
Power BI: From the Basics
 
PowerPivot and PowerQuery
PowerPivot and PowerQueryPowerPivot and PowerQuery
PowerPivot and PowerQuery
 
Introduction of ssis
Introduction of ssisIntroduction of ssis
Introduction of ssis
 
Introduction to AWS Glue
Introduction to AWS Glue Introduction to AWS Glue
Introduction to AWS Glue
 
Building Lakehouses on Delta Lake with SQL Analytics Primer
Building Lakehouses on Delta Lake with SQL Analytics PrimerBuilding Lakehouses on Delta Lake with SQL Analytics Primer
Building Lakehouses on Delta Lake with SQL Analytics Primer
 
Azure DataBricks for Data Engineering by Eugene Polonichko
Azure DataBricks for Data Engineering by Eugene PolonichkoAzure DataBricks for Data Engineering by Eugene Polonichko
Azure DataBricks for Data Engineering by Eugene Polonichko
 
SSAS Tabular model importance and uses
SSAS  Tabular model importance and usesSSAS  Tabular model importance and uses
SSAS Tabular model importance and uses
 
Tableau Prep.pptx
Tableau Prep.pptxTableau Prep.pptx
Tableau Prep.pptx
 
Introduction to AWS Glue
Introduction to AWS GlueIntroduction to AWS Glue
Introduction to AWS Glue
 
Understanding Power BI Data Model
Understanding Power BI Data ModelUnderstanding Power BI Data Model
Understanding Power BI Data Model
 
Intro to Azure Data Factory v1
Intro to Azure Data Factory v1Intro to Azure Data Factory v1
Intro to Azure Data Factory v1
 
SQL
SQLSQL
SQL
 
Power BI Overview
Power BI OverviewPower BI Overview
Power BI Overview
 
Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)
 
Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)
 
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
 

Similar to DAX (Data Analysis eXpressions) from Zero to Hero

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
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
Chris Seebacher
 

Similar to DAX (Data Analysis eXpressions) from Zero to Hero (20)

Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql
 
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
 
Real-world BISM in SQL Server 2012 SSAS
Real-world BISM in SQL Server 2012 SSASReal-world BISM in SQL Server 2012 SSAS
Real-world BISM in SQL Server 2012 SSAS
 
2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power Tools2015 NCAIR Excel Power Tools
2015 NCAIR Excel Power Tools
 
Hello my name is DAX
Hello my name is DAXHello my name is DAX
Hello my name is DAX
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
SQLDay2013_ChrisWebb_DAXMD
SQLDay2013_ChrisWebb_DAXMDSQLDay2013_ChrisWebb_DAXMD
SQLDay2013_ChrisWebb_DAXMD
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Excel patterns in Power BI: From Excel hero to Power BI Champion
Excel patterns in Power BI: From Excel hero to Power BI ChampionExcel patterns in Power BI: From Excel hero to Power BI Champion
Excel patterns in Power BI: From Excel hero to Power BI Champion
 
Getting power bi
Getting power biGetting power bi
Getting power bi
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
From Excel hero to Power BI champion
From Excel hero to Power BI championFrom Excel hero to Power BI champion
From Excel hero to Power BI champion
 
DataSaturday #1 - PBI Modeling At Warp Speed With Tabular Editor Advanced Scr...
DataSaturday #1 - PBI Modeling At Warp Speed With Tabular Editor Advanced Scr...DataSaturday #1 - PBI Modeling At Warp Speed With Tabular Editor Advanced Scr...
DataSaturday #1 - PBI Modeling At Warp Speed With Tabular Editor Advanced Scr...
 
Advanced integration services on microsoft ssis 1
Advanced integration services on microsoft ssis 1Advanced integration services on microsoft ssis 1
Advanced integration services on microsoft ssis 1
 
Implementing Tables and Views.pptx
Implementing Tables and Views.pptxImplementing Tables and Views.pptx
Implementing Tables and Views.pptx
 
Alasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAlasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User Manual
 
Power BI / AAS Model Optimization
Power BI / AAS Model OptimizationPower BI / AAS Model Optimization
Power BI / AAS Model Optimization
 
Power BI / AAS Data Model Optimization 101 v2
Power BI / AAS Data Model Optimization 101 v2Power BI / AAS Data Model Optimization 101 v2
Power BI / AAS Data Model Optimization 101 v2
 
Salesforce Analytics Cloud - Explained
Salesforce Analytics Cloud - ExplainedSalesforce Analytics Cloud - Explained
Salesforce Analytics Cloud - Explained
 

More from Microsoft TechNet - Belgium and Luxembourg

More from Microsoft TechNet - Belgium and Luxembourg (20)

Windows 10: all you need to know!
Windows 10: all you need to know!Windows 10: all you need to know!
Windows 10: all you need to know!
 
Configuration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
Configuration Manager 2012 – Compliance Settings 101 - Tim de KeukelaereConfiguration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
Configuration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
 
Windows 8.1 a closer look
Windows 8.1 a closer lookWindows 8.1 a closer look
Windows 8.1 a closer look
 
So you’ve successfully installed SCOM… Now what.
So you’ve successfully installed SCOM… Now what.So you’ve successfully installed SCOM… Now what.
So you’ve successfully installed SCOM… Now what.
 
Data Leakage Prevention
Data Leakage PreventionData Leakage Prevention
Data Leakage Prevention
 
Deploying and managing ConfigMgr Clients
Deploying and managing ConfigMgr ClientsDeploying and managing ConfigMgr Clients
Deploying and managing ConfigMgr Clients
 
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
 
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware UpdatingHands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
 
SCEP 2012 inside SCCM 2012
SCEP 2012 inside SCCM 2012SCEP 2012 inside SCCM 2012
SCEP 2012 inside SCCM 2012
 
Jump start your application monitoring with APM
Jump start your application monitoring with APMJump start your application monitoring with APM
Jump start your application monitoring with APM
 
What’s new in Lync Server 2013: Persistent Chat
What’s new in Lync Server 2013: Persistent ChatWhat’s new in Lync Server 2013: Persistent Chat
What’s new in Lync Server 2013: Persistent Chat
 
What's new for Lync 2013 Clients & Devices
What's new for Lync 2013 Clients & DevicesWhat's new for Lync 2013 Clients & Devices
What's new for Lync 2013 Clients & Devices
 
Office 365 ProPlus: Click-to-run deployment and management
Office 365 ProPlus: Click-to-run deployment and managementOffice 365 ProPlus: Click-to-run deployment and management
Office 365 ProPlus: Click-to-run deployment and management
 
Office 365 Identity Management options
Office 365 Identity Management options Office 365 Identity Management options
Office 365 Identity Management options
 
SharePoint Installation and Upgrade: Untangling Your Options
SharePoint Installation and Upgrade: Untangling Your Options SharePoint Installation and Upgrade: Untangling Your Options
SharePoint Installation and Upgrade: Untangling Your Options
 
The application model in real life
The application model in real lifeThe application model in real life
The application model in real life
 
Microsoft private cloud with Cisco and Netapp - Flexpod solution
Microsoft private cloud with Cisco and Netapp -  Flexpod solutionMicrosoft private cloud with Cisco and Netapp -  Flexpod solution
Microsoft private cloud with Cisco and Netapp - Flexpod solution
 
Managing Windows RT devices in the Enterprise
Managing Windows RT devices in the Enterprise Managing Windows RT devices in the Enterprise
Managing Windows RT devices in the Enterprise
 
Moving from Device Centric to a User Centric Management
Moving from Device Centric to a User Centric Management Moving from Device Centric to a User Centric Management
Moving from Device Centric to a User Centric Management
 
Network Management in System Center 2012 SP1 - VMM
Network Management in System Center 2012  SP1 - VMM Network Management in System Center 2012  SP1 - VMM
Network Management in System Center 2012 SP1 - VMM
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

DAX (Data Analysis eXpressions) from Zero to Hero

  • 1. DAX (DATA ANALYSIS EXPRESSIONS) FROM ZERO TO HERO Frederik Vandeputte Partner @Kohera President @SQLUG.BE frederik.vandeputte@kohera.be
  • 2. AGENDA • What’s DAX • Calculated columns • Calculated measures • Some common DAX functions • Working with DAX and Dates • Define security in the model • Query the BI Semantic Model
  • 3. DAX - DATA ANALYSIS EXPRESSION • Introduced in PowerPivot v1 • DAX = Data Analysis Expressions • DAX goals • Make data analysis really easy • Uses relationships defined in PowerPivot/BISM model (no need for VLOOKUP) • Excel like Syntax • Support for +/- 80 Excel function • 35 Built in Time Intelligence functions • + Additional function • SQL Server 2012 – Analysis Services Tabular Models
  • 4. BI SEMANTIC MODEL: ARCHITECTURE Third-party Reporting SharePoint Excel PowerPivot applications Services Insights Databases LOB Applications Files OData Feeds Cloud Services
  • 5. WHAT CAN WE DO WITH DAX • Create calculated columns • Create (calculated) measures • Define security in the model • Query the BI Semantic Model
  • 6. 4 IMPORTANT CONCEPTS Calculated Calculated Columns Measures Row Filter Context Context
  • 7. CALCULATED COLUMNS • Just another column in a table • Similar to named calculations in SSAS OLAP Datasource views • Calculated after data has been loaded (cube processing) • Can be placed in colums, rows, filters and slicers • Evaluated in row context • Examples • [Amount] =[Qty] *[Price] • [Full Name] = [First Name] & “ “ & [Last Name]
  • 8. CALCULATED MEASURES • Created in the measure grid • Calculated “on the fly” • Can only be placed in values area of PivotTables • Evaluated in filter context • Rows/Columns/filters/Slicers • Examples • [Sales] = SUM (Sales[Amount]) • [Average Sale] = AVERAGEX ( Sales, Sales[Amount])
  • 9. FILTER CONTEXT • Filter Context = cell in PivotTable [CalendarYear] = 2008 [ChannelName]=”Store” [ContinentName]=”Europe” [RegionCountryName] = “Germany”
  • 10. MEASURES MUST BE EXPLICITELY CREATED • PowerPivot will create implicit measures when you drag a column to the values area in a pivot table • Not possible in BISM (No_ measure defined) • Like in SSAS OLAP – measures must be created explicitely • Eeasiest way: AutoSum in SQL Data Tools
  • 11. SOME COMMON DAX FUNCTIONS • DISTINCTCOUNT() • RELATED() • CALCULATE()
  • 12. RELATED(COLUMN) AND RELATEDTABLE(TABLE) • More powerfull than VLOOKUP • VLOOKUP only returns 1st match • Relies on relationships in PowerPivot • Follows many to one relationship
  • 13. RELATED(COLUMN) FactSales • Storekey • Travels many to one direction • Can travel multiple relationships •Geograpghy DimStore • Add calculated columns to FactSales Key • =RELATED(DimStore[StoreName]) • =RELATED(DimGeography[ContinentName]) DimGeography
  • 14. CALCULATE(EXPRESSION, SETFILTER1, SETFILTER2, …) • CALCULATE more complex than previous functions, but very powerful • CALCULATE is the Queen Of DAX • CALCUATE • Using the SetFilter arguments, modify the Filter Context • If there is a Row Context, move that Row Context onto the Filter Context • Evaluate the Expression in the newly modified Filter Context
  • 15. DAX AND TIME INTELLIGENCE • +/- 35 DAX time intelligence functions • DAX helps you when calculating with dates • But you must follow the rules
  • 16. THE GOLDEN RULES WHEN WORKING WITH DATES • Always create a separate Date table. • Make sure your date table has a continues date range • Create relationships between fact tables and the Date table. • Never use the datetime column from the fact table in time functions. • The datetime column in the Date table should be at day granularity (without fractions of a day). • Mark the Date table as a Date Table and set the Date column.
  • 17. IF YOU DON’T HAVE A SEPERATE TIME TABLE  ERRORS
  • 18. IF YOU HAVE A SEPERATE TIME TABLE  CORRECT VALUES
  • 19. DATE CALCULATIONS • TOTALYTD function • Calculated Year To Date Values • SalesAmtYTD:=TOTALYTD(SUM(AutoSales[SalesAmount]);Dates[Date]) WRONG RESULTS
  • 20. CREATE A DATE DIMENSION • Mark Time Dimension Table as Date • Use data column from Time dimension in Calculations • Sort Columns By key column • Create Hierarchies (in Diagram view) CORRECT RESULTS
  • 21. CREATE THE PERFECT DATE DIMENSION • Follow the golden rules • Sort Columns By key column • Create Hierarchies
  • 22. TIME INTELLIGENCE EXAMPLES FOR SALES Time Period Formula Current Period =SUM([SalesAmount]) MTD = CALCULATE(SUM(SalesAmount), DATESMTD(Dates[Date])) QTD = CALCULATE(SUM(SalesAmount), DATESQTD(Dates[Date])) YTD = CALCULATE(SUM(SalesAmount), DATESYTD(Dates[Date])) Current Period Last Year = CALCULATE(SUM(SalesAmount), DATEADD(Dates[Date],-1,YEAR)) PriorYearMTD = CALCULATE(SUM(SalesAmount), DATEADD(DATESMTD(Dates[Date]),-1,YEAR)) PriorYearQTD = CALCULATE(SUM(SalesAmount), DATEADD(DATESQTD(Dates[Date]),-1,YEAR)) PriorYearYTD = CALCULATE(SUM(SalesAmount), DATEADD(DATESYTD(Dates[Date]),-1,YEAR))
  • 23. DAX EDITOR • Code highlighting • No intellisense • Free download at http://daxeditor.codeplex.com/
  • 24. WHAT CAN WE DO WITH DAX • Create calculated columns • Create (calculated) measures • Define security in the model • Query the BI Semantic Model
  • 25. ADD SECURITY TO YOUR MODEL USING DAX
  • 26. WHAT CAN WE DO WITH DAX • Create calculated columns • Create (calculated) measures • Define security in the model • Query the BI Semantic Model
  • 27. DAX QUERIES [DEFINE { MEASURE <tableName>[<name>] = <expression> } EVALUATE <table> [ORDER BY {<expression> [{ASC | DESC}]}[, …] [START AT {<value>|<parameter>} [, …]]]
  • 28. DAX QUERIES IN REPORTING SERVICES (SQL DATA TOOLS) • Create SSAS DataSource • Create Dataset • In Query Designer • Switch to Command Type DMX • Switch to Design Mode • Define Parameters
  • 29. DAX QUERIES IN REPORT BUILDER • Query designer does not support DMX!! • Create OLEDB Datasource • Create Dataset • Write the query as an expression and concatenate using Parameters.ParamName.Value
  • 30. SO, WHAT CAN WE DO WITH DAX • Create calculated columns • Create (calculated) measures • Define security in the model • Query the BI Semantic Model • DAX is Simple, but it’s not always Easy
  • 31. SOME RESOURCES • Blogs • http://www.vandeputte.org (Frederik Vandeputte) • http://www.powerpivotblog.nl/ (Kasper De Jonge) • http://sqlblog.com/blogs/marco_russo/ (Marco Russo) • http://sqlblog.com/blogs/alberto_ferrari/ (Alberto Ferrari) • http://cwebbbi.wordpress.com/ (Chriss Webb) • http://javierguillen.wordpress.com/ (Javier Guillén) • Sites • http://social.technet.microsoft.com/wiki/contents/articles/277.powerpivot- overview.aspx (PowerPivot Wiki) • http://www.powerpivot-info.com/ • http://www.ssas-info.com • www.sqlug.be • www.kohera.be

Editor's Notes

  1. Carry forward the existing ecosystem of client applicationsLook a bit deeper into the conceptual architectureCall out PowerPivot as a clientMDX versus DAXData access: cache the data or pass it through Vertipaq new in-memorycolunmstore, compression, blazing fast perf. No aggregations or tuning. Same as PowerPivot for Excel and SharePoint.