DAX CHEAT SHEET
DAX CHEAT SHEET
Profit Calculation Calculated measure using two previously created calculated measures to determine profit.
Profit = [Total Sales] - [Total Cost]
Profit Margin Calculated measure using two previously created calculated measures to determine profit margin, the DIVIDE function
used to perform the division.
Profit Margin = DIVIDE( [Profit], [Total Sales])
Transaction Count Calculated measure that returns a count of all rows in a table, ultimately, many times this simple calculation
is used to return transaction counts.
Transactions = COUNTROWS('Table')
Related Table Count Returns the total rows in a related table. For example, total transactions by Product.
Transactions = COUNTROWS(RELATEDTABLE('TABLE'))
DAX Cheat Sheet
MTD Sales Calculates Total Sales for all days in the current month up to the maximum day in the selection.
MTD Sales = TOTALMTD( [Total Sales], 'DateTable'[DateColumn] )
IF Condition IF Condition =
IF( < logical_test >, <value_if_true>, <value_if_false>)
SWITCH Statement The switch statement can be used when there are many logical tests that need to be p
SWITCH Statement =
SWITCH(
<Column>,
<Value>, <Result>,
<Value>, <Result>
<Else> )
AND Function The AND function evaluates whether both given conditions are met. If both conditions
AND Function =
AND( <logical1>, <logical2> )
OR Function The OR function evaluates whether either given condition is met. If either condition is
OR Function =
OR( <logical1>, <logical2> )
OPENINGBALANCEYEAR() Opening Balance can be achieved using any of the three existing built-in functions whic
will allow you to return the closing balance for Month, Quarter or Year.
OPENINGBALANCEYEAR(
[Measure],
'Date'[Date] )
CLOSINGBALANCEYEAR() Closing Balance can be achieved using any of the three existing built-in functions which
CLOSINGBALANCEYEAR(
[Total Sales],
'Date'[Date] )
Vlookup with no The lookupvalue function will return a value from another table when a relationship does not e
relationship
in the data model.
Vlookup with The Related function will return a value from another table leveraging existing relationships in
relationship
Problem Calculation Expression
YTD Sales Calculates Total Sales for all days in the year up to the maximum day in the selection.
YTD Sales = TOTALYTD( [Total Sales], 'DateTable'[DateColumn] )
YTD Sales (Fiscal This calculation uses an optional third parameter specifying the fiscal year end date.
Calendar) YTD Sales = TOTALYTD( [Total Sales], 'DateTable'[DateColumn], "05/31" )
Year over Year Profit Calculated measure using two previously created calculated measures to determine YoY profit.
YoY Profit = [Profit] - [Prior Year Profit]
Last Year YTD Sales Last YTD Sales = CALCULATE ( [YTD Sales], SAMEPERIODLASTYEAR('DateTable'[DateColumn] ) )
Total Sales for all Countries This calculation uses calculate to return all countries in the calculation regardless of the filter context.
Total Sales All Countries = CALCULATE ( [Total Sales], ALL('Geography Table'[Country] ) )
Percent of Total Calculation This calculation uses two measures previously created to create a percent of total calculation.
Percent of Total = DIVIDE([Total Sales], [Total Sales All Countries])
Moving Totals
Problem Calculation Expression
Rolling 12 Month Calculated measure that returns a rolling 12 months total for Profit.
Sales Rolling 12 Months Profit =
CALCULATE ( [Profit],
DATESBETWEEN('DateTable'[DateColumn] ,
NEXTDAY(
SAMEPERIODLASTYEAR(
LASTDATE(DateTable'[DateColumn] ))),
LASTDATE('DateTable'[DateColumn])))
Country Rank Calculated measure to rank a specific column in a table by a measure. In this measure Country from the geography table
is being ranked by the measure [Total Sales].
Country Rank = RANKX( ALL ('GeographyTable'[Country]), [Total Sales],,,Skip)