This topic describes the expression elements that you can use in the Expression Editor.
Topics:
SQL operators are used to specify comparisons between expressions.
You can use various types of SQL operators.
Operator | Description |
---|---|
|
Determines if a value is between two non-inclusive bounds. For example:
|
|
Determines if a value is present in a set of values. For example:
|
|
Determines if a value is null. For example:
|
|
Determines if a value matches all or part of a string. Often used with wildcard characters to indicate any character string match of zero or more characters (%) or any single character match (_). For example:
|
You use conditional expressions to create expressions that convert values.
The conditional expressions described in this section are building blocks for creating expressions that convert a value from one form to another.
Note:
CASE
statements, AND
has precedence over OR
Expression | Example | Description |
---|---|---|
|
|
Evaluates each If none of the |
|
|
Also referred to as If none of the If the first expression matches an expression in multiple |
There are various types of functions that you can use in expressions.
Topics:
Aggregate functions perform operations on multiple values to create summary results.
Function | Example | Description |
---|---|---|
Avg |
|
Calculates the average (mean) of a numeric set of values. |
Bin |
|
Selects any numeric attribute from a dimension, fact table, or measure containing data values and places them into a discrete number of bins. This function is treated like a new dimension attribute for purposes such as aggregation, filtering, and drilling. |
Count |
|
Determines the number of items with a non-null value. |
First |
|
Selects the first non-null returned value of the expression argument. The |
Last |
|
Selects the last non-null returned value of the expression. |
Max |
|
Calculates the maximum value (highest numeric value) of the rows satisfying the numeric expression argument. |
Median |
|
Calculates the median (middle) value of the rows satisfying the numeric expression argument. When there are an even number of rows, the median is the mean of the two middle rows. This function always returns a double. |
Min |
|
Calculates the minimum value (lowest numeric value) of the rows satisfying the numeric expression argument. |
StdDev |
|
Returns the standard deviation for a set of values. The return type is always a double. |
StdDev_Pop |
|
Returns the standard deviation for a set of values using the computational formula for population variance and standard deviation. |
Sum |
|
Calculates the sum obtained by adding up all values satisfying the numeric expression argument. |
Analytics functions allow you to explore data using models such as trendline and cluster.
Function | Example | Description |
---|---|---|
Trendline |
|
Fits a linear or exponential model and returns the fitted values or model. The numeric_expr represents the Y value for the trend and the series (time columns) represent the X value. |
Cluster |
|
Collects a set of records into groups based on one or more input expressions using K-Means or Hierarchical Clustering. |
Outlier |
|
This function classifies a record as Outlier based on one or more input expressions using K-Means or Hierarchical Clustering or Multi-Variate Outlier detection Algorithms. |
Regr |
|
Fits a linear model and returns the fitted values or model. This function can be used to fit a linear curve on two measures. |
Evaluate_Script |
|
Executes an R script as specified in the script_file_path, passing in one or more columns or literal expressions as input. The output of the function is determined by the output_column_name. |
Calendar functions manipulate data of the data types DATE
and DATETIME
based on a calendar year.
Function | Example | Description |
---|---|---|
Current_Date |
|
Returns the current date. |
Current_Time |
|
Returns the current time to the specified number of digits of precision, for example: HH:MM:SS.SSS If no argument is specified, the function returns the default precision. |
Current_TimeStamp |
|
Returns the current date/timestamp to the specified number of digits of precision. |
DayName |
|
Returns the name of the day of the week for a specified date expression. |
DayOfMonth |
|
Returns the number corresponding to the day of the month for a specified date expression. |
DayOfWeek |
|
Returns a number between 1 and 7 corresponding to the day of the week for a specified date expression. For example, 1 always corresponds to Sunday, 2 corresponds to Monday, and so on through to Saturday which returns 7. |
DayOfYear |
|
Returns the number (between 1 and 366) corresponding to the day of the year for a specified date expression. |
Day_Of_Quarter |
|
Returns a number (between 1 and 92) corresponding to the day of the quarter for the specified date expression. |
Hour |
|
Returns a number (between 0 and 23) corresponding to the hour for a specified time expression. For example, 0 corresponds to 12 a.m. and 23 corresponds to 11 p.m. |
Minute |
|
Returns a number (between 0 and 59) corresponding to the minute for a specified time expression. |
Month |
|
Returns the number (between 1 and 12) corresponding to the month for a specified date expression. |
MonthName |
|
Returns the name of the month for a specified date expression. |
Month_Of_Quarter |
|
Returns the number (between 1 and 3) corresponding to the month in the quarter for a specified date expression. |
Now |
|
Returns the current timestamp. The |
Quarter_Of_Year |
|
Returns the number (between 1 and 4) corresponding to the quarter of the year for a specified date expression. |
Second |
|
Returns the number (between 0 and 59) corresponding to the seconds for a specified time expression. |
TimeStampAdd |
|
Adds a specified number of intervals to a timestamp, and returns a single timestamp. Interval options are: SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, SQL_TSI_YEAR |
TimeStampDiff |
|
Returns the total number of specified intervals between two timestamps. Use the same intervals as TimeStampAdd. |
Week_Of_Quarter |
|
Returns a number (between 1 and 13) corresponding to the week of the quarter for the specified date expression. |
Week_Of_Year |
|
Returns a number (between 1 and 53) corresponding to the week of the year for the specified date expression. |
Year |
|
Returns the year for the specified date expression. |
Conversion functions convert a value from one form to another.
Function | Example | Description |
---|---|---|
Cast |
|
Changes the data type of an expression or a null literal to another data type. For example, you can cast a customer_name (a data type of Char or Varchar) or birthdate (a datetime literal). Use Don’t use |
IfNull |
|
Tests if an expression evaluates to a null value, and if it does, assigns the specified value to the expression. |
IndexCol |
|
Uses external information to return the appropriate column for the signed-in user to see. |
NullIf |
|
Compares two expressions. If they’re equal, then the function returns null. If they’re not equal, then the function returns the first expression. You can’t specify the literal NULL for the first expression. |
To_DateTime |
|
Converts string literals of dateTime format to a DateTime data type. |
Display functions operate on the result set of a query.
Function | Example | Description |
---|---|---|
BottomN |
|
Returns the n lowest values of expression, ranked from lowest to highest. |
Filter |
|
Computes the expression using the given preaggregate filter. |
Mavg |
|
Calculates a moving average (mean) for the last n rows of data in the result set, inclusive of the current row. |
Msum |
|
Calculates a moving sum for the last n rows of data, inclusive of the current row. The sum for the first row is equal to the numeric expression for the first row. The sum for the second row is calculated by taking the sum of the first two rows of data, and so on. When the nth row is reached, the sum is calculated based on the last n rows of data. |
NTile |
|
Determines the rank of a value in terms of a user-specified range. It returns integers to represent any range of ranks. The example shows a range from 1 to 100, with the lowest sale = 1 and the highest sale = 100. |
Percentile |
|
Calculates a percent rank for each value satisfying the numeric expression argument. The percentile rank ranges are from 0 (1st percentile) to 1 (100th percentile), inclusive. |
Rank |
|
Calculates the rank for each value satisfying the numeric expression argument. The highest number is assigned a rank of 1, and each successive rank is assigned the next consecutive integer (2, 3, 4,...). If certain values are equal, they are assigned the same rank (for example, 1, 1, 1, 4, 5, 5, 7...). |
Rcount |
|
Takes a set of records as input and counts the number of records encountered so far. |
Rmax |
|
Takes a set of records as input and shows the maximum value based on records encountered so far. The specified data type must be one that can be ordered. |
Rmin |
|
Takes a set of records as input and shows the minimum value based on records encountered so far. The specified data type must be one that can be ordered. |
Rsum |
|
Calculates a running sum based on records encountered so far. The sum for the first row is equal to the numeric expression for the first row. The sum for the second row is calculated by taking the sum of the first two rows of data, and so on. |
TopN |
|
Returns the n highest values of expression, ranked from highest to lowest. |
Evaluate functions are database functions that can be used to pass through expressions to get advanced calculations.
Embedded database functions can require one or more columns. These columns are referenced by %1 ... %N within the function. The actual columns must be listed after the function.
Function | Example | Description |
---|---|---|
Evaluate |
|
Passes the specified database function with optional referenced columns as parameters to the database for evaluation. |
Evaluate_Aggr |
|
Passes the specified database function with optional referenced columns as parameters to the database for evaluation. This function is intended for aggregate functions with a |
The mathematical functions described in this section perform mathematical operations.
Function | Example | Description |
---|---|---|
Abs |
|
Calculates the absolute value of a numeric expression. |
Acos |
|
Calculates the arc cosine of a numeric expression. |
Asin |
|
Calculates the arc sine of a numeric expression. |
Atan |
|
Calculates the arc tangent of a numeric expression. |
Atan2 |
|
Calculates the arc tangent of |
Ceiling |
|
Rounds a non-integer numeric expression to the next highest integer. If the numeric expression evaluates to an integer, the |
Cos |
|
Calculates the cosine of a numeric expression. |
Cot |
|
Calculates the cotangent of a numeric expression. |
Degrees |
|
Converts an expression from radians to degrees. |
Exp |
|
Sends the value to the power specified. Calculates |
ExtractBit |
|
Retrieves a bit at a particular position in an integer. It returns an integer of either 0 or 1 corresponding to the position of the bit. |
Floor |
|
Rounds a non-integer numeric expression to the next lowest integer. If the numeric expression evaluates to an integer, the |
Log |
|
Calculates the natural logarithm of an expression. |
Log10 |
|
Calculates the base 10 logarithm of an expression. |
Mod |
|
Divides the first numeric expression by the second numeric expression and returns the remainder portion of the quotient. |
Pi |
|
Returns the constant value of pi. |
Power |
|
Takes the first numeric expression and raises it to the power specified in the second numeric expression. |
Radians |
|
Converts an expression from degrees to radians. |
Rand |
|
Returns a pseudo-random number between 0 and 1. |
RandFromSeed |
|
Returns a pseudo-random number based on a seed value. For a given seed value, the same set of random numbers are generated. |
Round |
|
Rounds a numeric expression to |
Sign |
|
This function returns the following:
|
Sin |
|
Calculates the sine of a numeric expression. |
Sqrt |
|
Calculates the square root of the numeric expression argument. The numeric expression must evaluate to a nonnegative number. |
Tan |
|
Calculates the tangent of a numeric expression. |
Truncate |
|
Truncates a decimal number to return a specified number of places from the decimal point. |
String functions perform various character manipulations. They operate on character strings.
Function | Example | Description |
---|---|---|
Ascii |
|
Converts a single character string to its corresponding ASCII code, between 0 and 255. If the character expression evaluates to multiple characters, the ASCII code corresponding to the first character in the expression is returned. |
Bit_Length |
|
Returns the length, in bits, of a specified string. Each Unicode character is 2 bytes in length (equal to 16 bits). |
Char |
|
Converts a numeric value between 0 and 255 to the character value corresponding to the ASCII code. |
Char_Length |
|
Returns the length, in number of characters, of a specified string. Leading and trailing blanks aren’t counted in the length of the string. |
Concat |
|
Concatenates two character strings. |
Insert |
|
Inserts a specified character string into a specified location in another character string. |
Left |
|
Returns a specified number of characters from the left of a string. |
Length |
|
Returns the length, in number of characters, of a specified string. The length is returned excluding any trailing blank characters. |
Locate |
|
Returns the numeric position of a character string in another character string. If the character string isn’t found in the string being searched, the function returns a value of 0. |
LocateN |
|
Like Locate, returns the numeric position of a character string in another character string. LocateN includes an integer argument that enables you to specify a starting position to begin the search. |
Lower |
|
Converts a character string to lowercase. |
Octet_Length |
|
Returns the number of bytes of a specified string. |
Position |
|
Returns the numeric position of |
Repeat |
|
Repeats a specified expression |
Replace |
|
Replaces one or more characters from a specified character expression with one or more other characters. |
Right |
|
Returns a specified number of characters from the right of a string. |
Space |
|
Inserts blank spaces. |
Substring |
|
Creates a new string starting from a fixed number of characters into the original string. |
SubstringN |
|
Like Substring, creates a new string starting from a fixed number of characters into the original string. SubstringN includes an integer argument that enables you to specify the length of the new string, in number of characters. |
TrimBoth |
|
Strips specified leading and trailing characters from a character string. |
TrimLeading |
|
Strips specified leading characters from a character string. |
TrimTrailing |
|
Strips specified trailing characters from a character string. |
Upper |
|
Converts a character string to uppercase. |
The USER
system function returns values relating to the session.
It returns the user name you signed in with.
Time series functions are aggregate functions that operate on time dimensions.
The time dimension members must be at or below the level of the function. Because of this, one or more columns that uniquely identify members at or below the given level must be projected in the query.
Function | Example | Description |
---|---|---|
Ago |
|
Calculates the aggregated value of a measure from the current time to a specified time period in the past. For example, |
Periodrolling |
|
Computes the aggregate of a measure over the period starting |
ToDate |
|
Aggregates a measure from the beginning of a specified time period to the currently displayed time. For example, this function can calculate Year to Date sales. |
Forecast |
|
Creates a time-series model of the specified measure over the series using either Exponential Smoothing or ARMIA and outputs a forecast for a set of periods as specified by numPeriods. |
You can use constants in expressions.
Available constants include Date, Time, and Timestamp.
Constant | Example | Description |
---|---|---|
Date | DATE [2014-04-09] |
Inserts a specific date. |
Time | TIME [12:00:00] |
Inserts a specific time. |
TimeStamp | TIMESTAMP [2014-04-09 12:00:00] |
Inserts a specific timestamp. |