• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Hello my name is DAX
 

Hello my name is DAX

on

  • 1,397 views

Learn the basics of how to use DAX in PowerPivot to create new columns, join tables, and define new aggregate measures.

Learn the basics of how to use DAX in PowerPivot to create new columns, join tables, and define new aggregate measures.

Statistics

Views

Total Views
1,397
Views on SlideShare
1,395
Embed Views
2

Actions

Likes
5
Downloads
53
Comments
1

2 Embeds 2

https://twitter.com 1
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • C:SQLSaturday/DAX/Contoso/Contoso Data From SQL Server.xlsx=FactSales[SalesAmount] – FactSales[TotalCost] – FactSales[ReturnAmount]
  • C:SQLSaturday/DAX/Contoso/Contoso Data From SQL Server.xlsx=(Related(DimProduct[UnitPrice]) – Related(DimProduct[UnitCost])) * FactSales[SalesQuantity]
  • Load: C:SQLSaturday/DAX/Vaccinations2Time
  • C:SQLSaturday/DAX/Vaccinations2Time
  • Load: C:SQLSaturday/DAX/NCAA/NCAA_MultiColumn_Link
  • C:SQLSaturday/DAX/NCAA/NCAA_MultiColumn_Link= [@[Institution_ID]] & "-" & [@[Uniform_Number]] & "-" & [@[Last_Name]] & "-" & [@[First_Name]]
  • Reload C:SQLSaturday/DAX/Vaccinations2Time if necessary at this point
  • C:SQLSaturday/DAX/Vaccinations2Time=COUNTROWS(DISTINCT(Patient_Vaccinations[VisitID]))
  • C:SQLSaturday/DAX/Contoso/Contoso Data From SQL Server.xlsx

Hello my name is DAX Hello my name is DAX Presentation Transcript

  • Michael P. AntonovichBlog: http://SharePointMike.WordPress.comIT PRO Camp - Jacksonville 2012
  • • User‟s Guide to the Apple ][ - 1983• FoxPro 2 Programming Guide – 1992• Debugging and Maintaining FoxPro – 1992• Using Visual FoxPro 3.0 – 1995• Using Visual FoxPro 5.0 – 1996• Office and SharePoint User’s Guide – 2007• Office and SharePoint User’s Guide – 2010 Speaker at: Code Camp 2009, 2010, 2011, 2012 Orlando SharePoint Saturday 2011 Tampa, 2012 Orlando SQL Saturday - #1, #4, #8, #10, #15, #16, #21, #32, #38, #49, #62, #74, #79, #85, #86, #110, #1306/16/2012 IT Pro Camp - Jacksonville 2012 2
  • • DAX stands for: Data Analysis Expressions• DAX is used in PowerPivot to: • Create calculated columns • Create custom measures6/16/2012 IT Pro Camp - Jacksonville 2012 3
  • • Aggregate – A mathematical function that allows you to summarize values of an attribute• Dimension - A dimension is essentially a look-up table that may define a hierarchy or drill-down path such as Year > Quarter > Month• Measure – A measure is something that identifies a value• Fact – A fact is another term for a measure that contains numeric data that can be grouped along one or more dimensional hierarchy• Star Schema – All dimension tables radiate out from a single fact table• Snowflake Schema – One fact table may relate to another fact table before relating to dimension tables. One dimension table can also have a related dimension table• A Pivot table or chart is usually based around a single fact table6/16/2012 IT Pro Camp - Jacksonville 2012 4
  • • PowerPivot is a data analysis tool• PowerPivot is a free download from Microsoft• PowerPivot lets you process millions of rows of data• PowerPivot uses as much memory as available & multi-cores• PowerPivot lets you integrate data from multiple sources• PowerPivot lets you explore, analyze and create analysis• PowerPivot was originally called: Project „Gemini‟ 6/16/2012 IT Pro Camp - Jacksonville 2012 5
  • • 32-or 64 bit Operating System• 1 GB of RAM, 2 GB recommended (or more)• Windows XP with SP3, Vista with SP1, Windows 7• .NET Framework 3.5 SP1 or better• Microsoft Office 20106/16/2012 IT Pro Camp - Jacksonville 2012 6
  • • Fewer data requests since staff can slice and dice their own data• More control over data other people can access• Users can generate their own reports• PowerPivot gives SQL Server data access to the masses6/16/2012 IT Pro Camp - Jacksonville 2012 7
  • • Simple Calculations • Calculated columns within fact tables • Calculated columns for dimension tables • Calculated columns between tables • Calculated columns to serve as links to tables using multiple columns (Calculated columns are calculated for every row in the table)• Aggregate Calculations • Calculate unique measures (Aggregate measures are only calculated for the displayed data in the Pivot table)6/16/2012 IT Pro Camp - Jacksonville 2012 8
  • • Comprised of 135 functions• 71 functions are similar to Excel functions • 69 have the same name – 2 do not • TEXT  FORMAT • DATEDIF  YEARFRAC• 64 functions are unique to DAX • Aggregate data functions • Date related functions6/16/2012 IT Pro Camp - Jacksonville 2012 9
  • • DAX expressions always begin with an equal sign: =• Column References can be qualified or unqualified • TableName[ColumnName] • [ColumnName]6/16/2012 IT Pro Camp - Jacksonville 2012 10
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 11
  • • To concatenate first and last name: = Table1[First_Name] & “-” & Table2[Last_Name] • To calculate a new measure value like Total_Profit = Table1[Total_Revenue] – Table1[Total Cost] – Table1[Returns]6/16/2012 IT Pro Camp - Jacksonville 2012 12
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 13
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 14
  • • Wrong way = DimProduct(Unit_Price) – DimProduct(Unit_Cost)• Right way = RELATED(DimProduct(Unit_Price)) – RELATED(DimProduct(Unit_Cost))6/16/2012 IT Pro Camp - Jacksonville 2012 15
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 16
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 17
  • • Often you will need to build a Date Dimension table based on the minimum and maximum dates in your fact table.• Date Dimension tables are relatively easy to build using DAX formulas. Or you can build them in SQL Server using T-SQL. You can even build the table in Excel and use standard Excel functions.6/16/2012 IT Pro Camp - Jacksonville 2012 18
  • =DATE(<year>, <month>, <day>) =DATEVALUE(<date_text>) =DAY(<date>) =EDATE(<start_date>, <months>) =EOMONTH(<start_date>, <months>) =HOUR(<datetime>) =MINUTE(<datetime>) =MONTH(<datetime>) =NOW() =SECOND(<datetime>) =TIME(<hour>, <minute>, <second>) =TIMEVALUE(<time_text>) =TODAY() =WEEKDAY(<datetime>) =WEEKNUM(<date>, <return_type>) =YEAR(<date>) =YEARFRAC(<start_date>, <end_date>, <basis>)6/16/2012 IT Pro Camp - Jacksonville 2012 19
  • • Get the Year: =YEAR(Patient_Vaccinations[VisitDate])• Get Month Number: =FORMAT(MONTH(Patient_Vaccinations[VisitDate]),"00") =FORMAT(Patient_Vaccinations[VisitDate],”MM”)• Get name of the month =FORMAT(Patient_Vaccinations[VisitDate],"MMM")• Get name of the week day =FORMAT(WEEKDAY(Patient_Vaccinations[VisitDate]), "dddd")6/16/2012 IT Pro Camp - Jacksonville 2012 20
  • • Calculating Quarter of Year =INT((MONTH(Patient_Vaccinations[VisitDate])-1)/3)+1• Calculating Quarter of Year Name ="Qtr " &INT((MONTH(Patient_Vaccinations[VisitDate])- 1)/3)+1• Get week number of year =WEEKNUM(Patient_Vaccinations[VisitDate])6/16/2012 IT Pro Camp - Jacksonville 2012 21
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 22
  • • Problem: • PowerPivot can only link two tables based on a single column. • You need to link two tables using two or more columns.• Solution: • Use DAX to create a calculated column that combines the data from the two columns in each table. • Typically when combining the data from multiple columns, it implies first a conversion of the column data to strings and then the string versions of the column data are the concatenated.6/16/2012 IT Pro Camp - Jacksonville 2012 23
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 24
  • • Standard measures are aggregated using one of the following aggregate functions: • COUNTA (count non-empty cells) • SUM • MIN • MAX • AVERAGENote: List says COUNT, not COUNTA but it uses the COUNTAfunction6/16/2012 IT Pro Camp - Jacksonville 2012 25
  • • When you right click a measure, you can select from one of the following calculation types: • % of Grand Total • % of Column Total • % of Row Total • % of … • % of Parent Row Total • % of Parent Column Total • % of Parent Total … • Difference from … • % Difference from … • Running Total In … • Rank Smallest to Largest … • Rank Largest to Smallest …6/16/2012 IT Pro Camp - Jacksonville 2012 26
  • % of Parent Row % of Grand Total6/16/2012 IT Pro Camp - Jacksonville 2012 27
  • • Sometimes you need a DAX measure that is not built-in. For example, suppose you want to display the number of distinct values as a function of other dimensions, not a total count.6/16/2012 IT Pro Camp - Jacksonville 2012 28
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 29
  • • COUNT – Number of cells that contain numbers• COUNTA – Number of cells that contain numbers or blanks• COUNTBLANK – Counts blank cells in a column• AVERAGEA – Average based on all non-empty cells• MAXA – Largest value in column including blanks and logical values• MINA - Smallest value in column including blanks and logical values• CALCULATE – Overrides existing pivot table filters• FILTER – Applies against existing pivot table filters6/16/2012 IT Pro Camp - Jacksonville 2012 30
  • • DAX expressions are calculated independently for every cell, even total rows and total columns• One DAX expression can include another embedded DAX expression. (average profit per visit) = SUM(FactSales[TotalProfit]) / FactSales[DistinctSales] By default, DAX expressions obey filters. Sometime you need to ignore filters as in: (This is the same as % of Total) =SUM(FactSales[TotalProfit])/ CALCULATE(SUM(FactSales[TotalProfit]),ALL(FactSales)) • There are 35 time intelligence functions not covered here.6/16/2012 IT Pro Camp - Jacksonville 2012 31
  • • Download PowerPivot at • http://www.powerpivot.com/download.aspx• PowerPivot Sample Data • http://powerpivotsampledata.codeplex.com• PowerPivot Tutorial Data • http://technet.microsoft.com/en-us/library/ee835510.aspx• DAX On-line Function Reference • http://technet.microsoft.com/en-us/library/ff452127.aspx • http://social.technet.microsoft.com/wiki/contents/articles/powerpivot -dax-text-functions.aspx6/16/2012 IT Pro Camp - Jacksonville 2012 32
  • 6/16/2012 IT Pro Camp - Jacksonville 2012 33
  • Don‟t forget to fill out yourevaluations.Mike@micmin.orgSharePoint Book Site: http://sharepointmike.wordpress.com/ 6/16/2012 IT Pro Camp - Jacksonville 2012 34