Creating Computed Columns

Posted on 12/11/2023

computed columns
intermediate
functions
scripting

What are Computed Columns?

Computed Columns in BIRT Studio are columns that are created using the custom functions provided in BIRT Studio. The functions in BIRT Studio are somewhat similar to function calls in a modern programming language such as Python or Javascript where it is written as functionName(arg1, arg2, etc.). The function is written independently in a text box that is called on

Creating a Computed Column

To create a computed column in BIRT Studio, right click on a column header and select Column > New Computed Column. This will open the New Computed Column window.

In the Column Label field, enter a label for the column. This will be the name that appears in the column header. There is a Category dropdown that will allow you to browse the existing function categories mentioned in BIRT Studio Functions below. Changing this dropdown changes the functions available in the Select Function area.

To enter a custom expression, select “Advanced…” in any category. This shows a previously hidden Enter Expression text area. Enter your custom expression here. Click the Validate button to check if the expression is valid. If it is valid, a dialog stating “The expression is valid” will appear. If it is invalid, BIRT Studio will alert you. Click OK to close the dialog. Click Cancel to close the New Computed Column window without saving. Click OK in the New Computed Column window to save the computed column.

BIRT Studio Functions

The functions in BIRT Studio are separated into several categories in the UI:

  • Comparison
  • Financial
  • Text
  • Math
  • Date & Time

The functions that appear in the UI when selecting any one of the below categories is not the comprehensive list. There are more functions that are not listed but can still be used to write computed columns. See the full list below. For easier navigation, each function is linked in the Table of Contents.

ABS()

Returns the absolute value of a number without regard to its sign.

Syntax ABS(number) Arguments
number

A numeric expression.

Returns

A number that represents the absolute value of num

ADD_DAY()

Returns a date that is a specified number of days from a given date.

Syntax ADD_DAY(date, daysToAdd) Arguments
  • date

    A date expression.

  • daysToAdd

    A numeric expression.

Returns

The date value that results from adding the specified number of days to the start date

ADD_HOUR()

Returns a date that is a specified number of hours from a given date.

Syntax ADD_HOUR(date, hoursToAdd) Arguments
  • date

    The date or date expression that represents the start date. If a start date does not have a time value, the function assumes the time is midnight, 12:00 AM.

  • hoursToAdd

    The number of hours to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date and time value that results from adding the specified number of hours to the start date

ADD_MINUTE()

Returns a date that is a specified number of minutes from a given date.

Syntax ADD_MINUTE(date, minutesToAdd) Arguments
  • date

    The date or date expression that represents the start date. If a start date does not have a time value, the function assumes the time is midnight, 12:00 AM.

  • minutesToAdd

    The number of minutes to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date and time value that results from adding the specified number of minutes to the start date

ADD_MONTH()

Returns a date that is a specified number of months from a given date.

Syntax ADD_MONTH(date, monthsToAdd) Arguments
  • date

    The date or date expression that represents the start date

  • monthsToAdd

    The number of months to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date value that results from adding the specified number of months to the start date

ADD_QUARTER()

Returns a date that is a specified number of quarters from a given date.

Syntax ADD_QUARTER(date, quartersToAdd) Arguments
  • date

    The date or date expression that represents the start date

  • quartersToAdd

    The number of quarters to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date value that results from adding the specified number of quarters to the start date

ADD_SECOND()

Returns a date that is a specified number of seconds from a given date.

Syntax ADD_SECOND(date, secondsToAdd) Arguments
  • date

    The date or date expression that represents the start date

  • secondsToAdd

    The number of seconds to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date and time value that results from adding the specified number of seconds to the start date

ADD_WEEK()

Returns a date that is a specified number of weeks from a given date.

Syntax ADD_WEEK(date, weeksToAdd) Arguments
  • date

    The date or date expression that represents the start date

  • weeksToAdd

    The number of weeks to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date value that results from adding the specified number of weeks to the start date

ADD_YEAR()

Returns a date that is a specified number of years from a given date.

Syntax ADD_YEAR(date, yearsToAdd) Arguments
  • date

    The date or date expression that represents the start date

  • yearsToAdd

    The number of years to add to the start date. If you specify a negative number, the result appears to subtract the number from the start date

Returns

The date value that results from adding the specified number of years to the start date

BETWEEN()

Tests if a value is between two specified values

Syntax BETWEEN(value, upperBound, lowerBound) Arguments
  • value

    The value to test. The value can be a string, numeric, or date value.

  • upperBound

    The first value in the range of values to which to compare. String and date values must be enclosed in double quotation marks (" ")

  • lowerBound

    The second value in the range of values to which to compare. String and date values must be enclosed in double quotation marks (" ")

Returns

True if the value is between the upper and lower bounds, false otherwise

CEILING()

Returns the smallest integer greater than or equal to a number.

Syntax CEILING(number, significance) Arguments
  • number

    The numeric value to round up

  • significance

    The multiple to which to round.

Returns

The smallest integer greater than or equal to the number

DAY()

Returns a number from 1 to 31 that represents the day of the month

Syntax DAY(date) Arguments
date

A date expression.

Returns

The number of the day of the month for the specified date value

DIFF_DAY()

Calculates the number of days between two date values

Syntax DIFF_DAY(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of days between the two date values

DIFF_HOUR()

Calculates the number of hours between two date values

Syntax DIFF_HOUR(date1, date2) Arguments
  • date1

    The first date value. If the date does not have a time value, the function assumes the time is midnight, 12:00 AM.

  • date2

    The second date value. If the date does not have a time value, the function assumes the time is midnight, 12:00 AM.

Returns

The number of hours between the two date values

DIFF_MINUTE()

Calculates the number of minutes between two date values

Syntax DIFF_MINUTE(date1, date2) Arguments
  • date1

    The first date value. If the date does not have a time value, the function assumes the time is midnight, 12:00 AM.

  • date2

    The second date value. If the date does not have a time value, the function assumes the time is midnight, 12:00 AM.

Returns

The number of minutes between the two date values

DIFF_MONTH()

Calculates the number of months between two date values

Syntax DIFF_MONTH(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of months between the two date values. The function calculates the difference by subtracting the month number of `date1` from the month number of `date2`

DIFF_QUARTER()

Calculates the number of quarters between two date values

Syntax DIFF_QUARTER(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of quarters between `date1` and `date2`

DIFF_SECOND()

Calculates the number of seconds between two date values

Syntax DIFF_SECOND(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of seconds between `date1` and `date2`

DIFF_WEEK()

Calculates the number of weeks between two date values

Syntax DIFF_WEEK(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of weeks between `date1` and `date2`

DIFF_YEAR()

Calculates the number of years between two date values

Syntax DIFF_YEAR(date1, date2) Arguments
  • date1

    The first date value

  • date2

    The second date value

Returns

The number of years between `date1` and `date2`

FIND()

Finds the location of a substring in a string

Syntax FIND(strToFind, str, startPosition?) Arguments
  • strToFind

    The substring to search for. The search is case-sensitive

  • str

    The string in which to search

  • startPosition

    The position in `str` where the search starts

Returns

The numberical position of the substring in the string

IF()

Returns one value if a specified condition evaluates to TRUE, or another value if the condition evaluates to FALSE

Syntax IF(condition, doIfTrue, doIfFalse) Arguments
  • condition

    The condition to test

  • doIfTrue

    The value to return if the condition evaluates to TRUE. The value can be a BIRT Expression that evaluates to any of the following in "Types Allowed"

  • doIfFalse

    The value to return if the condition evaluates to FALSE. The value can be a BIRT Expression that evaluates to any of the following in "Types Allowed"

Returns

Returns the `doIfTrue` value if condition is TRUE or the `doIfFalse` value if the condition is FALSE

IN()

Tests if a value is equal to a value in a list

Syntax IN(value, check1, ..., checkN) Arguments
  • value

    The value to test. The value can be a string, numeric, or date value

  • check1, ..., checkN

    The value or values to which to compare. Can add as many checks as needed.

Returns

Returns TRUE if value is equal

ISNULL()

Tests if a value in a specified data field is a null value. A null value means that no value exists

Syntax ISNULL(value) Arguments
value

The data field in which to check for null values

Returns

Returns TRUE if a value in the specified data field is null. Returns FALSE otherwise.

LEFT()

Extracts a substring from a string, starting from the left-most, or first, character

Syntax LEFT(str, n?) Arguments
  • str

    The string from which to extract a substring

  • n

    The number of characters to extract, starting from the first character

Returns

A substring of a specified length

  • If you omit `n`, the number of characters to extract, the function returns the first character only
  • If `n` is zero, the function returns an empty string
  • If `n` is greater than the length of the string, the function returns the entire string

LEN()

Counts the number of characters in a string

Syntax LEN(str) Arguments
str

The string expression to evaluate

Returns

The number of characters in a specified string

LIKE()

Tests if a string matches a pattern

Syntax LIKE(str, pattern) Arguments
  • str

    The string to evaluate

  • pattern

    The string pattern to match. You must enclose the pattern in double quotation marks (" "). The match is case-sensitive. The pattern does not support full regex. Characters supported are a percent character (%) and an underscore (_).

Returns

TRUE if the string matches the pattern. Otherwise FALSE.

LOWER()

Converts all letters in a string to lowercase

Syntax LOWER(str) Arguments
str

The string to convert to lowercase

Returns

The string converted to lowercase

MATCH()

Returns a boolean indicating whether a pattern exists within a string

Syntax MATCH(str, pattern) Arguments
  • str

    The string to evaluate

  • pattern

    The string pattern to match. The pattern uses ECMAScript (Javascript) syntax, as defined in Section 15.10 of Standard ECMA-262.

Returns

TRUE if the string matches the pattern. Otherwise FALSE.

MOD()

Returns the modulo value for a number and divisor

Syntax MOD(number, divisor) Arguments
  • number

    The numeric value to divide

  • divisor

    The numeric value to divide by

Returns

The remainder value of number divided by divisor

MONTH()

Returns the month for a specified date value

Syntax MONTH(date, option?) Arguments
  • date

    The date value from which to extract the month

  • option

    An optional parameter that specifies the format of the month. If you do not specify a format, the function returns the month as a number from 1 to 12

    • 1 to get the month as a number from 1 to 12
    • 2 to get the full month name. The result is locale-specific
    • 3 to get the abbreviated month name. The result is locale-specific
Returns

The month of the specified date value

NOT()

Negates a boolean expression

Syntax NOT(expression) Arguments
expression

The boolean value or expression to negate

Returns

TRUE if the expression evaluates to FALSE, and FALSE if the expression evaluates to TRUE

NOTNULL()

Tests if a value in a specified data field is a non-null value

Syntax NOTNULL(value) Arguments
value

The data field in which to check for non-null values

Returns

Returns TRUE if a value in the specified data field is not null. Returns FALSE otherwise.

NOW()

Returns the current date and time

Syntax NOW() Arguments

None

Returns

The current date and time

QUARTER()

Returns the quarter number for a specified date value

Syntax QUARTER(date) Arguments
date

The date value from which to extract the quarter

Returns

A number from 1 to 4 that represents the quarter for a specified date value

RIGHT()

Extracts a substring from a string, starting from the right-most, or last, character

Syntax RIGHT(str, n?) Arguments
  • str

    The string from which to extract a substring

  • n

    The number of characters to extract, starting from the last character

Returns

A substring of a specified length

ROUND()

Rounds a number to a specified number of decimal places

Syntax ROUND(number, decimalPlaces?) Arguments
  • number

    The numeric value to round

  • decimalPlaces

    The number of decimal places to round to

Returns

A number rounded to a specified number of digits

ROUNDDOWN()

Rounds a number down to a specified number of decimal places

Syntax ROUNDDOWN(number, decimalPlaces?) Arguments
  • number

    The numeric value to round

  • decimalPlaces

    The number of decimal places to round to. If omitted, assumes 0.

Returns

A number rounded down to a specified number of digits

ROUNDUP()

Rounds a number up to a specified number of decimal places

Syntax ROUNDUP(number, decimalPlaces?) Arguments
  • number

    The numeric value to round

  • decimalPlaces

    The number of decimal places to round to. If omitted, assumes 0.

Returns

A number rounded up to a specified number of digits

SEARCH()

Finds the location of a substring in a string. The substring can contain wildcard characters

Syntax SEARCH(strToFind, str, startPosition?) Arguments
  • strToFind

    The substring to search for. The search is case-sensitive

  • str

    The string in which to search

  • startPosition

    The position in `str` where the search starts

Returns

The numberical position of the substring in the string. The first character of a string starts at 1. If the substring is not found, the function returns 0.

SQRT()

Returns the square root of a number

Syntax SQRT(number) Arguments
number

The numeric value to find the square root of

Returns

The square root of the specified number

TODAY()

Returns the current date that includes a time value of midnight, 12:00 AM

Syntax TODAY() Arguments

None

Returns

The current date in the format MMM dd, yyyy 12:00 AM

TRIM()

Removes leading and trailing spaces from a string. Does not remove black characters between words

Syntax TRIM(str) Arguments
str

The string to remove leading and trailing spaces from

Returns

The string with leading and trailing spaces removed

TRIMLEFT()

Removes leading spaces from a string

Syntax TRIMLEFT(str) Arguments
str

The string to remove leading spaces from

Returns

The string with leading spaces removed

TRIMRIGHT()

Removes trailing spaces from a string

Syntax TRIMRIGHT(str) Arguments
str

The string to remove trailing spaces from

Returns

The string with trailing spaces removed

UPPER()

Converts all letters in a string to uppercase

Syntax UPPER(str) Arguments
str

The string to convert to uppercase

Returns

The string converted to uppercase

WEEK()

Returns a number from 1 to 52 that represents the week of the year

Syntax WEEK(date) Arguments
date

The date or date expression whose week of the year to get

Returns

The week of the year for the specified date value

WEEKDAY()

Returns the day of the week for a specified date value

Syntax WEEKDAY(date, option?) Arguments
  • date

    The date value from which to extract the day of the week

  • option

    An optional parameter that specifies the format of the day of the week. If you do not specify a format, the function returns the day of the week as a number from 1 to 7

    • 1 to get the day as a number from 1 (Sunday) to 7 (Saturday)
    • 2 to get the day as a number from 1 (Monday) to 7 (Sunday)
    • 3 to get the day as a number from 0 (Monday) to 6 (Sunday)
    • 4 to get the full weekday name. The result is locale-specific
    • 5 to get the abbreviated weekday name. The result is locale-specific
Returns

The day of the week for the specified date value

YEAR()

Returns the four digit year value for a specified date value

Syntax YEAR(date) Arguments
date

The date value from which to extract the year

Returns

The number that represents the year for the specified date value