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•  ...
• DAX stands for: Data Analysis Expressions• DAX is used in PowerPivot to:    • Create calculated columns    • Create cust...
• Aggregate – A mathematical function that allows you to  summarize values of an attribute• Dimension - A dimension is ess...
•   PowerPivot is a data analysis tool•   PowerPivot is a free download from Microsoft•   PowerPivot lets you process mill...
•   32-or 64 bit Operating System•   1 GB of RAM, 2 GB recommended (or more)•   Windows XP with SP3, Vista with SP1, Windo...
• Fewer data requests since staff can slice and dice  their own data• More control over data other people can access• User...
• Simple Calculations    • Calculated columns within fact tables    • Calculated columns for dimension tables    • Calcula...
• Comprised of 135 functions• 71 functions are similar to Excel functions    • 69 have the same name – 2 do not       • TE...
• DAX expressions always begin with an equal sign: =• Column References can be qualified or unqualified    • TableName[Col...
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 ...
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)) –    RELAT...
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 D...
=DATE(<year>, <month>, <day>)            =DATEVALUE(<date_text>)            =DAY(<date>)            =EDATE(<start_date>, <...
• Get the Year:       =YEAR(Patient_Vaccinations[VisitDate])• Get Month Number:      =FORMAT(MONTH(Patient_Vaccinations[Vi...
• Calculating Quarter of Year       =INT((MONTH(Patient_Vaccinations[VisitDate])-1)/3)+1• Calculating Quarter of Year Name...
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 o...
6/16/2012   IT Pro Camp - Jacksonville 2012   24
• Standard measures are aggregated using one of the following  aggregate functions:            • COUNTA (count non-empty c...
• When you right click a measure, you can select from one of  the following calculation types:    •   % of Grand Total    ...
% of Parent Row            % of Grand Total6/16/2012                      IT Pro Camp - Jacksonville 2012                 ...
• Sometimes you need a DAX measure that is not built-in.   For example, suppose you want to display the number of   distin...
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 – Cou...
• DAX expressions are calculated independently for every  cell, even total rows and total columns• One DAX expression can ...
• Download PowerPivot at    • http://www.powerpivot.com/download.aspx• PowerPivot Sample Data    • http://powerpivotsample...
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...
Upcoming SlideShare
Loading in …5
×

Hello my name is DAX

1,623 views

Published on

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

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total views
1,623
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
67
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide
  • 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]] &amp; &quot;-&quot; &amp; [@[Uniform_Number]] &amp; &quot;-&quot; &amp; [@[Last_Name]] &amp; &quot;-&quot; &amp; [@[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

    1. 1. Michael P. AntonovichBlog: http://SharePointMike.WordPress.comIT PRO Camp - Jacksonville 2012
    2. 2. • 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
    3. 3. • 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
    4. 4. • 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
    5. 5. • 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
    6. 6. • 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
    7. 7. • 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
    8. 8. • 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
    9. 9. • 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
    10. 10. • 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
    11. 11. 6/16/2012 IT Pro Camp - Jacksonville 2012 11
    12. 12. • 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
    13. 13. 6/16/2012 IT Pro Camp - Jacksonville 2012 13
    14. 14. 6/16/2012 IT Pro Camp - Jacksonville 2012 14
    15. 15. • 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
    16. 16. 6/16/2012 IT Pro Camp - Jacksonville 2012 16
    17. 17. 6/16/2012 IT Pro Camp - Jacksonville 2012 17
    18. 18. • 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
    19. 19. =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
    20. 20. • 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
    21. 21. • 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
    22. 22. 6/16/2012 IT Pro Camp - Jacksonville 2012 22
    23. 23. • 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
    24. 24. 6/16/2012 IT Pro Camp - Jacksonville 2012 24
    25. 25. • 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
    26. 26. • 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
    27. 27. % of Parent Row % of Grand Total6/16/2012 IT Pro Camp - Jacksonville 2012 27
    28. 28. • 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
    29. 29. 6/16/2012 IT Pro Camp - Jacksonville 2012 29
    30. 30. • 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
    31. 31. • 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
    32. 32. • 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
    33. 33. 6/16/2012 IT Pro Camp - Jacksonville 2012 33
    34. 34. 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

    ×