Appendix B. DAX Function Reference

This appendix lists the functions currently available in DAX.

Date and Time Functions

The basic date and time functions available in PowerPivot mainly operate as converters between text and datetime types. Also, other “time intelligence” functions are specific to PowerPivot and are covered in the subsection Time Intelligence Functions later in this appendix.

Function

Description

DATE(<year>, <month>, <day>)

Returns the specified date in datetime format.

DATEVALUE(date_text)

Converts a date in the form of text to a date in datetime format.

DAY(<date>)

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

EDATE(<start_date>, <months>)

Returns the date that is the indicated number of months before or after the start date. Use EDATE to calculate maturity dates or due dates that fall on the same day of the month as the date of issue.

EOMONTH(<start_date>, <months>)

Returns the date in datetime format of the last day of the month, before or after a specified number of months. Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.

HOUR(<datetime>)

Returns the hour as a number from 0 (12:00 A.M.) to 23 (11:00 P.M.).

MINUTE(<datetime>)

Returns the minute as a number from 0 to 59, given a date and time value.

MONTH(<datetime>)

Returns the month as a number from 1 (January) to 12 (December).

NOW()

Returns the current date and time in datetime format.

SECOND(<time>)

Returns the seconds of a time value, as a number from 0 to 59.

TIME(hour, minute, second)

Converts hours, minutes, and seconds given as numbers to a time in datetime format.

TIMEVALUE(time_text)

Converts a time in text format to a time in datetime format.

TODAY()

Returns the current date.

WEEKDAY(<date>, <return_type>)

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).

WEEKNUM(<date>, <return_type>)

Returns the week number for the given date and year according to the specified convention. The week number indicates where the week falls numerically within a year.

YEAR(<date>)

Returns the year of a date as a four digit integer in the range 1900-9999.

YEARFRAC(<start_date>, <end_date>, <basis>)

Calculates the fraction of the year represented by the number of whole days between two dates. Use the YEARFRAC worksheet function to identify the proportion of a whole year’s benefits or obligations to assign to a specific term.

Information Functions

Information functions are used to analyze the type of an expression. They all return a TRUE or FALSE value and can be used in any logical expressions.

Function

Description

ISBLANK(<value>)

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

ISERROR(<value>)

Checks whether a value is an error, and returns TRUE or FALSE.

ISLOGICAL(<value>)

Checks whether a value is a logical value, and returns TRUE or FALSE.

ISNONTEXT(<value>)

Checks whether a value is not text (blank cells are not text), and returns TRUE or FALSE.

ISNUMBER(<value>)

Checks whether a value is a number, and returns TRUE or FALSE.

ISTEXT(<value>)

Checks whether a value is text, and returns TRUE or FALSE.

Filter and Value Functions

Filter and Value functions are used to evaluate and manipulate the context.

Function

Description

ALL(<table_or_column>)

Returns all the rows in a table or all the values in a column, ignoring any filters that might have been applied.

ALLEXCEPT(<table>,column1>,<column2>,...)

Overrides all context filters in the table except filters that have been applied to the specified columns.

BLANK()

Returns a blank.

CALCULATE(<expression>,<filter1>,<filter2>...)

Evaluates an expression in a context modified by the specified filters.

CALCULATETABLE( <expression>, <filter1>, <filter2>,...)

Evaluates a table expression in a context modified by filters.

DISTINCT(<column>)

Returns a one-column table that contains the distinct values from the specified column.

EARLIER(<column>, <number>)

Returns the current value of the specified column in an outer evaluation pass of the mentioned column.

EARLIEST(<table_or_column>)

Returns the current value of the specified column in an outer evaluation pass of the mentioned column.

FILTER(<table>,<filter>)

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

RELATED(<column>)

Returns a related value from another table.

RELATEDTABLE(<table>)

Follows an existing relationship, in either direction and returns a table that contains all matching rows from the specified table.

VALUES(<column>)

Returns a one-column table that contains the distinct values from the specified column. This function is similar to the DISTINCT function, but the VALUES function can also return an Unknown member.

ALLNONBLANKROW(?)

In a table or column, returns all the rows except for blank rows and disregards any context filters that might exist.

FIRSTNONBLANK(<column>,<expression>)

Returns the first non-blank values in a column, filtered by expression.

Logical Functions

Logical functions return a TRUE or FALSE value and are used to implement logical conditions in a DAX expression.

Function

Description

AND(<logical1>,<logical2>,...)

Checks whether all arguments are TRUE, and returns TRUE if all arguments are TRUE.

FALSE()

Returns the logical value FALSE.

IF(logical_test>,<value_if_true>, value_if_false)

Checks whether 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.

IFERROR(value, value_if_error)

Returns value_if_error if the first expression is an error. Otherwise, the function returns the value of the expression itself.

NOT(<logical>)

Changes FALSE to TRUE, or TRUE to FALSE.

TRUE()

Returns the logical value TRUE.

OR(<logical1>,<logical2>,...)

Checks whether one of the arguments is TRUE to return TRUE. The function returns FALSE if all arguments are FALSE.

Math and Trig Functions

The following mathematical and trigonometric functions are available in DAX.

Function

Description

ABS(<number>)

Returns the absolute value of a number.

CEILING(<number>, <significance>)

Rounds a number up to the nearest integer or to the nearest multiple of significance.

EXP(<number>)

Returns e raised to the power of a given number. The constant e equals 2.71828182845904, the base of the natural logarithm.

FACT(<number>)

Returns the factorial of a number, equal to the series 1*2*3*...*, ending in the given number.

FLOOR(<number>, <significance>)

Rounds a number down, toward zero, to the nearest multiple of significance.

INT(<number>)

Rounds a number down to the nearest integer.

LN(<number>)

Returns the natural logarithm of a number. Natural logarithms are based on the constant e (2.71828182845904).

LOG(<number>,<base>)

Returns the logarithm of a number to the base you specify.

LOG10(<number>)

Returns the base-10 logarithm of a number.

MOD(<number>, <divisor>)

Returns the remainder after a number is divided by a divisor. The result always has the same sign as the divisor.

MROUND(<number>, <multiple>)

Returns a number rounded to the desired multiple.

PI()

Returns the value of pi, 3.14159265358979, accurate to 15 digits.

POWER(<number>, <power>)

Returns the result of a number raised to a power.

QUOTIENT(<numerator>, <denominator>)

Performs division and returns only the integer portion of the division result. Use this function when you want to discard the fractional remainder of a division operation.

ROUND(<number>, <num_digits>)

Rounds a number to the specified number of digits.

ROUNDDOWN(<number>, <num_digits>)

Rounds a number down, toward zero.

ROUNDUP(<number>, <num_digits>)

Rounds a number up, away from zero.

SIGN(<number>)

Determines the sign of a number, the result of a calculation, or a value in a column. The function returns 1 if the number is positive, 0 (zero) if the number is zero, or -1 if the number is negative.

SQRT(<number>)

Returns the square root of a number.

TRUNC(<number>,<num_digits>)

Truncates a number to an integer by removing the decimal, or fractional, part of the number.

[vb] RAND()

Returns a random number greater than or equal to 0 and less than 1, evenly distributed. The number that is returned changes each time the cell containing this function is recalculated.

[vb] RANDBETWEEN(<bottom>,<top>)

Returns a random number between the numbers you specify.

Statistical Functions

Statistical functions aggregate data that returns a scalar value. Usually these functions operate on all rows of the table that contains the specified column. This column has to be a numeric or date type.

Function

Description

AVERAGE(<column>)

Returns the average (arithmetic mean) of all the numbers in a column.

AVERAGEA(<column>)

Returns the average (arithmetic mean) of the values in a column. Handles text and non-numeric values.

AVERAGEX(<table>, <expression>)

Calculates the average (arithmetic mean) of a set of expressions evaluated over a table.

COUNT(<column>)

Counts the number of cells in a column that contain numbers.

COUNTA(<column>)

Counts the number of cells in a column that are not empty.

COUNTAX(<table>, <expression>)

Counts nonblank results when evaluating the result of an expression over a table.

COUNTBLANK(<column>)

Counts the number of blank cells in a column.

COUNTROWS(<table>)

Counts the number of rows in the specified table or in a table defined by an expression.

COUNTX(<table>, <expression>)

Counts the number of rows that contain a number or an expression that evaluates to a number, when evaluating an expression over a table.

MAX(<column>)

Returns the largest numeric value in a column.

MAXA(<column>)

Returns the largest value in a column. Logical values and blanks are counted.

MAXX(<table>, <expression>)

Evaluates an expression for each row of a table and returns the largest numeric value.

MIN(<column>)

Returns the smallest numeric value in a column. Ignores logical values and text.

MINA(<column>)

Returns the smallest value in a column, including any logical values and numbers represented as text.

MINX(<table>, < expression>)

Returns the smallest numeric value that results from evaluating an expression for each row of a table.

SUM(<column>)

Adds all the numbers in a column.

SUMX(<table>, <expression>)

Returns the sum of an expression evaluated for each row in a table.

Text Functions

The following functions for evaluating and handling text strings are available in DAX.

Function

Description

CODE(<text>)

Returns a numeric code for the first character in a text string, in the character set used by your computer.

CONCATENATE(<text1>, <text2>,...)

Joins multiple text strings into one text string. The joined items can be text, numbers, or Boolean values represented as text, or a combination of those items. You can also use a column reference if the column contains appropriate values.

EXACT(<text1>,<text2>)

Compares two text strings and returns TRUE if they are exactly the same, and returns FALSE otherwise. EXACT is case-sensitive but ignores formatting differences. You can use EXACT to test text that is entered into a document.

FIND(<find_text, within_text, start_num)

Returns the starting position of one text string within another text string. FIND is case-sensitive.

FIXED(<number>, <decimals>, <no_commas>)

Rounds a number to the specified number of decimals and returns the result as text. You can specify that the result be returned with or without commas.

LEFT(<text>, <num_chars>)

Returns the specified number of characters from the start of a text string.

LEN(<text>)

Returns the number of characters in a text string.

LOWER(<text>)

Converts all letters in a text string to lowercase.

MID(<text>, <start_num>, <num_chars>)

Returns a string of characters from the middle of a text string, given a starting position and length.

REPLACE(<old_text>, <start_num>, <num_chars>, <new_text>)

Replaces part of a text string, based on the number of characters you specify, with a different text string.

REPT(<text>, <num_times>)

Repeats text a given number of times. Use REPT to fill a cell with a number of instances of a text string.

RIGHT(<text>, <num_chars>)

Returns the last character or characters in a text string, based on the number of characters you specify.

SEARCH(<search_text>, <within_text>, [start_num])

Returns the number of the character at which a specific character or text string is first found, reading left to right. SEARCH is case-sensitive.

SUBSTITUTE(<text>, <old_text>, <new_text>, <instance_num>)

Replaces existing text with new text in a text string.

TRIM(<text>)

Removes all spaces from text except for single spaces between words.

UPPER (<text>)

Converts a text string to all uppercase letters.

VALUE(<text>)

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

FORMAT(<value>, <format_string>)

Converts a value to text according to the specified format.

Time Intelligence Functions

The Time Intelligence functions perform complex operations on dates, such as comparing aggregated values year over year or calculating the year-to-date value of a measure.

Function

Description

CLOSINGBALANCEMONTH (<expression>, <dates>, <filter>)

Evaluates the specified expression at the calendar-date end of the given month. The given month is calculated as the month of the latest date in the dates argument, after applying all filters.

CLOSINGBALANCEQUARTER (<expression>, <dates>, <filter>)

Evaluates the specified expression at the calendar-date end of the given quarter. The given quarter is calculated as the quarter of the latest date in the dates argument, after applying all filters.

CLOSINGBALANCEYEAR (<expression>,<dates>,<filter>)

Evaluates the specified expression at the calendar-date end of the given year. The given year is calculated as the year of the latest date in the dates argument, after applying all filters.

DATESINPERIOD (<date_column>, <start_date>, <number_of_intervals>, <intervals>)

Returns a table of dates that can be found in the specified date column, beginning with the start date and continuing for the specified number of intervals.

DATESBETWEEN (<column>, <start_date>, <end_date>

Returns a table of dates that can be found in the specified date column, beginning with the start date and ending with the end date.

DATEADD (<date_column>, <number_of_intervals>, <interval>)

Returns a table that contains a column of dates, shifted either forward in time or back in time from the dates in the specified date column.

FIRSTDATE (<datecolumn>)

Returns the first date in the current context for the specified date column.

LASTDATE (<datecolumn>)

Returns the last date in the current context for the specified date column.

LASTNONBLANK (<datecolumn>, <expression>)

Returns the last value in the column, filtered by the current context, where the expression is not blank.

STARTOFMONTH (<date_column>)

Returns the first day of the month in the specified date column.

STARTOFQUARTER (<date_column>)

Returns the first day of the quarter in the specified date column.

STARTOFYEAR (<date_column>[,<YE_date>])

Returns the first day of the year in the specified date column.

ENDOFMONTH(<date_column>)

Returns the last day of the month in the specified date column.

ENDOFQUARTER(<date_column>)

Returns the last day of the quarter in the specified date column.

ENDOFYEAR(<date_column>)

Returns the last day of the year in the specified date column.

PARALLELPERIOD(<date_column>, <number_of_intervals>,<intervals>)

Moves the specified number of intervals and then returns all contiguous full months that contain any values after that shift. Gaps between the first and last dates are filled in, and months are also filled in.

PREVIOUSDAY(<date_column>)

Returns the previous day date from the date column.

PREVIOUSMONTH(<date_column>)

Returns the set of dates in the previous month from the date column.

PREVIOUSQUARTER(<date_column>)

Returns the set of dates in the previous quarter from the date column.

PREVIOUSYEAR(<date_column>)

Returns the set of dates in the previous year from the date column.

NEXTDAY(<date_column>)

Returns the next day date from the date column.

NEXTMONTH(<date_column>)

Returns the set of dates in the next month from the date column.

NEXTQUARTER (<date_column>)

Returns the set of dates for the next quarter from the date column.

NEXTYEAR (<date_column> [,<YE_date>])

Returns the set of dates for the next year from the date column.

DATESMTD(<date_column>)

Returns the subset of dates from the date column for the interval that starts at the first day of the month and ends at the latest date in the specified dates column, for the month that is the corresponding month of the latest date.

DATESQTD (<date_column>)

Returns the subset of dates from the date column for the interval that starts at the first day of the quarter and ends at the latest date in the specified dates column, for the quarter that is the corresponding quarter of the latest date.

DATESYTD (<date_column> [,<YE_date>])

Returns the subset of dates from the date column for the interval that starts the first day of the year and ends at the latest date in the specified dates column for the year to date.

SAMEPERIODLASTYEAR (<dates>)

Returns a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context.

OPENINGBALANCEMONTH (<expression>, <dates>,<filter>)

Evaluates the specified expression at the calendar-date end of the month prior the given month. The given month is calculated as the month of the latest date in the dates argument, after applying all filters.

OPENINGBALANCEQUARTER (<expression>,<dates>,<filter>)

Evaluates the specified expression at the calendar-date end of the quarter prior to the given quarter. The given quarter is calculated as the quarter of the latest date in the dates argument, after applying all filters.

OPENINGBALANCEYEAR (<expression>,<dates>,<filter>)

Evaluates the specified expression at the calendar-date end of the year prior to the given year. The given year is calculated as the year of the latest date in the dates argument, after applying all filters.

TotalMTD (<expression>,<dates>,<filter>)

Evaluates the specified expression for the interval that starts at the first day of the month and ends at the latest date in the specified dates column, after applying all filters.

TotalQTD (<expression>,<dates>,<filter>)

Evaluates the specified expression for the interval that starts at the first day of the quarter and ends at the latest date in the specified dates column, after applying all filters.

TotalYTD (<expression>,<dates>,<filter>)

Evaluates the specified expression for the interval that starts at the first day of the year and ends at the latest date in the specified dates column, after applying all filters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset