0% found this document useful (0 votes)
176 views

DAX Quick Reference Guide

The document provides a quick reference to some of the most commonly used time and date functions, filter functions, and lookup functions in DAX for Power BI and SQL Server Analysis Services. It includes the syntax and descriptions of functions like CALENDAR, DATE, WEEKDAY, DATEADD, DISTINCT, FILTER, and CALCULATE. These functions help with calculations involving dates, times, and filtering or selecting distinct values from columns in DAX queries and calculations.

Uploaded by

This Pot Boiler
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views

DAX Quick Reference Guide

The document provides a quick reference to some of the most commonly used time and date functions, filter functions, and lookup functions in DAX for Power BI and SQL Server Analysis Services. It includes the syntax and descriptions of functions like CALENDAR, DATE, WEEKDAY, DATEADD, DISTINCT, FILTER, and CALCULATE. These functions help with calculations involving dates, times, and filtering or selecting distinct values from columns in DAX queries and calculations.

Uploaded by

This Pot Boiler
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Most Popular DAX Function Quick Reference

For Microsoft SQL Server Analysis Services, Power Pivot in Excel, and Power BI Desktop

These functions help you create calculations based on dates and


time. Many of the functions in DAX are similar to the Excel date
Time and Date Functions and time functions. However, DAX functions use
a datetime data type, and can take values from a column as an
argument.

Returns a table with a single column named “Date” that contains a contiguous set of dates. The
range of dates is from the specified start date to the specified end date, inclusive of those two
dates.
Syntax: CALENDAR(<start_date>, <end_date>)
CALENDAR Term Definition

start_date Any DAX expression that returns a datetime value.

end_date Any DAX expression that returns a datetime value.

Returns the specified date in datetime format. In contrast to Microsoft Excel, which stores dates
as a serial number, DAX date functions always return a datetime data type.
Syntax: DATE(<year>, <month>, <day>)
Term Definition

year A number representing the year. The value of the year argument can include one to
DATE four digits. The year argument is interpreted according to the date system used by
your computer.

month If month is a number from 1 to 12, it represents a month of the year. 1 represents
January, 2 represents February, and so on until 12 that represents December.

day A number representing the day or a calculation. If day is a number from 1 to the
last day of the given month then it represents a day of the month.

Returns the day of the month, a number from 1 to 31.


Syntax: DAY(<date>)
DAY Term Definition

date A date in datetime format, or a text representation of a date.

Description: Returns a number from 1 to 7 identifying the day of the week of a date. By default
the day ranges from 1 (Sunday) to 7 (Saturday).
Syntax: WEEKDAY(<date>, <return_type>)
Term Definition
WEEKDAY date The date in datetime format.

return_type A number that determines the return value: Return type: 1, week begins on
Sunday (1) and ends on Saturday (7). numbered 1 through 7. Return type: 2,
week begins on Monday (1) and ends on Sunday (7). Return type: 3, week begins
on Monday (0) and ends on Sunday (6) numbered 1 through .

1 WWW.DATALYTICSACADEMY.COM
Returns the week number for the given date and year according to the return_type value. The
week number indicates where the week falls numerically within a year.
Syntax: WEEKNUM(<date>, <return_type>)
Term Definition

date The date in datetime format.


WEEKNUM
return_type A number that determines the return value: use 1 when the week
begins on Sunday; use 2 when the week begins on Monday. The
default is 1.
Return type: 1, week begins on Sunday. Weekdays are numbered 1 through 7.
Return type: 2, week begins on Monday. Weekdays are numbered 1 through
7.

Time intelligence functions support the needs of Business

Time Intelligence Functions Intelligence analysis by enabling you to manipulate data using
time periods, including days, months, quarters, and years, and
then build and compare calculations over those periods.

Returns a table that contains a column of dates, shifted either forward or backward in time by the
specified number of intervals from the dates in the current context.
Syntax: DATEADD(<dates>,<number_of_intervals>,<interval>)

Term Definition
DATEADD dates A column that contains dates.

number_of_intervals An integer that specifies the number of intervals to add to or


subtract from the dates.

interval The interval by which to shift the dates. The value for interval can be
one of the following: year, quarter, month, day

Description: Returns the first date in the current context for the specified column of dates.
FIRSTDATE Syntax: FIRSTDATE(<dates>)
Dates = A column that contains dates

Description: Returns a table that contains a column of the dates for the month to date, in the
current context.
DATESMTD Sytnax: DATESMTD(<dates>)
Dates = A column that contains dates
Interchangeable: MTD can be exchanged out for QTD or YTD.

Description: Returns a table that contains a column of all dates from the next day, based on the
first date specified in the dates column in the current context.
NEXTDAY Sytnax: NEXTDAY(<dates>)
Dates = A column that contains dates
Interchangeable: DAY can be exchanged out for MONTH, QUARTER, or YEAR.

2 WWW.DATALYTICSACADEMY.COM
Returns a table that contains a column of all dates representing the day that is previous to the
first date in the dates column, in the current context.
PREVIOUSDAY Sytnax: PREVIOUSDAY(<dates>)
Dates = A column that contains dates
Interchangeable: DAY can be exchanged out for MONTH, QUARTER, or YEAR.

Description: Evaluates the value of the expression for the month to date, in the current context.
Syntax: TOTALMTD(<expression>,<dates>[,<filter>])

Parameter Definition
TOTALMTD
expression An expression that returns a scalar value.

dates A column that contains dates.

filter (optional) An expression that specifies a filter to apply to the current context.
Interchangeable: MTD can be exchanged out for QTD or YTD.

The filter and value functions in DAX are some of the most
complex and powerful, and differ greatly from Excel functions.
Filter Functions The lookup functions work by using tables and relationships,
like a database. The filtering functions let you manipulate data
context to create dynamic calculations.

Description: Returns all the rows in a table, or all the values in a column, ignoring any filters that
might have been applied. This function is useful for clearing filters and creating calculations on all
the rows in a table.
Syntax: ALL( {<table> | <column>[, <column>[, <column>[,…]]]} )

Parameter Definition
ALL
table The table that you want to clear filters on.

column The column that you want to clear filters on.

Note: The argument to the ALL function must be either a reference to a table or a reference to a
base column. You cannot use table expressions or column expressions with the ALL function.
Description: Evaluates an expression in a context that is modified by the specified filters.
Syntax: CALCULATE(<expression>,<filter1>,<filter2>…)
Parameter Definition
CALCULATE
expression The expression to be evaluated.

filter1,filter2,… (optional) A comma separated list of Boolean expression or a table


expression that defines a filter.

Description: Returns a one-column table that contains the distinct values from the specified
column. In other words, duplicate values are removed and only unique values are returned.
DISTINCT Syntax: DISTINCT(<column>)
<column>= The column from which unique values are to be returned. Or, an expression that
returns a column.

3 WWW.DATALYTICSACADEMY.COM
Note: This function cannot be used to return values into a cell or column on a worksheet;
rather, you nest the DISTINCT function within a formula, to get a list of distinct values that can
be passed to another function and then counted, summed, or used for other operations.

Description: Returns a table that represents a subset of another table or expression.


Syntax: FILTER(<table>,<filter>
Parameter Definition
FILTER table The table to be filtered. The table can also be an expression that results in a
table.

filter A Boolean expression that is to be evaluated for each row of the table. For
example, [Amount] > 0 or [Region] = "France"

Description: Returns the values that are directly applied as filters to columnName.
Syntax: FILTERS(<columnName>)
FILTERS <columnName>= The name of an existing column, using standard DAX syntax. It cannot be an
expression.

Description: Returns a one-column table that contains the distinct values from the specified table
or column. In other words, duplicate values are removed and only unique values are returned.
Syntax: VALUES(<TableNameOrColumnName>)
<TableNameOrColumnName>= The table or column from which unique values are to be
VALUES returned.
Note: This function cannot be used to return values into a cell or column on a worksheet;
rather, you use it as an intermediate function, nested in a formula, to get a list of distinct values
that can be counted, or used to filter or sum other values.

DAX information functions look at the cell or row that is

Information Functions provided as an argument and tells you whether the value
matches the expected type. For example, the ISERROR function
returns TRUE if the value that you reference contains an error.

Description: Returns true if values for all referred columns exist, or are contained, in those
columns; otherwise, the function returns false.
Syntax: CONTAINS(<table>, <columnName>, <value>[, <columnName>, <value>]…)
Parameter Definition

table Any DAX expression that returns a table of data.


CONTAINS
filter The name of an existing column, using standard DAX syntax. It
cannot be an expression.
Note: Any DAX expression that returns a single scalar value, that is to be sought in columnName.
The expression is to be evaluated exactly once and before it is passed to the argument list.

Description: Checks whether a value is blank, and returns TRUE or FALSE.


ISBLANK Syntax: ISERROR (<value>)
Value = The value or expression you want to test.

4 WWW.DATALYTICSACADEMY.COM
Description: Checks whether a value is an error, and returns TRUE or FALSE.
ISERROR Syntax: ISERROR (<value>)
Value = The value or expression you want to test.
Description: Checks whether a value is even, and returns TRUE or FALSE.
ISEVEN Syntax: ISEVEN (<value>)
Value = The value you want to test.
Note you can also use ISODD
Returns the value in result_columnName for the row that meets all criteria specified
by search_columnName and search_value.
Syntax: LOOKUPVALUE( <result_columnName>, <search_columnName>,
<search_value>[, <search_columnName>, <search_value>]…)
Parameter Definition

result_columnName The name of an existing column that contains the value you
want to return. The column must be named using standard DAX
LOOKUPVALUE syntax, usually, fully qualified. It cannot be an expression.

search_columnName The name of an existing column, in the same table as


result_columnName or in a related table, over which the look-
up is performed. The column must be named using standard
DAX syntax, usually, fully qualified. It cannot be an expression.

search_value A scalar expression that does not refer to any column in the
same table being searched

Logical functions act upon an expression to return information

Logical Functions about the values or sets in the expression. For example, you
can use the IF function to check the result of an expression and
create conditional results.

Description: Checks whether both arguments are TRUE, and returns TRUE if both arguments are
AND TRUE. Otherwise returns false.
Syntax: AND(<logical1>,<logical2>)
Logica1, Logical2 = The logical values you want to test.

FALSE Description: Returns the logical value FALSE.


Syntax: FALSE()
Description: Checks if a condition provided as the first argument is met. Returns one value if the
condition is TRUE, and returns another value if the condition is FALSE.
Syntax: IF(logical_test>,<value_if_true>, value_if_false)
Parameter Definition

logical_test Any value or expression that can be evaluated to TRUE or FALSE.


IF
value_if_true The value that is returned if the logical test is TRUE. If omitted,
TRUE is returned.

value_if_false The value that is returned if the logical test is FALSE. If omitted,
FALSE is returned.

Description: Evaluates an expression and returns a specified value if the expression returns an
IFERROR error; otherwise returns the value of the expression itself.
Syntax: IFERROR(value, value_if_error)

5 WWW.DATALYTICSACADEMY.COM
Parameter Definition

value Any value or expression.

value_if_error Any value or expression.

Description: Changes FALSE to TRUE, or TRUE to FALSE.


Syntax: NOT(<logical>)
NOT Parameter Definition

logical_1, logical_2 The logical values you want to test.

TRUE Description: Returns the logical value TRUE.


Syntax: TRUE()

Math Functions
Description: Returns the absolute value of a number.
ABS Syntax: ABS(<number>)
Number: The Number which you want the absolute value
Description: Returns the number of combinations for a given number of items. Use COMBIN to
determine the total possible number of groups for a given number of items.
Syntax: COMBIN(number, number_chosen)
Parameter Definition
COMBIN
number The number of items.

number_chosen The number of items in each combination.

Description: Performs division and returns alternate result or BLANK() on division by 0.


Syntax: DIVIDE(<numerator>, <denominator> [,<alternateresult>])
Parameter Definition

numerator The dividend or number to divide.


DIVIDE
denominator The divisor or number to divide by.

alternateresult (Optional) The value returned when division by zero results in an


error. When not provided, the default value is BLANK().

Description: Rounds a number down, toward zero, to the nearest multiple of significance.
Syntax: FLOOR(<number>, <significance>)
Parameter Definition
FLOOR
number The numeric value you want to round.

6 WWW.DATALYTICSACADEMY.COM
significance The multiple to which you want to round. The
argumentsnumber and significance must either both be positive,
or both be negative.

Note: FLOOR can be interchanged for CEILING to round up to the nearest multiple of
significance.
Description: Rounds a number down to the nearest integer.
INT Syntax: INT(<number>)
Number: The number you want to round down to an integer.
Description: Returns the product of the numbers in a column. To return the product of an
expression evaluated for each row in a table, use PRODUCTX
PRODUCT Syntax: SUM(<column>)
Column: The column that contains the numbers to sum.
Note: Only the numbers in the column are counted. Blanks, logical values, and text are ignored.
PRODUCT( Table[Column] ) is equivalent to PRODUCTX( Table, Table[Column] )
Description: Returns the product of an expression evaluated for each row in a table. To return
the product of the numbers in a column
Syntax: PRODUCTX(<table>, <expression>)
PRODUCTX Column: The column that contains the numbers to sum.
Note: The PRODUCTX function takes as its first argument a table, or an expression that returns a
table. The second argument is a column that contains the numbers for which you want to
compute the product, or an expression that evaluates to a column.
Description: Adds all the numbers in a column.
SUM Syntax: SUM(<column>)
Column: The column that contains the numbers to sum.
Description: Returns the sum of an expression evaluated for each row in a table.
Syntax: SUMX(<table>, <expression>)
Parameter Definition
SUMX table The table containing the rows for which the expression will be
evaluated.

expression The expression to be evaluated for each row of the table.

Data Analysis Expressions (DAX) provides many functions for


creating aggregations such as sums, counts, and averages. These
Statistical Functions functions are very similar to aggregation functions used by
Microsoft Excel. This section lists the statistical and aggregation
functions provided in DAX.

Description: Returns the average (arithmetic mean) of all the numbers in a column.
AVERAGE Syntax: AVERAGE(<column>)
Column: The column that contains the numbers take the average of.
Description: The COUNT function counts the number of cells in a column that contain numbers.
COUNT Syntax: COUNT(<column>)
Column: The column that contains the numbers to be counted.

7 WWW.DATALYTICSACADEMY.COM
Note:
COUNTA counts cells which are not blank.

COUNTX counts the number of rows that contain a number or an expression that
evaluates to a number, when evaluating an expression over a table.
COUNTAX counts nonblank results when evaluating the result of an expression
over a table. That is, it works just like the COUNTA function, but is used to
iterate through the rows in a table and count rows where the specified
expressions results in a nonblank result.

Description: The DISTINCTCOUNT function counts the number of distinct values in a column.
DISTINCTCOUNT Syntax: DISTINCTCOUNT(<column>)
Column: The column that contains the numbers you want to count.
Description: Returns a table with the Cartesian product between each row in table1 and the table
that results from evaluating table2 in the context of the current row from table1.
Syntax: GENERATE(<table1>, <table2>)
Parameter Definition
GENERATE
Table1 Any DAX expression that returns a table.

Table2 Any DAX expression that returns a table.

Description: Returns the largest numeric value in a column, OR between two scalar expressions.
Syntax: MAX(<column>)
Syntax: MAX(<expression1>, <expression2>)
Parameter Definition

column The column in which you want to find the largest numeric value.

expression Any DAX expression which returns a single numeric value.


MAX

Note:
MAXA Returns the largest value in a column. Logical values and blanks are counted, where as
MAX only recognizes numeric values
MAXX Evaluates an expression for each row of a table and returns the largest numeric value.
MINA and MINX can be interchanged to return the lowest values.
Description: Returns the median of numbers in a column.
MEDIAN Syntax: MEDIAN(<column>)
Column: The column that contains the numbers for which the median is to be computed.
Note: MEDIANX will return the median of an expression evaluated for each row in a table.
Description: Returns the median number of an expression evaluated for each row in a table.
Syntax: MEDIANX(<table>, <expression>
MEDIANX Parameter Definition

table The table containing the rows which will be evaluated.

8 WWW.DATALYTICSACADEMY.COM
expression The expression to be evaluated for each row of the table.

Description: Returns the sum of an expression evaluated for each row in a table.
Syntax: SUMX(<table>, <expression>)
Parameter Definition
SUMX table The table containing the rows for which the expression will be
evaluated.

expression The expression to be evaluated for each row of the table.

Data Analysis Expressions (DAX) includes a set of text functions

Text Functions that is based on the library of string functions in Excel, but which
has been modified to work with tables and columns. This section
lists all text functions available in the DAX language.

BLANK Description: Returns a blank


Syntax: BLANK()

Description: Joins two text strings into one text string.


Syntax: CONCATENATE(<text1>, <text2>)
text1, text2: The text strings to be joined into a single text string. Strings
CONCATENATE can include text or numbers.
Note: Concatenate only allows for 2 items to be merged. For more, use the &
operator for example: =[Product abbreviation] & "-" & [Product number].
In most cases, it makes more sense to use & instead of concatenate.

Description: Compares two text strings and returns TRUE if they are exactly the same, FALSE
otherwise. EXACT is case-sensitive but ignores formatting differences. You can use EXACT to test
text being entered into a document.
Syntax: EXACT(<text1>,<text2>)
EXACT Parameter Definition

text1 The first text string or column that contains text.

text2 The second text string or column that contains text.

Description: Returns the starting position of one text string within another text string. FIND is
case-sensitive.
Syntax: FIND(<find_text>, <within_text>[, [<start_num>][,
<NotFoundValue>]])

Parameter Definition
FIND find_text The text you want to find. Use double quotes (empty text) to
match the first character in within_text.

You can use wildcard characters — the question mark (?) and
asterisk (*) — in find_text. A question mark matches any single
character; an asterisk matches any sequence of characters. If

9 WWW.DATALYTICSACADEMY.COM
you want to find an actual question mark or asterisk, type a tilde
(~) before the character.

within_text The text containing the text you want to find.

start_num (optional) The character at which to start the search; if omitted,


start_num = 1. The first character in within_text is character
number 1.

NotFoundValue (optional) The value that should be returned when the


operation does not find a matching substring, typically 0, -1, or
BLANK().

Description: Converts a value to text according to the specified format.


Syntax: FORMAT(<value>, <format_string>)
Parameter Definition
FORMAT
value A value or expression that evaluates to a single value.

format_string A string with the formatting template.

Description: Returns the specified number of characters from the start of a text string.
Syntax: LEFT(<text>, <num_chars>)
Parameter Definition

LEFT text The text string containing the characters you want to extract, or
a reference to a column that contains text.

num_chars (optional) The number of characters you want LEFT to extract; if


omitted, 1.

Description: Returns a string of characters from the middle of a text string, given a starting
position and length.
Syntax: MID(<text>, <start_num>, <num_chars>)
Parameter Definition

text The text string from which you want to extract the characters, or
MID a column that contains text.

start_num The position of the first character you want to extract. Positions
start at 1.

num_chars The number of characters to return.

Description: RIGHT returns the last character or characters in a text string, based on the number
of characters you specify.
RIGHT Syntax: RIGHT(<text>, <num_chars>)
Parameter Definition

10 WWW.DATALYTICSACADEMY.COM
text The text string that contains the characters you want to extract,
or a reference to a column that contains text.

num_chars (optional) The number of characters you want RIGHT to extract;


is omitted, 1. You can also use a reference to a column that
contains numbers.

Description: Returns the number of the character at which a specific character or text string is first
found, reading left to right. Search is case-insensitive and accent sensitive.
Syntax: SEARCH(<find_text>, <within_text>[, [<start_num>][,
<NotFoundValue>]])
Parameter Definition

find_text The text that you want to find.

You can use wildcard characters — the question mark (?) and
asterisk (*) — in find_text. A question mark matches any single
character; an asterisk matches any sequence of characters. If you
want to find an actual question mark or asterisk, type a tilde (~)
SEARCH before the character.

within_text The text in which you want to search for find_text, or a column
containing text.

start_num (optional) The character position in within_text at which you


want to start searching. If omitted, 1.

NotFoundValue (optional) The value that should be returned when the


operation does not find a matching substring, typically 0, -1, or
BLANK().

Description: Replaces existing text with new text in a text string.


Syntax: SUBSTITUTE(<text>, <old_text>, <new_text>, <instance_num>)
Parameter Definition

text The text in which you want to substitute characters, or a


reference to a column containing text.
SUBSTITUTE
old_text The existing text that you want to replace.

new_text The text you want to replace old_text with.

instance_num (optional) The occurrence of old_text you want to replace. If


omitted, every instance of old_text is replaced

Description: Converts a text string that represents a number to a number..


VALUE Syntax: VALUE(<text>)
Text: The text to be converted to a number.

11 WWW.DATALYTICSACADEMY.COM

You might also like