Data Analysis Expressions in PowerPivot for Excel 2010 Howie Dickerman Microsoft Corporation
Agenda - Data Analysis Expressions (DAX) PowerPivot for Excel and why we need DAX Demo(s) of Data Analysis Expressions How (and where) to use DAX DAX Functions by Category Excel Functions Relationships Aggregation Table Functions Time Intelligence
PowerPivot Add-In for Excel 2010 PowerPivot for Excel Self-Service BI PivotTable(s) based on multiple tables of data Ease-of-use: No need to learn multi-dimensional concepts or specialized languages like MDX Data Analysis Expressions (DAX) Simple Excel style formulas Define new fields in the PivotTable field list Enable Excel users to perform powerful data analysis using the skills they already have
Demo 1 PowerPivot Add-In PowerPivot for Excel 2010 Sample Data PowerPivot ribbon in Excel PowerPivot window Sales [Amount] = [Qty]*[Price] Field List with multiple tables Sales PivotTables by customer/product
Data Analysis Expressions (DAX) DAX uses Excel syntax and many Excel functions No notion of addressing individual cells or ranges DAX functions refer to columns in the data DAX is not a replacement for MDX Sample DAX expression Comment = [First Name] &“ ”& [Last Name] String concatenation just like Excel =SUM(Sales[Amount]) SUM function takes a column name instead of a range of cells =RELATED (Product[Cost]) new RELATED function follows relationship between tables
Beyond Excel – Relational data PowerPivot for Excel works with multiple tables of related data, so DAX provides functions that implement relational database concepts: Filter Tables Aggregate over Tables Follow Relationships (fetch data from a related table) Many-to-One One-to-Many
Demo 2 - RELATED and RELATEDTABLE RELATED, RELATEDTABLE in calc columns: Sales [UnitCost] = RELATED (Product[Cost]) Sales [TotalCost] = [Qty]*[UnitCost] Calc column in 3 other tables fetches related transactions and adds up amounts: [Sales]=SUMX(RELATEDTABLE(Sales),Sales[Amount])
Beyond Excel – Dynamic Aggregation DAX has functions to assist with dynamic aggregation of measures in PivotTables Discovery of Filter Context (e.g. What is current product or year?) Modification of Filter Context (e.g. switch to all products or years) Time Intelligence Functions (e.g. compare values to previous period)
Demo 3 – Examine context with VALUES Demo VALUES in Sales PivotTable (Product) Concept of Filter Context - one formula in many cells Demo auto-complete while entering formulas = Values(Time[Year]) & “-” &Values (Product[Name]) = IF (Values(Time[Year])=2007, “Baseline”, “Other”)
Data Analysis Expressions are used in two places: Calculated Columns and Measures Expression (formula) is evaluated for each row in table Column in table is fully populated with values Values may be placed on Pivot Axis or aggregated and then placed in Values area (as a measure) Measures Named expression (formula) is not evaluated until placed into Values area of a PivotTable Measure is evaluated for each PivotTable cell using the “filter context” for that cell (row & column headers) Some measure calculations cannot be accomplished by aggregating a calculated column (e.g. ratios don’t add)
Demo 4 – Creating Measures Row & Column Labels Checkbox or drag/drop places values on axis Values Area SUM(numeric) or COUNT(non-numeric) Two ways to author measures Choose column from table (and choose agg) Enter custom DAX expression (formula) Each measure evaluated w/distinct context for each PivotTable cell
Functions for following relationships Related (Column) Follow existing many-to-one relationship and fetch the value from the specified column in the related table RelatedTable (Table) Follow existing relationship (either direction) and return table containing matching row(s) from the specified table Note that this returns a table, so must be used as a parameter to another function Ex: = SUMX ( RelatedTable(Sales), Sales[Amount]) Excel doesn’t offer table functions, but DAX needs them for intermediate results. (List of table functions to be shown later.)
DAX Aggregation Functions DAX implements aggregation functions from Excel including SUM, AVERAGE, MIN, MAX, COUNT, but instead of taking multiple arguments (a list of ranges,) they take a reference to a column DAX also adds some new aggregation functions which aggregate any expression over the rows of a table SUMX (Table, Expression) AVERAGEX (Table, Expression) COUNTAX (Table, Expression) MINX (Table, Expression) MAXX (Table, Expression)
More than 80 Excel Functions in DAX Date and Time Information Math and Trig Statistical Text DATE ISBLANK ABS AVERAGE CONCATENATE DATEVALUE ISERROR CEILING, ISO.CEILING AVERAGEA EXACT DAY ISLOGICAL EXP COUNT FIND EDATE ISNONTEXT FACT COUNTA FIXED EOMONTH ISNUMBER FLOOR COUNTBLANK LEFT HOUR ISTEXT INT MAX LEN MINUTE LN MAXA LOWER MONTH Logical LOG MIN MID NOW AND LOG10 MINA REPLACE SECOND IF MOD REPT TIME IFERROR MROUND RIGHT TIMEVALUE NOT PI SEARCH TODAY OR POWER SUBSTITUTE WEEKDAY FALSE QUOTIENT TRIM WEEKNUM TRUE RAND UPPER YEAR RANDBETWEEN VALUE YEARFRAC ROUND ROUNDDOWN ROUNDUP SIGN SQRT SUM SUMSQ TRUNC
DAX Table Functions RelatedTable (Table) Filter (Table, Condition) returns table containing related rows of data Filter (Table, Condition) Returns table filtered to include rows where condition is true Distinct (Column) Returns one column table containing the distinct (unique) values in a column Values (Column) Returns one column table containing valid values in a column in current filter context All (Table), All(Column) Returns all data for the specified object, ignoring context filters and without duplicates AllExcept (Table, Col1, Col2,...) Returns all of the data for the specified table, ignoring any context filters EXCEPT that filters for the specified columns are retained
Changing Context and Calculating formulas in the modified context We provide an entire category of functions which are designed to modify the context and then perform calculations in the modified context. These are the CALCULATE functions and ALL functions which have several variants depending on how we want to modify the context of a calculation. The use of a measure as if it were a function is a useful shorthand notation for the CALCULATE function. =[SalesAmt]/[SalesAmt](All(Product))
Demo 5 – DAX measures Sales Table [SalesAmt] = SUM (Sales [Amount]) [AllProd] = CALCULATE ([SalesAmt], All(Product)) = [SalesAmt] (All(Product) [Cost] = SUM (Sales[TotalCost]) [Margin] = Sales[SalesAmt] – Sales[Cost] [Margin%] = (Sales[SalesAmt] – Sales[Cost]) / [Sales]
35 Time Intelligence Functions Manipulating the time period is a very common requirement for Business Intelligence analysis. Time Intelligence requires a Date column in the data and navigates using that column Time Intelligence functions work with intervals of days, months, quarters, and years, and include: Functions that return a single date Functions that return a table of dates Functions that evaluate expressions over time period
Functions that return a single date FirstDate (Date_Column) LastDate (Date_Column) FirstNonBlank (Date_Column, Expression) LastNonBlank (Date_Column, Expression) StartofMonth (Date_Column) StartofQuarter (Date_Column) StartofYear (Date_Column [,YE_Date]) EndofMonth (Date_Column) EndofQuarter (Date_Column) EndofYear (Date_Column [,YE_Date])
Functions that return a table of dates DateAdd (Date_Column, Number_of_Intervals, Interval) DatesBetween (Date_Column, Start_Date, End_Date) DatesInPeriod (Date_Column, Start_Date, Number_of_Intervals, Interval) ParallelPeriod (Date_Column, Number_of_Intervals, Interval) PreviousDay (Date_Column) PreviousMonth (Date_Column) PreviousQuarter (Date_Column) PreviousYear (Date_Column [,YE_Date]) NextDay (Date_Column) NextMonth (Date_Column) NextQuarter (Date_Column) NextYear (Date_Column [,YE_Date]) DatesMTD (Date_Column) DatesQTD (Date_Column) DatesYTD (Date_Column [,YE_Date]) SamePeriodLastYear (Date_Column)
Functions that evaluate expressions over a time period TotalMTD (Expression, Date_Column [, SetFilter]) TotalQTD (Expression, Date_Column [, SetFilter]) TotalYTD (Expression, Date_Column [, SetFilter] [,YE_Date]) OpeningBalanceMonth (Expression, Date_Column [,SetFilter]) OpeningBalanceQuarter (Expression, Date_Column [,SetFilter]) OpeningBalanceYear (Expression, Date_Column [,SetFilter] [,YE_Date]) ClosingBalanceMonth (Expression, Date_Column [,SetFilter]) ClosingBalanceQuarter (Expression, Date_Column [,SetFilter]) ClosingBalanceYear (Expression, Date_Column [,SetFilter] [,YE_Date])
Demo 6 - Time Intelligence Sales Table [YOYGrowth] = [SalesAmt] – [SalesAmt](DateAdd(Time[Date],-1,Year)) [QTDSales] = TotalQTD ([SalesAmt], Time[Date]) [YearAgo] = [SalesAmt] (ParallelPeriod(Time[Date],-12,Month)) CTP Note: In the CTP3 release, it is necessary to add All(Time) as an additional filter to the Time Intelligence invocations so the time selection won’t be restricted by the current filter context.
Summary DAX formulas use familiar Excel syntax: Calculated Columns (in PowerPivot tables) Measures (in PivotTable UI) Functionality includes: Excel functions (math, statistical, date/time, text, etc.) Aggregation of any expression over a table Table functions (Filter(), RelatedTable(), Distinct(), etc.) Fetch data across relationships (one-many, many-one) Set or modify calculation context (All, Calculate, etc.) Time Intelligence functions
Call To Action / Resources Visit website: http://PowerPivot.com Download these two applications and try out DAX! Microsoft Office 2010 (Beta) SQL Server PowerPivot for Excel 2010 (CTP3 ) Product Team Blog Site: http://blogs.msdn.com/powerpivot DAX Questions? e-mail: howied@microsoft.com
Complete the Evaluation Form & Win! You could win a Dell Mini Netbook – every day – just for handing in your completed form! Each session form is another chance to win! Pick up your Evaluation Form: Within each presentation room At the PASS Booth near registration area Drop off your completed Form: Near the exit of each presentation room Sponsored by Dell
PASS PowerPivot Sweepstakes Become a follower of www.twitter.com/powerpivot Re-tweet our message: “Want to learn more, go to www.powerpivot.com and sign up for CTP #powerpivot” You are entered to win an XBOX 360 We will randomly select a follower who re-tweeted this and announce the winner The results will be posted on Monday, November 9th at www.twitter.com/powerpivot *No Purchase Necessary. Open only to residents 18+ of the 50 US (includes D of C) or Canada (excluding Quebec). Game ends 11/5/09. For full Official Rules, visit www.powerpivot.com/contest
for attending this session and the 2009 PASS Summit in Seattle Thank you for attending this session and the 2009 PASS Summit in Seattle