DAX (Data Analysis eXpressions) from Zero to Hero

5,784 views

Published on

Presented by Frederik Vandeputte.

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,784
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
343
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide
  • 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.
  • DAX (Data Analysis eXpressions) from Zero to Hero

    1. 1. DAX (DATA ANALYSIS EXPRESSIONS)FROM ZERO TO HEROFrederik VandeputtePartner @KoheraPresident @SQLUG.BEfrederik.vandeputte@kohera.be
    2. 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. 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. 4. BI SEMANTIC MODEL: ARCHITECTURE Third-party Reporting SharePoint Excel PowerPivot applications Services Insights Databases LOB Applications Files OData Feeds Cloud Services
    5. 5. WHAT CAN WE DO WITH DAX• Create calculated columns• Create (calculated) measures• Define security in the model• Query the BI Semantic Model
    6. 6. 4 IMPORTANT CONCEPTS Calculated Calculated Columns Measures Row Filter Context Context
    7. 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. 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. 9. FILTER CONTEXT• Filter Context = cell in PivotTable [CalendarYear] = 2008 [ChannelName]=”Store” [ContinentName]=”Europe” [RegionCountryName] = “Germany”
    10. 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. 11. SOME COMMON DAX FUNCTIONS• DISTINCTCOUNT()• RELATED()• CALCULATE()
    12. 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. 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. 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. 15. DAX AND TIME INTELLIGENCE• +/- 35 DAX time intelligence functions• DAX helps you when calculating with dates• But you must follow the rules
    16. 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. 17. IF YOU DON’T HAVE A SEPERATE TIME TABLE  ERRORS
    18. 18. IF YOU HAVE A SEPERATE TIME TABLE  CORRECT VALUES
    19. 19. DATE CALCULATIONS• TOTALYTD function • Calculated Year To Date Values • SalesAmtYTD:=TOTALYTD(SUM(AutoSales[SalesAmount]);Dates[Date]) WRONG RESULTS
    20. 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. 21. CREATE THE PERFECT DATE DIMENSION• Follow the golden rules• Sort Columns By key column• Create Hierarchies
    22. 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. 23. DAX EDITOR• Code highlighting• No intellisense• Free download at http://daxeditor.codeplex.com/
    24. 24. WHAT CAN WE DO WITH DAX• Create calculated columns• Create (calculated) measures• Define security in the model• Query the BI Semantic Model
    25. 25. ADD SECURITY TO YOUR MODEL USING DAX
    26. 26. WHAT CAN WE DO WITH DAX• Create calculated columns• Create (calculated) measures• Define security in the model• Query the BI Semantic Model
    27. 27. DAX QUERIES[DEFINE { MEASURE <tableName>[<name>] = <expression> }EVALUATE <table>[ORDER BY {<expression> [{ASC | DESC}]}[, …] [START AT {<value>|<parameter>} [, …]]]
    28. 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. 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. 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. 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
    32. 32. THANK YOU

    ×