Download presentation
Presentation is loading. Please wait.
Published byJeffrey Preston Modified over 8 years ago
1
Level 200 Let‘s learn DAX Tomislav Piasevoli Piasevoli analitika d.o.o.
2
Level 200 Goals Understand the philosophy behind DAX Learn the basic expressions and queries Become interested in learning more about DAX
3
Level 200 WINDAYS12 TECHNOLOGY OBRAZOVNI PARTNER 1.Introduction to DAX 2.Types of function 3.Examples of DAX expressions 4.Examples of DAX queries 5.Summary Contents
4
Level 200 Data Analysis Expressions (DAX) A new calculation and query language Used in PowerPivot for Excel 2010 and Microsoft SQL Server 2012 Analysis Services Tabular models Calculations Enrich the data models so that you can get the most of your data Queries Retrieve the data from the models in an easy to consume format (flat format)
5
Level 200 Calculated columns Columns defined in the table using a DAX expression and a name Values are populated and stored in the model Calculated columns can be placed onto all PivotTable’s area (Rows, Columns, Filter and Slicers) except the Values area * Columns can be used in measure’s definition Example: Margin defined as = [Sales Amount] - [Total Product Cost] * in PowerPivot a measures is automatically created for the column dragged into the Values area, so in that respect, a columns „can be placed“ in any area
6
Level 200 Measures DAX expressions defined in the Measure Grid (or in PowerPivot Field List in Excel) Measures can be added to the Values area of the PivotTable The formula is evaluated on the fly for each cell in the Values area The result is never stored nor cached Example: Total Sales := SUM( [Sales Amount] ) In Measure Grid measures are defined using := In PowerPivot Field List in Excel measures are defined using =
7
Level 200 Contexts ROW CONTEXT Inside a table Defined by a row in a table Typically for calculated columns FILTER CONTEXT Inside PowerPivot table Defined by rows, columns, filter and slicers Typically for measures
8
Level 200 Other useful info Reference columns using this syntax: Table[Column] Column name must be unique within a table Measure name must be unique across the model Split measures, but don’t split calculated columns Various data types are supported Expressions must return a scalar, but intermediate results can be tables as well
9
Level 200 Types of functions * Easy to use and understand Math and Trig Logical and Information Text Date/Time Intermediate difficulty Statistical Navigation Time Intelligence Difficult to grasp and use Context-related * the way I see them
10
Level 200 Math and Trig functions ABS, SIGN, ROUND, MROUND, ROUNDUP, ROUNDDOWN, CEILING, ISO.CEILING, FLOOR, INT, TRUNC, QUOTIENT EXP, LN, LOG, LOG10 POWER, SQRT, FACT RAND, RANDBETWEEN PI
11
Level 200 Logical and Information functions AND, OR, NOT FALSE, TRUE IF, IFERROR, SWITCH ISBLANK, ISERROR, ISLOGICAL, ISNONTEXT, ISNUMBER, ISTEXT
12
Level 200 Text functions LEFT, RIGHT, MID, LEN, TRIM, SEARCH, FIND LOWER, UPPER FORMAT, FIXED CONCATENATE REPLACE, SUBSTITUTE EXACT BLANK, REPT, VALUE
13
Level 200 Date/Time functions DAY, MONTH, YEAR, HOUR, MINUTE, SECOND, WEEKDAY, WEEKNUM, YEARFRAC NOW, TODAY DATE, DATEVALUE, TIME, TIMEVALUE EDATE, EOMONTH
14
Level 200 Statistical functions SUM, SUMX, MAX, MAXA, MAXX, MIN, MINA, MINX, AVERAGE, AVERAGEA, AVERAGEX, COUNT, COUNTA, COUNTAX, COUNTX, COUNTBLANK, COUNTROWS, DISTINCTCOUNT, SUMMARIZE, TOPN Aggregate the data, that is, reduce the table horizontally (rows) CROSSJOIN, GENERATE, GENERATEALL, ROW, ADDCOLUMN Expand the table vertically (more rows) and/or horizontally (more columns) RANKX, RANK.EQ, STDEV.P, STDEV.S, STDEVX.P, STDEVX.S, VAR.P, VAR.S, VARX.P, VARX.S Calculate statistical values
15
Level 200 Navigation functions CONTAINS, LOOKUPVALUE Used for checking the existance or returning a value PATH, PATHLENGTH, PATHITEM, PATHITEMREVERSE, PATHCONTAINS Used for parent-child relationships RELATED, RELATEDTABLE Get a column/table from related table
16
Level 200 Context-related functions DISTINCT, VALUES Get (distinct) values in the context HASONEVALUE, HASONEFILTER, FILTERS, ISCROSSFILTERED, ISFILTERED Check the context FILTER Restrict the context ALL, ALLEXCEPT, ALLNOBLANKROW, ALLSELECTED Loosen up the context CALCULATE, CALCULATETABLE Jump out of the current context and create a new one EARLIER, EARLIEST Link two contexts (row-based recursion)
17
Level 200 Time Intelligence functions ½ * FIRSTDATE, FIRSTNONBLANK, LASTDATE, LASTNONBLANK Move back/forth to the edge of the context down on the leaf level STARTOFMONTH, STARTOFQUARTER, STARTOFYEAR, ENDOFMONTH, ENDOFQUARTER, ENDOFYEAR Move back/forth to the edge of the context on an upper level PREVIOUSDAY, PREVIOUSMONTH, PREVIOUSQUARTER, PREVIOUSYEAR, NEXTDAY, NEXTMONTH, NEXTQUARTER, NEXTYEAR Move back/forth in the context by one member only DATEADD Change the date DATESBETWEEN, DATESINPERIOD, PARALLELPERIOD, SAMEPERIODLASTYEAR Get a set of dates for typical point-in-time calculations DATESMTD, DATESQTD, DATESYTD Get a period-to-date set of dates * Return dates
18
Level 200 Time Intelligence functions 2/2 * TOTALMTD, TOTALQTD, TOTALYTD Calculate the value of an expression for a period-to-date set of dates CLOSINGBALANCEMONTH, CLOSINGBALANCEQUARTER, CLOSINGBALANCEYEAR, OPENINGBALANCEMONTH, OPENINGBALANCEQUARTER, OPENINGBALANCEYEAR Calculate typical inventory/state calculations * Evaluate expressions
19
Level 200 DAX expressions
20
Level 200 DAX expressions example 1 =[FirstName] & " " & [LastName] Profit:=[Sales] - [Cost] Profit%:=[Profit] / [Sales] Sales YTD (Ordered):=TOTALYTD([Sales]; 'Date'[Date]) Sales YTD (Shipped):=TOTALYTD(CALCULATE([Sales]; USERELATIONSHIP(ResellerSales[ShipDateKey]; 'Date'[DateKey])); 'Date'[Date])
21
Level 200 DAX expressions example 2 Quota:=IF(HASONEVALUE('Date'[Month]); CALCULATE(SUM([SalesAmountQuota]); ALL('Date'[Month])) / 3; SUM([SalesAmountQuota]))
22
Level 200 DAX expressions example 3 =LOOKUPVALUE(Salesperson[SalesTerritoryKey]; Salesperson[LoginID]; USERNAME()) = [SalesTerritoryKey]
23
Level 200 DAX expressions example 4 =PATH([EmployeeKey]; [ParentEmployeeKey]) =LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 1)) =LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 2)) =LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 3)) =LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 4)) =LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 5))
24
Level 200 DAX expressions example 5 =IF(ISBLANK(PATHITEM([Path]; 2)); "(" & LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEMREVERSE([Path]; 1)) & " data)"; LOOKUPVALUE([Salesperson]; [EmployeeKey]; PATHITEM([Path]; 2)) )
25
Level 200 DAX expressions example 6 Internet Distinct Count Sales Order:=DISTINCTCOUNT([Sales Order Number]) Internet Order Lines Count:=COUNT([Sales Order Line Number])
26
Level 200 DAX expressions example 7 =[Sales Amount]-[Total Product Cost] Internet Total Margin:=SUM([Margin]) Internet Previous Quarter Margin:=CALCULATE([Internet Total Margin];PREVIOUSQUARTER('Date'[Date])) Internet Current Quarter Margin:=TOTALQTD([Internet Total Margin];'Date'[Date])
27
Level 200 DAX expressions example 8 Days in Current Quarter:=COUNTROWS( DATESBETWEEN( 'Date'[Date]; STARTOFQUARTER( LASTDATE('Date'[Date])); ENDOFQUARTER('Date'[Date]))) Days Current Quarter to Date:=COUNTROWS( DATESQTD( 'Date'[Date]))
28
Level 200 DAX expressions example 9 =RELATED('Product Category'[Product Category Name]) =RELATED('Product Subcategory'[Product Subcategory Name]) =RIGHT(" " & FORMAT([Day Number Of Week];"#0"); 2) & " - " & [Day Name] =SUMX(RELATEDTABLE(FactSales);FactSales[SalesAmount]) =RANK.EQ([UnitPrice]; [UnitPrice]; 1)
29
Level 200 DAX Queries
30
Level 200 DAX Query syntax [DEFINE { MEASURE [ ] = }] EVALUATE [ORDER BY { [{ASC | DESC}]} [, …] [START AT { | } [, …]] ]
31
Level 200 DAX Query example 1 EVALUATE 'Product' ORDER BY Product[Category] ASC, Product[Subcategory] ASC, Product[Product] START AT "Bikes", "Road Bikes"
32
Level 200 DAX Query example 2 EVALUATE FILTER( 'ResellerSales', 'ResellerSales'[Sales] > 22000 )
33
Level 200 DAX Query example 3 EVALUATE SUMMARIZE( Product, 'Product'[Color], "No of Products", COUNTROWS( Product ) ) ORDER BY 'Product'[Color]
34
Level 200 DAX Query example 4 DEFINE MEASURE 'ResellerSales'[Avg Sales] = AVERAGE( 'ResellerSales'[SalesAmount] ) EVALUATE SUMMARIZE( 'ResellerSales', 'Date'[Year], 'Date'[Month], "Avg Sales", 'ResellerSales'[Avg Sales] )
35
Level 200 DAX Query example 5 EVALUATE ADDCOLUMNS ( GENERATE( VALUES(DimGeography[ContinentName]), TOPN(5, VALUES(DimProduct[ProductName]), [Sales])), "Sales", [Sales] ) ORDER BY DimGeography[ContinentName], [Sales] DESC
36
Level 200 WINDAYS12 TECHNOLOGY OBRAZOVNI PARTNER DAX can be used to define calculated columns and measures and hence enrich the data model There is a row context and a filter context Most of DAX functions are easy to understand and use Functions that deal with context are difficult to start with DAX can also be used to write queries against Tabular SSAS models Although all existing clients should support querying Tabular models using MDX, a better performance might be achieved using DAX Summary
37
Level 200 QUESTIONS? After the session please fill out the questionnaire. Questionnaires will be sent to you by e-mail and will be available in the profile section of the NT Conference website www.ntk.si.www.ntk.si Thank you!
38
Level 200 WINDAYS12 TECHNOLOGY OBRAZOVNI PARTNER MSDN – DAX Reference http://msdn.microsoft.com/en-us/library/gg413422 DAX Resource Center http://social.technet.microsoft.com/wiki/contents/articles/1088.dax- resource-center.aspx Blogs Marco Russohttp://sqlblog.com/blogs/marco_russohttp://sqlblog.com/blogs/marco_russo Alberto Ferrarihttp://sqlblog.com/blogs/alberto_ferrarihttp://sqlblog.com/blogs/alberto_ferrari Chris Webbhttp://cwebbbi.wordpress.comhttp://cwebbbi.wordpress.com Rob Colliehttp://www.powerpivotpro.comhttp://www.powerpivotpro.com Links
39
Level 200 Related contents: Grega Jerkič: What’s new in PowerPivot 2012 next session (16:15) in Europa A http://msdn.microsoft.com/en-us/library/gg413422
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.