To use IBM Cognos product documentation, you must enable JavaScript in your browser.

Functions

A function is a subroutine that returns a single value. You can use functions to create calculations and conditions to filter data. Functions are similar to operators in that they manipulate data items and return a result. Functions differ from operators in the format in which they appear with their arguments. This format allows them to operate with zero, one, two, or more arguments:

function (argument, argument, ...)

Functions are of these general types:

Function

Description

Date Functions

Accepts numeric input and returns a value that is a date.

Numeric Functions

Accepts numeric input and returns numeric values.

Aggregate Functions

Executes a predefined function and returns an aggregate value.

Text Functions

Accepts character input and can return both character and number values.

Date Functions

Date functions return a value that is either a date or a number that relates to a date.

Function

Description

Add-Days

Returns a datetime value resulting from adding a number of days to a date.

Add-Months

Returns a datetime value resulting from adding a number of months to a date.

Add-Years

Returns a datetime value resulting from adding a number of years to a date.

Age

Returns age as a day-month-year interval by subtracting a specified date from today's date.

Date-to-Days-from-1900

Returns the number of days since Jan 1, 1900 inclusive. The value returned is negative if the date is before 1900.

Day

Returns a numeric value for the day of the month from 1 to 31, from a date, datetime value, or interval.

Days-to-End-of-Month

Returns the number of days to the last day of the month from a date or datetime value.

First-of-Month

Returns the first day of the month from a date or datetime value.

Last-of-Month

Returns the last day of the month from a date or datetime value.

Month

Returns the month number as an integer from 1 to 12, from a date or datetime value.

Months-Between

Returns the number of months between two dates. If the first date is later than the second date, then the result is a negative number.

Today

Returns the current date according to the date set on your computer.

Year

Returns the year from the date.

Years-Between

Returns the number of years from one date to another date.

Add-Days

Returns a datetime value resulting from adding a number of days to a date.

Syntax
add-days (date_exp | datetime_exp, integer_exp)
Examples
add-days (today(), 10)

Returns the result: 03/30/2007 00:00

add-days (today(), -10)

Returns the result: 03/10/2007 00:00

Add-Months

Returns a datetime value resulting from adding a number of months to a date.

Syntax
add-months (date_exp | datetime_exp, integer_exp)
Examples
add-months (today(), 10)

Returns the result: 01/20/2007 00:00

add-months (today(), -10)

Returns the result: 05/20/2007 00:00

Add-Years

Returns a datetime value resulting from adding a number of years to a date.

Syntax
add-years (date_exp | datetime_exp, integer_exp)
Examples
add-years (today(), 10)

Returns the result: 03/20/2017 00:00

add-years (today(), -10)

Returns the result: 03/20/1997 00:00

Age

Returns age as a month-day-year interval by subtracting a specified date from today's date.

Syntax
age (date_exp | datetime_exp)
Example
age (1996-08-19)

Returns the result: 02/01/0002 00:00

Note

Date-to-Days-from-1900

Returns the number of days since Jan. 1, 1900 inclusive.The value returned is negative if the date is before 1900.

Syntax
date-to-days-from-1900 (date_exp | datetime_exp)
Example
date-to-days-from-1900 (1998-03-20)

Returns the result: 35873

Day

Returns a numeric value for the day of the month from 1 to 31, from a date, datetime value, or interval.

Syntax
day (date_exp | datetime_exp | interval_exp)
Examples
day (2007-03-20)

Returns the result: 20

day (2007-03-20 18:22:00.000)

Returns the result: 20

day (20 00:00:00.000)

Returns the result: 20

Days-to-End-of-Month

Returns the number of days to the last day of the month from a date or datetime value.

Syntax
days-to-end-of-month (date_exp | datetime_exp)
Example
days-to-end-of-month (2007-03-20)

Returns the result: 11

First-of-Month

Returns the first day of the month from a date or datetime value. The datetime value is converted from a date_exp value to a date with the same year and month, but the day is set to one.

Syntax
first-of-month (date_exp | datetime_exp)
Example
first-of-month (2007-03-20)

Returns the result: 03/01/2007 00:00

Last-of-Month

Returns the last day of the month from a date or datetime value.

Syntax
last-of-month (date_exp | datetime_exp)
Example
last-of-month (2007-03-21)

Returns the result: 03/31/2007 00:00

Month

Returns the month number as an integer from 1 to 12, from a date or datetime value.

Syntax
month (date_exp | datetime_exp)
Examples
month (2007-03-21)

Returns the result: 3

month (2007-03-21 09:21:00.000)

Returns the result: 3

Months-Between

Returns the number of months between two dates. If the first date is later than the second date, then the result is a negative number. This function does not round months; the days and time portions of the difference are ignored.

This function is processed only on an IQD data source.

Syntax
months-between (date_exp_1 | datetime_exp_1, date_exp2 | datetime_exp2)
Examples
months-between (2007-03-21, add-months (2007-03-21, 4))

Returns the result: 4

months-between (2007-01-31, 2007-02-01)

Returns the result: 0

months-between (2007-01-31, 2007-03-21)

Returns the result: 1

Today

Returns the current date according to the date set on your computer.

Syntax
today ()
Example
today ()

Returns today's date as the result.

Year

Returns the year from the date.

Syntax
year (date_exp | datetime_exp)
Example
year (2007-12-10)

Returns the result: 2007

Years-Between

Returns the difference between the year values of date_exp1 and date_exp2. If date_exp1 is later than date_exp2, the result will be a negative number.

Syntax
years-between (date_exp1 | datetime_exp1, date_exp2 | datetime_exp2)
Example
years-between (2005-03-21, 2007-03-21)

Returns the result: 2

Numeric Functions

Accepts numeric input and returns numeric values.

Function

Description

Ceiling

Returns a number rounded to the next highest integer.

Floor

Returns a number rounded to the next lowest integer.

Integer-Divide

Returns the integer obtained from truncating the result of an integer divided by a second integer.

Mod

Returns the remainder (modulus) of an integer divided by a second integer.

Number-to-String

Returns a string from a number.

Round-Down

Returns a number rounded down.

Round-Near

Returns a number rounded to the nearest value.

Round-Up

Returns a number rounded up.

Round-Zero

Returns a number rounded toward zero.

Sqrt

Returns the square root of a positive number.

Ceiling

Returns a number rounded to the next highest integer.

Syntax
ceiling (numeric_exp)
Examples
ceiling (-1.23)

Returns the result: -1

ceiling (1.23)

Returns the result: 2

Floor

Returns a number rounded to the next lowest integer.

Syntax
floor (numeric_exp)
Examples
floor (-1.23)

Returns the result: -2

floor (3.45)

Returns the result: 3

Integer-Divide

Returns the integer obtained from truncating the result of an integer divided by a second integer.

Syntax
integer-divide (integer_exp1, integer_exp2)
Examples
integer-divide (10, 20)

Returns the result: 0

integer-divide (20, 6)

Returns the result: 3

Mod

Returns the remainder (modulus) of an integer divided by a second integer. If the second integer is zero, Transformer issues a divide by zero error.

Syntax
mod (integer_exp1, integer_exp2)
Example
mod (245,3)

Returns the result: 2

Number-to-String

Returns a string from a number. If the number is negative, a minus sign (-) precedes the string. If the number is a real number, only the truncated integer part of the number is converted to a string.

Syntax
number-to-string (numeric_exp)
Examples
number-to-string (12345)

Returns the result: 12345

number-to-string (12345.678)

Returns the result: 12345

Round-Down

Returns a number rounded down.

The integer_exp value determines the position that is rounded. A positive integer_exp acts on the digits to the right of the decimal point. A negative integer_exp acts on the digits to the left of the decimal point. An integer_exp value of zero rounds the number and removes the decimal places.

Syntax
round-down (numeric_exp, integer_exp)
Examples
round-down (-113.6667, 0)

Returns the result: -114

round-down (-113.6667, 1)

Returns the result: -113.7

round-down (-113.6667, -1)

Returns the result: -120

round-down (-113.6667, -2)

Returns the result: -200

round-down (366.2162, 0)

Returns the result: 366

round-down (366.2162, 1)

Returns the result: 366.2

round-down (366.2162, -1)

Returns the result: 360

round-down (366.2162, -2)

Returns the result: 300

Round-Near

Returns a number rounded to the nearest value.

The integer_exp value determines the position that is rounded. A positive integer_exp value acts on the digits to the right of the decimal point. A negative integer_exp value acts on the digits to the left of the decimal point. An integer_exp value of zero rounds the number and removes the decimal places.

Syntax
round-near (numeric_exp, integer_exp)
Examples
round-near (-113.6667, 0)

Returns the result: -114

round-near (-113.6667, 1)

Returns the result: -113.7

round-near (-113.6667, -1)

Returns the result: -110

round-near (-113.6667, -2)

Returns the result: -100

round-near (366.2162, 0)

Returns the result: 366

round-near (366.2162, 1)

Returns the result: 366.2

round-near (366.2162, -1)

Returns the result: 370

round-near (366.2162, -2)

Returns the result: 400

Round-Up

Returns a number rounded up.

The An integer_exp value determines the position that is rounded. A positive An integer_exp value acts on the digits to the right of the decimal point. A negative An integer_exp value acts on the digits to the left of the decimal point. An integer_exp value of zero rounds the number and removes the decimal places.

Syntax
round-up (numeric_exp, integer_exp)
Examples
round-up (-113.6667, 0)

Returns the result: -113

round-up (-113.6667, 1)

Returns the result: -113.6

round-up (-113.6667, -1)

Returns the result: -110

round-up (-113.6667, -2)

Returns the result: -100

round-up (366.2162, 0)

Returns the result: 367

round-up (366.2162, 1)

Returns the result: 366.3

round-up (366.2162, -1)

Returns the result: 370

round-up (366.2162, -2)

Returns the result: 400

Round-Zero

Returns a number rounded toward zero.

The integer_exp value determines the position that is rounded. A positive integer_exp value acts on the digits to the right of the decimal point. A negative integer_exp value acts on the digits to the left of the decimal point. An integer_exp value of zero rounds the number and removes the decimal places.

Syntax
round-zero (numeric_exp, integer_exp)
Examples
round-zero (-113.6667, 0)

Returns the result: -113

round-zero (-113.6667, 1)

Returns the result: -113.6

round-zero (-113.6667, -1)

Returns the result: -110

round-zero (-113.6667, -2)

Returns the result: -100

round-zero (366.2162, 0)

Returns the result: 366

round-zero (366.2162, 1)

Returns the result: 366.2

round-zero (366.2162, -1)

Returns the result: 360

round-zero (366.2162, -2)

Returns the result: 300

Sqrt

Returns the square root of a positive number.

Syntax
sqrt (numeric_exp)
Examples
sqrt (2)

Returns the result: 1.4142135623731

sqrt (64)

Returns the result: 8

Text Functions

Text functions accept character input and can return both character and numeric values.

Function

Description

Char_Length

Returns the number of characters in a string.

First-Word

Returns the first word in a string.

Left

Returns a specific number of characters, starting at the left of the string.

Lower

Converts uppercase characters to lowercase.

Position

Returns the starting position of a string in a second string.

Reverse

Reverses the characters in a string.

Right

Returns a specific number of characters, starting at the right of the string.

String-to-Integer

Converts a string to an integer.

Substring

Returns a substring from a string.

Trim-Leading

Returns a string with leading spaces removed.

Trim-Trailing

Returns a string with trailing spaces removed.

Upper

Converts lowercase characters to uppercase.

Note: The Pack, Spread and Substitute text functions are not supported in Transformer version 8.x.

Char_Length

Returns the number of characters in a string.

Syntax
char_length (string_exp)
Examples
char_length ('ABCDEFG')

Returns the result: 7

char_length ('')

Returns the result: 0

char_length (' ')

Returns the result: 1

First-Word

Returns the first word in a string.

Syntax
first-word (string_exp)
Example
first-word ('Cat sat on the mat')

Returns the result: Cat

Left

Returns a specific number of characters, starting at the left of the string.

Syntax
left (string_exp, integer_exp)
Example
left ('ABCDEFG', 2)

Returns the result: AB

Lower

Converts uppercase characters to lowercase.

Syntax
lower (string_exp)
Example
lower ('ABCDEFG')

Returns the result: abcdefg

Position

Returns the starting position of string_exp1 in string_exp2. The first character in a string is at position one.

Syntax
position (string_exp1, string_exp2)
Examples
position ('DEF', 'ABCDEF')

Returns the result: 4

position ('Z', 'ABCDEFGH'

Returns the result: 0

Reverse

Reverses the characters in a string.

Syntax
reverse (string_exp)
Example
reverse ('ABCDEF')

Returns the result: FEDCBA

Right

Returns a specific number of characters, starting at the right of the string.

Syntax
right (string_exp, integer_exp)
Example
right ('ABCDEFG', 3)

Returns the result: EFG

String-to-Integer

Returns the integer representation of string_exp.

Syntax
string-to-integer (string_exp)
Example
string-to-integer (' 101 tents')

Returns the result: 101

Substring

Returns a substring from a string. The first character in the string is at position one.

Syntax
substring (string_exp, integer_exp1, integer_exp2)

where:

Example
substring ('abdefg', 3, 2)

Returns the result: de

Trim-Leading

Returns a string with leading spaces removed. For example, if you merge two data items with leading spaces, use trim-leading to eliminate the spaces between them.

Syntax
trim-leading (string_exp)
Example
trim-leading ('  ABC')

Returns the result: ABC

Trim-Trailing

Returns a string with trailing spaces removed. For example, if you merge two data items in an expression and the data items have trailing spaces, the spaces between the data items can be eliminated using the trim-trailing function.

Syntax
trim-trailing (string_exp)
Example
trim-trailing ('XYZ  ')

Returns the result: XYZ

Upper

Converts lowercase characters to uppercase.

Syntax
upper (string_exp)
Examples
upper ('Auriga')

Returns the result: AURIGA

upper ('DeEr')

Returns the result: DEER