460 likes | 1.33k Vues
Required Slide. SESSION CODE: BIU302. Enriching Microsoft PowerPivot for Microsoft Excel Applications Using DAX (Data Analysis Expressions). Ashvini Sharma Lead Program Manager SQL Server Analysis Service. Agenda. PowerPivot overview DAX Introduction and concepts. PowerPivot.
E N D
Required Slide SESSION CODE: BIU302 Enriching Microsoft PowerPivot for Microsoft Excel Applications Using DAX (Data Analysis Expressions) Ashvini Sharma Lead Program Manager SQL Server Analysis Service
Agenda • PowerPivot overview • DAX Introduction and concepts
PowerPivot PowerPivot For Excel 2010 PowerPivot For SharePoint 2010 Sharing PowerPivot content in SharePoint Usage monitoring by IT SQL Server 2008R2 for SharePoint 2010 Any AS client app can connect, multi-user DAX is invisible here • Authoring PowerPivot content in Excel • Free download for Excel 2010 • Desktop, single user experience • DAX formulas written here
PowerPivot for Excel Quick walkthrough DEMO
PowerPivot Add-In for Excel • Self-Service BI • PivotTable(s) based on multiple tables of data • Ease-of-use: No need to learn Multi-Dimensional anything • Data Analysis Expressions (DAX) • Simple Excel style formulas • Enable Excel users to do powerful data analysis using their existing skills
Calculated Columns DEMO
Demo 1 - PowerPivot & Calculated Columns • Launch workbook – see PowerPivot Ribbon • Navigate between Excel & PowerPivot windows • Ten tables from Contoso • Two calculated columns • Margin = [SalesAmount]–[TotalCost] • MarginPct = ([SalesAmount]-[TotalCost])/[SalesAmount] • Show PivotTable field list with multiple tables
Calculated Columns • Formula is evaluated for each row • Results are stored back into PowerPivot as any other column • Columns can be used for both slicing data and summarizing values • Part of the model, available for use in any PivotTable • Usable by other AS clients in PowerPivot for SharePoint
Data Analysis Expressions (DAX) • Uses Excel syntax and has many of the Excel functions • Functions refer to columns, not individual cells or ranges [Cost] or Product[Cost] or ‘Product Category’[Category Name]
Beyond Excel You Are Here
Demo 2 - RELATED and RELATEDTABLE • RELATED and RELATEDTABLE in calculated columns • RELATED ProductColor = RELATED (DimProduct[ColorName]) StoreCity = RELATED (DimGeography[CityName]) • RELATEDTABLE =SUMX(RELATEDTABLE(FactSales),FactSales[SalesAmount]) Identical formula can be placed in multiple tables!
Following relationships • Related (Column) • Fetches a value from a related table • Works when going from the many-side to one-side of a relationship • Blank returned back for missing values • Can make multiple hops = RELATED(DimStore[StoreName]) = RELATED(DimGeography[ContinentName])
Beyond Calculated Columns Summarizing numeric and non-numeric data in PivotTables DEMO
Demo 3 – 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 aggregation) • Enter custom DAX expression (formula) • Each measure evaluated w/distinct context for each PivotTable cell
Demo 3 – Show Filter Context • Show filter context
Calculated Measures • Evaluated dynamically per value in PivotTable • Part of the model, available to other PivotTables • Usable by any AS client through PowerPivot for SharePoint
DAX Aggregation Functions • SUM, AVERAGE, MIN, MAX, COUNT take column references • Extensions aggregate an expression over the rows of a table • SUMX (Table, Expression) • AVERAGEX (Table, Expression) • COUNTAX (Table, Expression) • MINX (Table, Expression) • MAXX (Table, Expression) • COUNTROWS (Table)
Table Functions SUMX, RELATEDTABLE DEMO
Demo 4 – Calculated Column with Table Function • =SUMX(RELATEDTABLE(FactSales),FactSales[SalesAmount])
Changing Filter Context • Changing filter context is very common in BI • Sales in all channels vs. Sales in Stores only • Sales of a product vs. Sales of All products • Sales in a region vs. Sales in All Regions • Can enable measures to be resilient to multiple PivotTable layouts • CALCULATE (Expression [, SetFilter1][, SetFilter2]...) = CALCULATE([Sales], DimChannel[ChannelName]="Store") = CALCULATE([Sales], ALL(DimProduct)) = [Sales](ALL(DimProduct)) <- Shortcut for previous statement
Changing Filter Context Using CALCULATE DEMO
Demo 5 – CALCULATE and Measures [Sales] =SUM(FactSales[SalesAmount]) [StoreSales] =CALCULATE([Sales],DimChannel[ChannelName]="Store") = [Sales](DimChannel[ChannelName]="Store") [PctAllRegions] =[Sales] / CALCULATE([Sales],ALL(DimGeography)) =[Sales] / [Sales](ALL(DimGeography))
Quiz! Calculating RANK • Rank: (Number of customers that have more sales than the customer) + 1 DimCustomer[CustomerRank] = COUNTROWS ( FILTER ( ALL (DimCustomer [CustomerName]), [CustomerSales] > [CustomerSales] (VALUES (DimCustomer [CustomerName])) ) ) + 1 Sales for Filter Context from PivotTable Sales for current row in the table being filtered
Quiz! Calculating RANK • Rank: (Number of customers that have more sales than the customer) + 1 DimCustomer[CustomerRank] = COUNTROWS ( FILTER ( ALL (DimCustomer [CustomerName]), [CustomerSales] > [CustomerSales] (VALUES (DimCustomer [CustomerName])) ) ) + 1
Time Intelligence Functions • Built-in 35 functions that update filter context for time based analysis • Require a Date column in the data joined to a Date table • Work with intervals of days, months, quarters, and years • 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])
Time Intelligence DEMO
Demo 6 - Time Intelligence [YOY Growth] =[Sales]- [Sales](PREVIOUSYEAR(DimDate[Datekey])) [PrevYearSales] =IF( COUNTROWS(VALUES(DimDate[CalendarYear]))=1 , [Sales](PARALLELPERIOD(DimDate[Datekey],-12,MONTH)), BLANK() ) [PctGrowth] =IF( [PrevYearSales], ([Sales]-[PrevYearSales])/[PrevYearSales], BLANK() )
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
Required Slide Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Links • DAX Whitepaper and Samples on http://www.microsoft.com/downloads • PowerPivot team blog on http://blogs.msdn.com/powerpivot • Other good resources: • www.powerpivot.com • www.powerpivot-info.com • http://powerpivotfaq.com/ • www.powerpivotpro.com
Required Slide Speakers, please list the Breakout Sessions, Interactive Sessions, Labs and Demo Stations that are related to your session. Related Content • BIU02-INT – Budgeting Solution Built with PowerPivotThursday, June 10 | 1:30 PM - 2:45 PM | Rm 240 • BIU02-HOL – Defining DAX Calculations with MS PowerPivot for MS Excel 2010
Required Slide Complete an evaluation on CommNet and enter to win!
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
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)