Академический Документы
Профессиональный Документы
Культура Документы
chris@crossjoin.co.uk
www.crossjoin.co.uk
Who am I?
Chris Webb (chris@crossjoin.co.uk)
Independent consultant specialising in
Analysis Services and MDX (and PowerPivot
and DAX!): http://www.crossjoin.co.uk
Blogger: http://cwebbbi.spaces.live.com
Author:
MDX Solutions 2nd Edition
Expert Cube Development With Analysis
Services 2008
DAX Calculations
Agenda
What is DAX and why should I learn
it?
Calculated columns and calculated
measures
Row context and filter context
Calculate()
Values()
Demos, demos, demos!
DAX Calculations
What is DAX?
DAX is the new calculation language for
PowerPivot
MDX is still the query language
DAX Calculations
DAX Calculations
Calculated Columns
DAX can be used to create two types of
calculation: calculated columns and calculated
measures
Calculated columns are derived columns in a
PowerPivot table
Are defined inside the PowerPivot UI
After they are created, they behave like any other
column
Their values are calculated immediately after the real
data has been loaded into PowerPivot
Can be used to do basic ETL work, eg concatenating
first and last names, deriving years from dates etc
DAX Calculations
Calculated Measures
Calculated measures provide the numeric
values you see aggregated in pivot tables
All measures are calculated measures in
PowerPivot!
Are defined within the pivot table in Excel
Are calculated at query time
DAX Calculations
DAX Calculations
Filter Context
DAX Calculations
Filter Context
DAX Calculations
Row Context
DAX Calculations
DAX Calculations
DAX Calculations
Calculate()
The Calculate() function is the key to all
advanced DAX calculation functionality
Signature: Calculate(Expression, SetFilter1,
SetFilter2,...)
It allows any expression to be evaluated in a
specific filter context
It works as follows:
Modifies the current filter context according to the
SetFilter arguments you pass in
Shifts the row context onto the filter context
Evaluates your expression in the new filter context
DAX Calculations
Calculate()
SetFilter arguments can either be:
Boolean expressions, eg
CALCULATE(COUNTROWS(), Consultants[Skill]="MDX")
Table functions, so the filter context for any table is
set to the rows returned by the table function, eg
CALCULATE(COUNTROWS(), FILTER(Consultants,
Consultants[Measure1]>3))
DAX Calculations
DAX Calculations
Year to Date
Luckily there are many built-in time
intelligence functions for common calculations
Eg for doing year-to-date sums, we have
TotalYTD:
=TOTALYTD(
SUM(FactInternetSales[SalesAmount])
,DimDate[FullDateAlternateKey]
, ALL(DimDate))
In this case, TotalYTD is a variant of Calculate
with some filters set automatically
DAX Calculations
Total to Date
A total-to-date gets the running total from
the first date we have in our data
No built-in function for it
Total to Date
The final version is:
=CALCULATE(
SUM(FactInternetSales[SalesAmount])
,
DATESBETWEEN('DimDate'[FullDateAlter
nateKey]
, BLANK()
,
LASTDATE( 'DimDate'[FullDateAlternateK
ey]))
, All('DimDate'))
DAX Calculations
DAX Calculations
Distinct Count
To find a distinct count, we need to
count the rows in a table containing
only the distinct values from a
column
The Values() function returns such a
table
Because its a table, all we need to
do is count the number of rows in it:
=COUNTROWS(VALUES(Consultants[
Skill]))
DAX Calculations
Final Thoughts
DAX does the easy stuff very easily
DAX does the medium-hard stuff well too
Links
http://blogs.msdn.com/powerpivot/
http://www.powerpivot.com/
http://powerpivotgeek.com
http://powerpivottwins.com/
http://powerpivotpro.com/
http://www.powerpivot-info.com/
http://cwebbbi.spaces.live.com
http://social.msdn.microsoft.com/Forums/en-US
/sqlkjpowerpivotforexcel/threads
http://www.business-intelligence.kdejonge.net
/
http://sqlblog.com/blogs/marco_russo/
DAX Calculations
Thanks!
Coming up
P/X001
How to Get Full Access to a Database Backup in 3 Minutes
or Less
Idera
P/L001
End-to-end database development has arrived
Red Gate
P/L002
Weird, Deformed, and Grotesque Horrors Stories from the
World of IT
Quest
P/L005
Expert Query Analysis with SQL Sentry
SQLSentry
P/T007
Attunity Change Data Capture for SSIS
#SQLBI
Attunity
TS