Download presentation
Presentation is loading. Please wait.
1
DAX Gently Alnis Bajars. alnis@bajars.com @alnisb
A fast paced but sequential approach to learn Data Analysis eXpressions Alnis
2
Agenda DAX Gently Recap of Advantages of Power Pivot Fundamentals of Power Pivot Environment Calculated Columns First Pivot Table ex Power Pivot Calculated Fields aka Measures Functions and their use NOTE: Download Adventure Works DW 2014 (or recent version) to do the demos yourself. Load FactInternetSales, selected Related Tables, select Product SubCat and Cat.
3
Assumptions So we don’t get bogged down.
Excel 2013 only (not 2010), and you can enable Power Pivot. (Note: Power BI Desktop emerging) You know where Power Pivot fits into Power BI You know the difference between Personal BI, Team BI and Corporate BI You know the basic Power Pivot environment. You know how to acquire data in Power Pivot You understand the concept of the Data Model
4
Hot off the Press! Power BI Desktop coming July 24.
Power BI Designer Preview going live Separates Power BI from Excel (corporate friendly) No impediment to using 64 bit version general-availability-coming-july-24th.aspx
5
References Power Pivot Succinctly by James Beresford DAX Patterns 2015
Best possible price Great overview of Power Pivot ecosystem. Explains DAX well. Engine deep dive. DAX Patterns 2015 By Marco Russo and Alberto Ferrari (The Italians) Fast paced yet rigorous, does not over explain concepts Other Books by the Italians Ensure you have Power Pivot enabled. Excel 2013 or O365 preferred. Excel 2010 will work but UI quite different. SQL Server 2012 Analysis Services: The BISIM Tabular Model Excel 2013: Building Data Models with PowerPivot Very rigorous and detailed, can be hard to digest Books by Rob Collie, Bill Jelen, Kapser de Jonge Widely available on Kindle. Some easy to digest explanations, lacks rigour in places
6
Advantages of Power Pivot
Recap Advantages of Power Pivot
7
Advantages of Power Pivot
Breaks Excel 1 million row barrier Fast and compressed xVelocity (ex Vertipaq), cf SSAS Tabular) Eclectic range of data sources Data modelling, no cell references No Vlookup! The streets are safe again. Can do a lot of things Excel formulas can’t easily do. Prototype SSAS Tabular
8
And this is the focus of this presentation.
But be warned Looks like simple Excel functions .. But be warned. Mismatch of expectations by Microsoft Subtleties of row context and filter context are not easy to master Not necessarily a power user tool And this is the focus of this presentation. Fast track over the bleeding obvious and focus on the more challenging concepts.
9
Power Pivot Succinctly by James Beresford.
MDX vs DAX Power Pivot Succinctly by James Beresford.
10
Power Pivot Environment
Fundamentals of Power Pivot Environment
11
Getting Started Enable Power Pivot in Excel 2013.
Power Pivot: Switch to Advanced Mode
12
Demo: Relationships View
Free us from the tyranny of cells and Vlookups Auto create known relationships Manually create relationships Cardinality is important: 1-many vs many-1 No direct support for many-many, simple workarounds later Multiple relationships – but only one active (no direct role playing)
13
Demo: Hierarchies As per OLAP Create in Diagram View
Either drag drop members, or right mouse click
14
Data Manipulation Notes
Limited # of data types. Text, Decimal, Whole, Currency, TRUE/FALSE Compression good, except for Decimal/Currency Note BLANK() function. Behaviour not always obvious for arithmetic and Boolean. DIVIDE function handles div by zero, optional parameter to override BLANK(). Cleaner code and performs better than IF.
15
Functions: The Bleeding Obvious
16
Demo: Cleanse Data Delete columns not needed cf. Filter at Preview cf filter at data source Helper columns not needed by user: Hide From Client Tools Format columns
17
Demo: Mark as Date Table
Essential prerequisite for advanced time intelligence functions Design -> Mark as Date Table Nominate a Unique Column Also sort Month Name by Month Number of Year
18
Calculated Columns vs Calculated Fields
Custom columns Applies row by row , individual cells cannot be edited By default, ROW CONTEXT Calculated Fields Called Measures in Excel 2010 (and Power BI Designer!) Must be aggregates of some sort By default, FILTER CONTEXT Warning Filters can be enforced, overridden or transitioned Context must be understood to understand many of the powerful functions. This is the KEY takeaway slide (hence Gold colour heading)..
19
Context Overview Row Context Filter Context Custom columns
Applies row by row Individual By default, ROW CONTEXT Filter Context Called Measures in Excel 2010 Must be aggregates of some sort By default, FILTER CONTEXT
20
Calculated Columns
21
Calculated Columns Basics
An extra column! Format [Column Name] = <Formula> Row Context Applies row by row See later contrasts with Filter Context Table Qualification Can use [Field Name] Can use Table[Field Name} for disambiguation cf SQL
22
Demo: Calculated Columns
Note the ways to name the column Note references to other columns cf. “official tables” Note behavior of aggregations
23
Demo: Reference Other Tables
Premature look at first functions RELATED() when direction from many to 1 RELATEDTABLE() when direction 1 to many Will traverse relationships for as long as relationships of the same type Sneak preview. CALCULATE auto works relationships 1-many
24
EARLIER Each pass of calculation engine creates a row context level
Acts like “CURRENTROW”, remembers previous row context EARLIER(<column>, <skip_levels> ) skip_levels defaults to 1 Eg. ListPriceRank = COUNTROWS ( FILTER ( DimProduct, DimProduct[ListPrice] > EARLIER ( DimProduct[ListPrice] ) )) + 1
25
First Pivot Table From Power Pivot
26
Demo: Create Pivot Table
Note all tables visible, except “Hide From Client Tools” Otherwise a lot like Pivot Tables … so far
27
Calculated Fields And Filter Context
Calculated Fields were called Measures in Excel 2010.
28
Demo: First Calculated Fields
Enter below the line Note Pascal like assignment [Calculated Column] := <Formula> Enter from Calculated Fields button Note the default behaviour of filter context!
29
Aggregation Function Types
Standard Functions AVERAGE, MAX, MIN, SUM Can only pass one column as an argument Append with A AVERAGEA, MAXA, MINA If text, returns 0 instead of error Append with X Solves the one column problem <Function>X(Table, Expression) SUMX( Sales, Sales[OrderQuantity] * Sales[UnitPrice] ) AVERAGEX, MAXX, MINX, SUMX
30
Count Functions COUNT, COUNTA COUNTX, COUNTAX COUNTBLANK COUNTROWS
COUNTDISTINCT
31
Essential Functions And their use
Covering the Functions that are the basis for common patterns.
32
FILTER Supply a table and filters
Returns table subset (cf. WHERE clause), still a table FILTER(<table>, <filter1>, <filter2> …> Eg. SumHiValueProd := SUMX( FILTER(FactInternetSales, FactInternetSales[UnitPrice]>100), FactInternetSales [OrderQuantity] * FactInternetSales [UnitPrice] )
33
CALCULATE Probably the most important DAX function
Roll your own filter context, including none at all Still obeys active filters CALCULATE(<expression>, <filter1>, <filter2> …> Eg. [Sales 2011] := CALCULATE ( SUM(FactInternetSales[SalesAmount]), DimDate[CalendarYear] = 2011)
34
ALL Effectively removes filter each time a calculated field is executed Eg. [Sales 2011 ALL] := CALCULATE ( SUM(FactInternetSales[SalesAmount]), DimDate[CalendarYear] = 2011, ALL(DimDate))
35
HASONEVALUE TRUE if current context filtered to just one value, otherwise FALSE Eg. [ResellerSales compared to 2011] := IF(HASONEVALUE(DateTime[CalendarYear]), SUM(ResellerSales[SalesAmount])/ CALCULATE(SUM(ResellerSales[SalesAmount]), DateTime[CalendarYear]=2011) ,BLANK())
36
USERELATIONSHIP Make one of multiple relationships between tables active Workaround for lack of support for role playing dimensions Eg. [Sales by Ship Date] =CALCULATE(SUM(FactInternetSales[SalesAmount]), USERELATIONSHIP(FactInternetSales[ShipDateKey], DimDate[DateKey]))
37
First Look at Time Intelligence
Functions very difficult to do in Excel Huge choice Eg 1 [SalesYTD] := TOTALYTD( Sum(FactInternetSales[SalesAmount]), DimDate[FullDateAlternateKey] ) Eg 2 [PYSales] := CALCULATE(Sum(FactInternetSales[SalesAmount]), SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]) )
38
Many to Many Relationship
A number of workarounds, eg. SUMMARIZE( Bridge_AccountNumber, DimAccount[ID_Account])
39
Summary Future Gently Talks Basic DAX simple and intuitive ….
But there are a lot of subtle tricks. Lots of in depth material from The Italians ie. Marco Russo and Alberto Ferrari Future Gently Talks If you think this format works well…. M Gently (Power Query) R Gently (Machine Learning/ Predictive Analysis) Alnis Bajars.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.