MS EXCEL
ESSENTIAL
TRAINING FOR THE
70-779 EXAM
ADVANCED
DAX/MDX FORMULAS
CALCULATE FUNCTION
1 3
MeasureName := CALCULATE( <expression>, <filter1>, <filter2>,…)
2 4
1 Name of your measure; ex. TotalSales
2 CALCULATE function, used for calculating measures in a different context
3 Expression you want calculated in a different context; ex. SUM(mortgages[Cost])
4 Filters used to set the context for the expression in the CALCULATE function
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
FILTER EXAMPLES
1 3
MeasureName := CALCULATE( <expression>, <filter1>, <filter2>,…)
2 4
4 mortgages[LoanConsultant]=“David Michigan”, units[UnitType]=“Double”
4 ALL(mortgages)
4 USERELATIONSHIP(customers[OfferDate], Calendar[Date])
4 SAMEPERIODLASTYEAR(Calendar[Date]) – and others!
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
PERCENT OF TOTAL EXAMPLE
1 2 3
PercentOfTotalMargin := DIVIDE( [TotalMargin],
CALCULATE( [TotalMargin], ALL(mortgages) )
3 4
1 Name of our new measure
2 Safe divide function to account for zeros, if any
3 Previously created measure/expression; SUMX(mortgages,mortgages[Cost]*mortgages[Margin])
4 Forces context to be the entire table, regardless of implicit context from the Pivot Table
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
PREVIOUS YEAR EXAMPLE
1 2 3 4
SalesLastYear := CALCULATE( [TotalCost], DATEADD(Calendar[Date],-1,YEAR))
:= CALCULATE( [TotalCost], SAMEPERIODLASTYEAR(Calendar[Date]))
3 4
1 Name of our new measure
2 CALCULATE function to set a new context
3 Previously created measure/expression; SUM(mortgages[Cost])
4 Equivalent filters using different functions; both reference our calendar table
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
YEAR-OVER-YEAR GROWTH EXAMPLE
1 2
YOYGrowth := IF( ISBLANK([SalesLastYear]) , BLANK(), [TotalCost]/[SalesLastYear])
YOYGrowth := DIVIDE( [TotalCost] , [SalesLastYear])
3
1 ISBLANK() function returns TRUE if the field/expression returns a blank value
2 BLANK() function returns a blank rather than a divide by zero error
3 Safe DIVIDE() function saves the extra IF comparison
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
RUNNING TOTAL EXAMPLE
1 2
RunningTotalSales := CALCULATE( [TotalCost], FILTER( ALL(Calendar[Date]),
Calendar[Date] <= MAX(Calendar[Date]) ) )
3
1 FILTER() function returns a table that is filtered for each filter condition you provide
2 ALL() function gets every date possible to act as your base table
3 Date comparison (current date to maximum date) filters down the entire table from ALL() to return only the values leading
up to the date of the current row in context
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
BASIC CUBE FUNCTION (MDX) EXAMPLE
1 3
=CUBEVALUE(“ThisWorkbookDataModel”, $A23, B$14, Slicer_Date_Hierarchy)
2 4
1 CUBEVALUE() tells Excel to get the value associated with parameters/members you pass
2 References the data model you want to pull from
3 References to cells to pass member expressions to the function
4 Slicer reference that is still used as a Filter
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
ADVANCED CUBE FUNCTION EXAMPLE
1
=CUBEVALUE("ThisWorkbookDataModel",CUBEMEMBER("ThisWorkbookDataModel“
,"[mortgages].[LoanConsultant].[Ricky Zobrist]"), B$1, Slicer_Year)
2 3 4
1 Rather than a cell reference, you can hard-code the value you want with CUBEMEMBER
2 Declare a table or Measures in your model first; ex. [mortgages]; ex. [Measures]
3 Declare the column or Measure second; ex. [LoanConsultant]; ex. [TotalCost]
4 Declare a specific value you’re looking for; ex. [Ricky Zobrist]
MS EXCEL: ESSENTIAL TRAINING FOR THE 70-779 EXAM
SEE YOU IN
THE NEXT LECTURE