Variables and Expressions: Functions in Expressions
You can use functions to perform specific tasks that facilitate the processing of data for reports and generic inquiries. The Expression Editor provides many functions that process data and return values, which you can use in reports and generic inquiries.
To use functions in expressions, you can enter them manually in the expression editing area or select them from the list of functions provided by the Expression Editor. You can use the following groups of functions in expressions.
Type Conversion Functions
You use the type conversion functions to convert data from one data type to another. The following table lists the type conversion functions available in the Conversion subnode of the Functions node in the Expression Editor.
Function | Description and Examples |
---|---|
CBool(x)
|
Converts the expression used as the function argument into a Boolean expression.
Returns Example:
In this example, |
CDate(x) |
Converts the expression used as the function argument into a value of the Date type. The argument should be a valid date expression according to the locale selected for the import or export scenario. Example:
In this example, |
CStr(x) |
Converts the expression used as the function argument into a string. If the
argument is Example:
Here, |
CDbl(x)
|
Converts the expression defined in the function argument into a value of the Double type. Example:
Here, |
CSng(x)
|
Converts the expression used as the function argument into a value of the Single type. If the expression has a value outside of the acceptable range for the Single type, this function returns an error. Example:
In this example, |
CDec(x)
|
Converts the expression used as the function argument into a value of the Decimal type. Example:
In this example, |
CInt(x)
|
Converts the expression used as the function argument into a value of the Integer type. Example:
In this example, |
CShort(x)
|
Converts a numeric value to a value of the Short type. Example:
|
CLong(x)
|
Converts a numeric value to a value of the Long type. Example:
In this example, |
Aggregate Functions
Aggregate functions perform a calculation on a set of values and return a single value. The following table lists the aggregate functions available in the Aggregates subnode of the Functions node in the Expression Editor.
Function | Description and Examples |
---|---|
Avg(expression)
|
Returns the average of all non-null values of the specified expression. Example:
In this example, |
Sum(expression) |
Returns the sum of the values of the specified expression. Example:
In this example, |
Count(expression) |
Returns the count of the values from the specified expression. Example:
In this example, |
Max(expression) |
Returns the maximum value from all non-null values of the specified expression. Example:
In this example, |
Min(expression) |
Returns the minimum value from all non-null values of the specified expression. Example:
In this example, |
Next(expression) |
Returns the next value (from the current one) in the specified expression. Example:
In this example, |
Prev(expression) |
Returns the previous value (from the current one) in the specified expression. Example:
|
First(expression) |
Returns the first value in the specified expression. Example:
In this example, |
Last(expression) |
Returns the last value in the specified expression. Example:
In this example, |
String Functions
String functions perform an operation on a string input value and return a string or numeric value. Listed below are the string functions available in the Text subnode of the Functions node in the Expression Editor.
Function | Description and Examples |
---|---|
LTrim(string) |
Removes all leading spaces or parsing characters from the specified character expression, or all leading 0 bytes from the specified binary expression. Example:
In this example, |
RTrim(string) |
Removes all trailing spaces or parsing characters from the specified character expression, or all trailing 0 bytes from the specified binary expression. Example:
In this example, |
Trim(string) |
Removes all leading and trailing spaces or parsing characters from the specified character expression, or all leading and trailing 0 bytes from the specified binary expression. Example:
In this example, |
Format(format, argument(s)) |
Replaces the format item in the specified formatting string (format) with the text equivalent of the arguments (arguments). Example:
In this example, |
UCase(string) |
Returns a string that has been converted to uppercase. The string argument is any valid string expression. If string contains Null, Null is returned. Example:
In this example, |
LCase(string) |
Returns a string that has been converted to lowercase. The string argument is any valid string expression. If string contains Null, Null is returned. Example:
In this example, |
InStr(string, findString) |
Returns the position of the first occurrence of one string (findString) within another (string). Example:
In this example, |
InStrRev(string, findString) |
Returns the position of the last occurrence of one string (findString) within another (string), starting from the right side of the string. Example:
In this example, |
Len(string) |
Returns an integer containing either the number of characters in the string or the nominal number of bytes required to store a variable. Example:
In this example, |
Left(string, length) |
Returns a string containing the specified number of characters from the left side of a string. If string contains Null, Null is returned. Example:
In this example, |
Right(string, length) |
Returns a string containing the specified number of characters from the right side of a string. If string contains Null, Null is returned. Example:
In this example, |
Replace(string, oldValue,
newValue) |
Returns a string in which the specified substring (oldValue) has been replaced with another substring (newValue). Example:
In this example, |
PadLeft(string, width,
paddingChar) |
Right-aligns the characters in the specified string (string), padding with the specified characters (paddingChar) on the left for the specified total width (width). Example:
In this example, |
PadRight(string, width,
paddingChar) |
Left-aligns the characters in the specified string (string), padding with the specified characters (paddingChar) on the right for the specified total width (width). Example:
In this example, |
Substring(string, start, length) |
Returns a string containing the specified number of characters (length) from the left side of the specified string (string) starting from the specified symbol number (start). The numbering is 0 based, meaning that the number of the first symbol in the string is 0. Example:
In this example, |
Mathematical Functions
Mathematical functions perform calculations, usually based on input values provided as arguments, and return numeric values. The following table lists the mathematical functions available in the Math subnode of the Functions node in the Expression Editor.
Function | Description and Examples |
---|---|
Abs(x) |
Returns the absolute value of a number. Example:
In this example, |
Floor(x) |
Returns the largest integer that is not greater than the argument. Example:
In this example, |
Ceiling(x) |
Returns the smallest integer that is not less than the argument. Example:
In this example, |
Round(x, decimals) |
Returns a numeric expression, rounded to the specified precision (decimals). Example:
In this example, |
Min(x, y) |
Returns the smaller of two values. Example:
In this example, |
Max(x, y) |
Returns the greater of two values. Example:
In this example, |
Pow(x, power) |
Computes the value of x raised to the specified power (power). Example:
In this example, |
Date and Time Functions
The date and time functionsperform operations on input values and return values of the following types: string, numeric, or date and time. The following table lists the string functions available in the Date/Time subnode of the Functions node in the Expression Editor.
Function | Description and Examples |
---|---|
DateAdd(date, interval, number) |
Returns a new date, which is calculated by adding the
specified number (number) of time intervals (interval) to the date
(date). The interval argument specifies the type of time interval and
can be one of the following options:
Examples:
In these examples, |
DateDiff(interval, date1, date2) |
Returns
the count (as a signed integer value) of the specified interval boundaries that
are crossed between the specified date1 and date2. The interval
argument, which specifies the type of time interval, can be one of the following
options:
|
Day(date) |
Returns the day (as an integer) extracted from the specified date (date). Examples:
In these examples, |
DayOfWeek(date) |
Returns the day of the week associated with the specified date (date) as an integer. Examples:
In these examples, |
DayOfYear(date) |
Returns the day of the year calculated for the specified date (date). Examples:
In these examples, |
DayOrdinal(day) |
Converts the specified integer value (day) to a string that contains the ordinal number in the current locale. For example, for the English locale, the string contains the short form of the ordinal number, such as 1st or 2nd. For numbers that are less than 1 or greater than 31, the function returns an empty string. Example:
|
Hour(date) |
Returns the number of hours extracted from the specified date (date). Examples:
In these examples, |
Minute(date) |
Returns the number of minutes extracted from the specified date (date). Examples:
In these examples, |
Month(date) |
Returns the month, as an integer, extracted from the specified date (date). Examples:
In these examples, |
MonthName(date) |
Returns a string that contains the name of the month extracted from the specified date (date) in the current locale. Example:
|
Now() |
Returns the current date and time according to the system date and time settings on the local computer. Example:
|
NowUTC() |
Returns the
current date and time in the user's time zone. The system
extracts the user's time zone from one of the following sources, which are ordered by
priority from the highest to the lowest:
Example:
|
Second(date) |
Returns the seconds extracted from the specified date (date) as an integer. Examples:
In these examples, |
Today() |
Returns the current date according to the system date and time settings on the local computer. Example:
|
TodayUTC() |
Returns the
current date in the user's time zone. The system extracts
the user's time zone from one of the following sources, which are ordered by priority
from the highest to the lowest:
Example:
|
Year(date) |
Returns the year, as an integer, extracted from the specified date
( Examples:
In these examples, |
Shortcut Functions
The shortcut functions perform miscellaneous operations. The following tables list the string functions available in the Math subnode of the Program Shortcut node in the Expression Editor.
Function | Description and Examples |
---|---|
Assign('$name', expression) |
Assigns the result of the expression calculation to the variable specified as the parameter. The function can be used to assign a value to an existing variable, or a new variable can be created with the expression calculation value assigned to it. Example:
In this example, |
Assign('$name', expression,
resetExpression) |
Assigns the result of the expression calculation to the variable specified as the parameter. The expression value is assigned to the variable when the variable is set, and the resetExpression value defines when the variable value should be reset. The function can be used to assign a value to an existing variable, or a new variable can be created and the expression calculation value is assigned to it. Example:
In this example, |
IIf(expression, truePart,
falsePart) |
Returns one of two values, depending on the evaluation
of the expression: If the expression evaluates to Example:
In this example, You can also use this function to set a field value to Null. Example:
|
IsNull(value, nullValue) |
Returns nullValue if value is NULL; otherwise, returns value. Example:
In this example, |
NullIf(value1, value2) |
Returns NULL if value1 is equal to value2. |
Switch(expression_1, value_1, expression_2,
value_2, ...) |
Returns the value (value_n) that corresponds to
the first expression (expression_n) that evaluates to Example:
In this example, |
Application-Specific Functions
Application-specific functions are specific for the application in which you will run the report. That is why these functions are not listed in the Expression Editor dialog box; you need to enter these functions manually.
The following table includes the application-specific functions available in MYOB Acumatica Report Designer.
Function | Description and Examples |
---|---|
GetAPPaymentInfo(accountCD, paymentMethodID, detailID,
acctCD) |
Returns the value of the specified AP payment attribute (detailID) for a specific cash account (accountCD), payment method (paymentMethodID), and vendor (acctCD). The function returns the attribute value as it is specified in the Payment Instructions section on the Payment Settings tab of the Vendors (AP303000) form. If the specified record is not available, the function returns an empty string. Example:
|
GetARPaymentInfo(accountCD, paymentMethodID, detailID,
pMInstanceID) |
Returns the value of the specified AR payment attribute (detailID) for a specific cash account (accountCD), payment method (paymentMethodID), and customer (acctCD). The function returns the attribute value as it is specified on the Payment Method Details tab of the Customer Payment Methods (AR303010) form. If the specified record is not available, the function returns an empty string. Example:
|
GetRemitPaymentInfo(accountCD, paymentMethodID, detailID)
|
Returns the value of the specified payment attribute (detailID) for a specific cash account (accountCD), payment method (paymentMethodID), and vendor or customer (acctCD). The function returns the attribute value as it is specified on the Remittance Settings tab of the Cash Accounts (CA202000) form. If the specified record is not available, the function returns an empty string. Example:
|
DAC Field Modifiers
The following table includes the modifiers that can be applied to a DAC field available in MYOB Acumatica Report Designer.
Function | Description and Examples |
---|---|
.Raw |
Returns the original field value without any additional processing (as it is stored in database). Example:
|
.Format |
Depending on a field type returns one of the following:
|
.DisplayName |
Returns the display name for the field. Example: SOOrder.CustomerRefNbr.DisplayName returns External Reference. |