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

Comprehensive Guide to Essential DAX Functions in Power BI

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Comprehensive Guide to Essential DAX Functions in Power BI

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Data Analysis Expressions(DAX)

DAX, or Data Analysis Expressions, is a formula language used in Microsoft tools


like Power BI, Power Pivot, and SQL Server Analysis Services (SSAS). It is
designed for data modeling and analysis, allowing users to create custom
calculations, aggregations, and queries.

1. Aggregation Functions

DAX Formula Name Syntax Definition


Returns the average
AVERAGE AVERAGE(<column>) (arithmetic mean) of the
values in a column.
Returns the average of an
AVERAGEX(<table>,
AVERAGEX expression evaluated over a
<expression>)
table.
Counts the number of values
COUNT COUNT(<column>) in a column (ignoring blank
values).
Counts the number of rows
COUNTAX(<table>, that contain a value in an
COUNTAX
<expression>) expression evaluated over a
table.
Counts the number of blank
COUNTBLANK COUNTBLANK(<column>)
values in a column.
Returns the number of rows
COUNTROWS COUNTROWS(<table>) in a table or table
expression.
Counts the number of
DISTINCTCOUNT DISTINCTCOUNT(<column>) distinct (unique) values in a
column.
Returns the largest value in a
MAX MAX(<column>)
column.
Returns the largest value
MAXX(<table>,
MAXX from an expression
<expression>)
evaluated over a table.
Returns the smallest value in
MIN MIN(<column>)
a column.
Returns the smallest
MINX(<table>,
MINX value from an expression
<expression>)
evaluated over a table.
Returns the sum of
SUM SUM(<column>)
values in a column.
Returns the sum of an
SUMAX(<table>,
SUMAX expression evaluated
<expression>)
over a table.
Returns the sum of an
SUMX(<table>,
SUMX expression evaluated
<expression>)
over a table.
Returns the product of
PRODUCT PRODUCT(<column>)
all values in a column.
Returns the product of
PRODUCTX(<table>,
PRODUCTX an expression evaluated
<expression>)
over a table.
Returns the median
MEDIAN MEDIAN(<column>)
value of a column.
Returns the sample
STDEV STDEV(<column>) standard deviation of a
column.
Returns the population
STDEVP STDEVP(<column>) standard deviation of a
column.
Returns the sample
VAR VAR(<column>)
variance of a column.
Returns the population
VARP VARP(<column>)
variance of a column.

2. Date and Time Functions


DAX Formula Name Syntax Definition
Returns the date value for
DATE(<year>, <month>,
DATE the specified year, month,
<day>)
and day.
Returns the difference
DATEDIFF(<start_date>, between two dates, in the
DATEDIFF
<end_date>, <interval>) specified interval (e.g.,
days, months, years).
Returns a table that shifts
DATEADD(<dates>, the dates in a column by a
DATEADD
<number>, <interval>) specified number of
intervals.
DAYS(<end_date>, Returns the number of
DAYS
<start_date>) days between two dates.
Returns the day of the
DAY DAY(<date>)
month from a date.
Returns the last date of
ENDOFMONTH(<dates>,
ENDOFMONTH the month, with an
<shift>)
optional offset.
Returns the last date of
ENDOFYEAR(<dates>,
ENDOFYEAR the year, with an optional
<shift>)
offset.
Returns the hour of a
HOUR HOUR(<time>)
given time.
Returns the month of the
MONTH MONTH(<date>)
year from a date.
Returns the name of the
MONTHNAME MONTHNAME(<date>)
month for a given date.
Returns the current date
NOW NOW()
and time.
Returns the quarter of the
QUARTER QUARTER(<date>)
year from a date.
STARTOFMONTH(<dates> Returns the first date of
STARTOFMONTH
) the month.
Returns the first date of
STARTOFYEAR STARTOFYEAR(<dates>)
the year.
Returns a time value for
TIME(<hour>, <minute>,
TIME the specified hour,
<second>)
minute, and second.
Returns the time portion
TIMEVALUE TIMEVALUE(<time>) of a date-time value as a
time value.
TODAY TODAY() Returns the current date.
Returns the year from a
YEAR YEAR(<date>)
date.
YEARFRAC(<start_date>, Returns the year fraction
YEARFRAC
<end_date>) between two dates.
Returns a table of the
SAMEPERIODLASTYEAR(< same period last year,
SAMEPERIODLASTYEAR
dates>) based on the provided
dates.
Calculates the year-to-
TOTALYTD(<expression>,
date (YTD) value for an
TOTALYTD <dates>, <filter>,
expression over a date
<year_end_date>)
range.
DATESBETWEEN(<dates>, Returns a table of dates
DATESBETWEEN <start_date>, between the specified
<end_date>) start and end date.
DATESINPERIOD(<dates>,
Returns a table of dates
<start_date>,
DATESINPERIOD within the specified
<number_of_periods>,
period.
<interval>)
Returns a table of dates
DATESMTD DATESMTD(<dates>) for the month-to-date
(MTD).
Returns a table of dates
DATESQTD DATESQTD(<dates>) for the quarter-to-date
(QTD).
Returns a table of dates
DATESYTD DATESYTD(<dates>)
for the year-to-date (YTD).
PREVIOUSMONTH(<dates Returns a table of dates
PREVIOUSMONTH
>) for the previous month.
Returns a table of dates
NEXTMONTH NEXTMONTH(<dates>)
for the next month.
PARALLELPERIOD(<dates Returns a table of dates
PARALLELPERIOD >, <number_of_intervals>, shifted by a specified
<interval>) number of intervals.
Returns the first date in a
FIRSTDATE FIRSTDATE(<dates>)
column or table.
Returns the last date in a
LASTDATE LASTDATE(<dates>)
column or table.
Returns the last date in a
LASTNONBLANK(<dates> column or table that
LASTNONBLANK
, <expression>) contains a non-blank
value for the expression.

3. Filter Functions

DAX Formula Name Syntax Definition


Removes all filters from a
ALL ALL(<table_or_column>)
table or column.
Returns all values in a
ALLSELECTED(<table_or_ table or column,
ALLSELECTED
column>) considering any filters in
the report context.
ALLEXCEPT(<table>, Removes all filters in a
ALLEXCEPT <column1>, <column2>, table except the ones on
...) specified columns.
REMOVEFILTERS(<table_ Removes filters from a
REMOVEFILTERS
or_column>) table or column.
Returns the value when a
SELECTEDVALUE(<colum single value is selected in
SELECTEDVALUE
n>, <default>) a column, otherwise
returns the default value.
Returns a one-column
table that contains the
VALUES VALUES(<column>)
unique values in a
column.
Returns a table that
FILTER(<table>, contains only rows for
FILTER
<expression>) which the expression
evaluates to true.
CALCULATE(<expressio Evaluates an expression
CALCULATE n>, <filter1>, <filter2>, in a modified filter
...) context.
CALCULATETABLE(<tabl
Returns a table modified
CALCULATETABLE e>, <filter1>, <filter2>,
by the specified filters.
...)
Treats one table as if it
TREATAS(<table>,
were another, with
TREATAS <column1>, <column2>,
different column names
...)
and relationships.
Specifies an alternative
USERELATIONSHIP(<col
USERELATIONSHIP relationship to be used
umn1>, <column2>)
in the calculation.
CROSSFILTER(<column Defines a cross-filtering
CROSSFILTER 1>, <column2>, direction for a
<relationship>) relationship.
Applies additional filters
KEEPFILTERS KEEPFILTERS(<filter>) to the current context in
a calculation.
Returns TRUE if the
column is being filtered,
ISFILTERED ISFILTERED(<column>)
otherwise returns
FALSE.
Returns TRUE if a value
ISBLANK ISBLANK(<value>) is blank, otherwise
returns FALSE.
4. Information Functions

DAX Formula Name Syntax Definition


Returns TRUE if the
value is blank,
ISBLANK ISBLANK(<value>)
otherwise returns
FALSE.

Returns TRUE if the


expression results in an
ISERROR ISERROR(<expression>)
error, otherwise returns
FALSE.

Returns TRUE if the


value is not text,
ISNONTEXT ISNONTEXT(<value>)
otherwise returns
FALSE.

Returns TRUE if the


value is a number,
ISNUMBER ISNUMBER(<value>)
otherwise returns
FALSE.

Returns TRUE if the


ISTEXT ISTEXT(<value>) value is text, otherwise
returns FALSE.

Returns TRUE if the


value is a logical
ISLOGICAL ISLOGICAL(<value>) (TRUE/FALSE),
otherwise returns
FALSE.
5. Logical Functions

DAX Formula Name Syntax Definition


Returns TRUE if both
AND(<expression1>, expressions evaluate to
AND
<expression2>) TRUE, otherwise returns
FALSE.
Returns one value if the
IF(<logical_test>,
condition is TRUE and
IF <value_if_true>,
another if the condition
<value_if_false>)
is FALSE.
Returns the value of an
expression if it does not
IFERROR(<expression>,
IFERROR result in an error,
<value_if_error>)
otherwise returns a
specified value.
Reverses the result of a
logical expression,
NOT(<logical_expressio
NOT returning TRUE if the
n>)
expression is FALSE, and
vice versa.
Returns TRUE if any of
OR(<expression1>,
OR the expressions evaluate
<expression2>)
to TRUE.
Evaluates an expression
against a list of values
SWITCH(<expression>,
SWITCH and returns the result
<value1>, <result1>, ...)
corresponding to the
first matching value.
Returns the logical value
TRUE TRUE()
TRUE.
Returns the logical value
FALSE FALSE()
FALSE.
Returns TRUE if a
column is in the current
ISINSCOPE ISINSCOPE(<column>)
scope, otherwise
returns FALSE.
Returns a value if the
IFBLANK(<value>, expression is not blank;
IFBLANK
<alternative_value>) otherwise, returns an
alternative value.
Returns the first non-
COALESCE(<expression
COALESCE blank value among the
1>, <expression2>, ...)
expressions.
Returns a specified
IFERROR(<expression>,
IFERROR value if an expression
<value_if_error>)
evaluates to an error.

6. Statistical Functions
DAX Formula Name Syntax Definition
Returns the median
MEDIAN MEDIAN(<column>)
value of a column.
Returns the value at the
given percentile of a
PERCENTILE.EXC(<colu
PERCENTILE.EXC column, excluding the
mn>, <percentile>)
0th and 100th
percentiles.
Returns the value at the
given percentile of a
PERCENTILE.INC(<colu
PERCENTILE.INC column, including the
mn>, <percentile>)
0th and 100th
percentiles.
DAX Formula Name Syntax Definition
Returns the sample
STDEV STDEV(<column>) standard deviation of a
column.

Returns the population


STDEVP STDEVP(<column>) standard deviation of a
column.

Returns the sample


VAR VAR(<column>)
variance of a column.
Returns the population
VARP VARP(<column>)
variance of a column.

Returns the rank of an


RANKX(<table>, expression evaluated
RANKX <expression>, <value>, over a table, with
<order>, <ties>) options for sorting and
handling ties.

Computes the running


RUNNINGTOTAL(<expre total of an expression
RUNNINGTOTAL ssion>, <dates>, over time, based on the
<order>) provided date and sort
order.

Returns the population


COVARIANCE.P(<colum
COVARIANCE.P covariance between two
n1>, <column2>)
columns.

Returns the sample


COVARIANCE.S(<colum
COVARIANCE.S covariance between two
n1>, <column2>)
columns.
7. Text Functions

DAX Formula Name Syntax Definition


CONCATENATE(<text1>, Joins two text values into
CONCATENATE
<text2>) one text string.
Concatenates the result
of an expression
CONCATENATEX(<table>
evaluated over a table
CONCATENATEX , <expression>,
with a specified
<delimiter>, <order>)
delimiter, and an
optional sort order.
Returns the leftmost
characters from a text
LEFT(<text>,
LEFT string, based on a
<num_chars>)
specified number of
characters.
Returns the rightmost
characters from a text
RIGHT(<text>,
RIGHT string, based on a
<num_chars>)
specified number of
characters.
Returns a substring from
MID(<text>,
a text string, starting at a
MID <start_position>,
specified position and
<num_chars>)
with a specified length.
Returns the number of
LEN LEN(<text>) characters in a text
string.
Converts a text string to
UPPER UPPER(<text>)
uppercase.
Converts a text string to
LOWER LOWER(<text>)
lowercase.
Removes leading and
TRIM TRIM(<text>) trailing spaces from a
text string.
REPLACE(<text>, Replaces part of a text
<start_position>, string with another text
REPLACE
<num_chars>, string, starting from a
<new_text>) specified position.
Returns the position of
SEARCH(<find_text>,
the first occurrence of a
SEARCH <within_text>,
substring within another
<start_position>)
string.

Compares two text


strings and returns TRUE
EXACT EXACT(<text1>, <text2>) if they are exactly the
same, otherwise returns
FALSE.
Converts a value to text
TEXT TEXT(<value>, <format>) according to the
specified format.
Converts a text string
VALUE VALUE(<text>) that represents a number
to a numeric value.
SUBSTITUTE(<text>, Replaces occurrences of
SUBSTITUTE <old_text>, <new_text>, a substring with another
<instance_num>) substring.
Joins multiple text strings
TEXTJOIN(<delimiter>,
into one, with an optional
TEXTJOIN <ignore_empty>, <text1>,
delimiter and the option
<text2>, ...)
to ignore empty values.
Returns the position of
FIND(<find_text>,
the first occurrence of a
FIND <within_text>,
substring within another
<start_position>)
string, case-sensitive.
Returns the Unicode
character that
UNICHAR UNICHAR(<unicode>)
corresponds to a
specified code point.
Returns the Unicode
UNICODE UNICODE(<text>) value of the first
character in a text string.

8. Parent-Child Functions

DAX Formula Name Syntax Definition

Returns a delimited text


string with the path from
PATH PATH(<parent>, <child>)
the parent to the child in
a parent-child hierarchy.

Returns a specific item


PATHITEM(<path>, from a path. The path is
PATHITEM
<item_number>) defined by the PATH
function.

Returns a specific item


PATHITEMREVERSE(<pat
PATHITEMREVERSE from a path in reverse
h>, <item_number>)
order.

Returns the length


PATHLENGTH PATHLENGTH(<path>) (number of items) of a
path.

Returns the value in a


LOOKUPVALUE(<result_
result column for a row
column>,
LOOKUPVALUE where a specified
<search_column>,
column has a matching
<search_value>)
value.
9. Rank Functions

DAX Formula Name Syntax Definition


Ranks the rows in a table
RANKX(<table>, based on the result of an
RANKX <expression>, <value>, expression, with the
<order>, <ties>) option to handle sorting
and ties.
Returns the rank of a
number in a list of
RANK.EQ(<number>,
RANK.EQ numbers, where
<values>, <order>)
duplicates receive the
same rank.
Returns the average rank
of a number in a list of
RANK.AVG(<number>,
RANK.AVG numbers, where
<values>, <order>)
duplicates receive the
average rank.

10. Mathematical Functions


DAX Formula Name Syntax Definition
Returns the absolute
ABS ABS(<number>)
value of a number.
Rounds a number up,
CEILING(<number>, away from zero, to the
CEILING
<significance>) nearest multiple of
significance.
Rounds a number down,
FLOOR(<number>, towards zero, to the
FLOOR
<significance>) nearest multiple of
significance.
Returns the remainder
MOD(<number>,
MOD after a number is divided
<divisor>)
by a divisor.
Returns the result of a
POWER(<number>,
POWER number raised to the
<exponent>)
power of an exponent.
Rounds a number to a
ROUND(<number>,
ROUND specified number of
<num_digits>)
digits.
Rounds a number up,
ROUNDUP(<number>, away from zero, to the
ROUNDUP
<num_digits>) specified number of
digits.
Rounds a number down,
ROUNDDOWN(<number towards zero, to the
ROUNDDOWN
>, <num_digits>) specified number of
digits.
Returns the square root
SQRT SQRT(<number>)
of a number.
Truncates a number to a
TRUNC(<number>, specified number of
TRUNC
<num_digits>) digits by removing the
fractional part.
Returns the constant e
EXP EXP(<number>) raised to the power of a
number.
Returns the natural
LN LN(<number>)
logarithm of a number.
Returns the logarithm of
LOG LOG(<number>, <base>) a number to the
specified base.
Returns the value of the
PI PI() mathematical constant
pi.
Returns a random
RAND RAND()
number between 0 and 1.
Returns the sign of a
number, indicating
SIGN SIGN(<number>) whether the number is
positive, negative, or
zero.
SQUAREROOT(<number Returns the square root
SQUAREROOT
>) of a number.
Returns the natural
LN10 LN10()
logarithm of 10.

11. Financial Functions

DAX Formula Name Syntax Definition


Returns the future value
of an investment based
FV(<rate>, <nper>,
FV on constant periodic
<pmt>, <pv>, <type>)
payments and a
constant interest rate.
Returns the interest
payment for an
IPMT(<rate>, <period>,
investment based on
IPMT <nper>, <pv>, <fv>,
constant periodic
<type>)
payments and a
constant interest rate.
Returns the periodic
payment for an
PMT(<rate>, <nper>, investment based on
PMT
<pv>, <fv>, <type>) constant periodic
payments and a
constant interest rate.
Returns the present
value of an investment
PV(<rate>, <nper>,
PV based on constant
<pmt>, <fv>, <type>)
periodic payments and a
constant interest rate.
Returns the interest rate
RATE(<nper>, <pmt>, for an investment based
RATE <pv>, <fv>, <type>, on constant periodic
<guess>) payments and a
constant present value.
Returns the number of
periods for an
NPER(<rate>, <pmt>, investment based on
NPER
<pv>, <fv>, <type>) constant periodic
payments and a
constant interest rate.

12. Miscellaneous Functions

DAX Formula Name Syntax Definition


BLANK BLANK() Returns a blank value.
Returns a table with
DISTINCT DISTINCT(<table>) distinct values from a
specified column.
Returns the value of an
EARLIER(<expression>, expression evaluated in
EARLIER
<level>) an earlier row context in
a nested iteration.
Returns the earliest
EARLIEST(<expression>,
EARLIEST value in a column for the
<level>)
current row context.
Returns the next month
NEXTMONTH NEXTMONTH(<dates>) from the given date
range.
Returns the previous
PREVIOUSMONTH(<dat
PREVIOUSMONTH month from the given
es>)
date range.
Specifies an alternative
USERELATIONSHIP(<col
USERELATIONSHIP relationship to be used
umn1>, <column2>)
in the calculation.
Compares two text
strings and returns TRUE
EXACT EXACT(<text1>, <text2>) if they are exactly the
same, otherwise returns
FALSE.

13. Conversion Functions

DAX Formula Name Syntax Definition

Converts a text string that


VALUE VALUE(<text>) represents a number to a
numeric value.

Converts a date in the


DATEVALUE DATEVALUE(<text>) form of text to a
date/time value.
Converts a time in the
TIMEVALUE TIMEVALUE(<text>) form of text to a time
value.
Converts a value to text
TEXT TEXT(<value>, <format>) according to the
specified format.
Converts a number to an
INT INT(<value>) integer by rounding
down.
Converts a text or
REAL REAL(<value>) number to a real number
(float).

Converts a value to a
BOOLEAN BOOLEAN(<value>)
boolean (TRUE or FALSE).
14. Geospatial Functions

DAX Formula Name Syntax Definition


Returns the geometry
resulting from the union
GEOADD(<geometry1>,
GEOADD of two geometries,
<geometry2>)
effectively combining
them.
Returns the geometry of a
geospatial object,
GEOMETRY(<geospatial_
GEOMETRY enabling the handling and
expression>)
manipulation of spatial
data.

Advanced Functions

DAX Formula Name Syntax Definition


Returns the Cartesian
product of two or more
CROSSJOIN(<table1>, tables. Every row from
CROSSJOIN
<table2>, ...) the first table is
combined with every row
from the second table.
Combines the rows of
UNION(<table1>,
UNION two or more tables,
<table2>, ...)
removing duplicates.
Returns a table with the
INTERSECT(<table1>,
INTERSECT rows common to both
<table2>)
tables.
Returns a table with the
EXCEPT(<table1>, rows that exist in the first
EXCEPT
<table2>) table but not in the
second table.
Returns a table that
contains only the rows
NATURALINNERJOIN(< where there is a match
NATURALINNERJOIN
table1>, <table2>) between both tables,
joining on columns with
the same names.
Returns a table that
contains all rows from
NATURALLEFTOUTERJ the first table and
NATURALLEFTOUTERJOIN OIN(<table1>, matching rows from the
<table2>) second table, joining on
columns with the same
names.
Returns a table by
applying an expression
GENERATE(<table1>,
GENERATE to each row of the first
<expression>)
table. The expression
must return a table.
Similar to GENERATE,
but it returns all rows
GENERATEALL(<table1
GENERATEALL from the second table
>, <expression>)
regardless of the filter
context.
SUMMARIZE(<table>, Returns a table grouped
<group_by_column1>, by one or more columns,
SUMMARIZE
<group_by_column2>, with aggregated results
...) for each group.
Returns a table with one
or more columns of data,
SUMMARIZECOLUMN
performing aggregations
SUMMARIZECOLUMNS S(<column1>,
over the provided
<column2>, ...)
columns and
expressions.
Adds one or more
ADDCOLUMNS(<table>, columns to a table,
ADDCOLUMNS <new_column1>, evaluating the specified
<expression1>, ...) expressions for each row
in the table.
Returns a table with the
SELECTCOLUMNS(<tabl
specified columns,
SELECTCOLUMNS e>, <column1>,
evaluating expressions
<expression1>, ...)
for each column.

You might also like