Sage 200 Report Designer - Report Designer Functions
Description

In Sage Report Designer, as well as adding variables to show values, you can also add expressions to return values based on variables. For example, you can show a percentage value of sales invoices, or calculate the number of days between 2 different dates. In addition to basic calculations, you can also use more advanced functions.
For information about how to add an expression to a report, please refer to article .


TIP: Another type of function is the If statement. This is an expression that is used on a report to say if a certain condition is met then do one thing, else if the condition is not met do something else. For further information about If statements, please refer to Article

NOTE: This article has been prepared and issued to you as a goodwill gesture only and Sage accepts no liability or responsibility for its use. For further support please refer to your Business Partner.

NOTE: If you are viewing this article from the Sage website, a list of Sage 200 Report Designer articles are now available. 

Cause
Resolution

Below is a list of some of the more advanced functions you can use within Sage Report Designer. For full details and examples of how to use the functions, please refer to the Function details tab.

FunctionDescription
Ceiling( )Rounds the value up to the nearest integer.
Concat( )Combines two values into one, creating a new value.
Contains( )Searches for characters in a string.
Count( )Counts the number of instances on a report.
CountIf( )Counts the number of instances on a report where the specified conditions are satisfied.
CountUnique( )Counts the number of unique instances of a specified variable.
Cstring(variable)Converts a numeric field to an alphanumeric string.
DateTimeToFormattedString( )Controls how dates appear.
DayfromDate( )Returns the day part of a date.
EndsWith( )Displays whether or not a string ends with a specified character.
Floor( )Rounds the value down to the nearest integer.
FormatString( )Prints a string, for example, a piece of text, with one or more predefined expressions inserted into the string using placeholders.
If( )Displays certain values depending on the condition specified.
Indexof( )Finds the position of a particular character in a string.
Length( )Displays how many characters exist in a string.
Max( )Displays the maximum value in a sequence.
Min( )Displays the minimum value in a sequence.
MonthfromDate( )Returns the month part of a date.
Now( )Displays the current PC date.
PadLeft( )To ensure a field contains a certain number of characters, this function inserts additional characters to the left of the value.
PadRight( )To ensure a field contains a certain number of characters, this function inserts additional characters to the right of the value.
ParseDateTime( )Converts alphanumeric fields to date fields for use in expressions and filters.
Previous( )Changes a value based on the previous line value.
Remove( )Removes a specified number of characters from a stated starting point in the string.
Replace( )Replaces a specified character in a string with another character.
StartsWith( )Displays whether or not a string starts with a specified character. Cannot be used as a report filter.
StringToFloat( )Converts alphanumeric fields to numeric fields for use in expressions and filters, when the fields contain decimal numbers.
StringToInteger( )Converts alphanumeric fields to numeric fields for use in expressions and filters, when the fields contain whole numbers.
Substring( )Displays part of a string from a specified starting point.
SumIf( )Totals only the values that meet the condition specified.
ToLower( )Converts the field to lower case.
ToUpper( )Converts the field to upper case.
Truncate( )Rounds a value to the nearest whole number in the direction of zero.
YearfromDate( )Returns the year part of a date.

To see details of how to use a function, select it from the list below:

Ceiling

Tip: To get the values you need, you can combine more than one function in a single expression.

FunctionReason for useOther information
Ceiling( )Determines the closest integer that is more than the specified number. It rounds up
Examples:
  • You can round a customer account balance up to the nearest whole number, for example, the following function displays a customer account balance of £20.11 as £21.00:

    Ceiling(SLCustomerAccounts.AccountBalance)

Concat
FunctionReason for useOther information
Concat( )To combine two values into one, creating a new value.
Example:
  • To combine the word Tel: and the customer's telephone number into one field, making it easier to align and move, use the following function:

    Concat("Tel: ",SLCustomerAccounts.ContactTelephoneNumber)

  • You can also use Concat function to get the currency symbol to print directly in front of a numeric value. For example, to get the currency symbol to print directly before the SOPInvoiceCredits.InvoicedGrossValue, use the following function:

    Concat(SYSCurrencies.Symbol, FormatString("{0:N2}", (SOPInvoiceCredits.InvoicedGrossValue)))

NOTE: The properties of this expression must be set to signed. If not, when running the layout, the following message appears: 'Sage.expressions.DefaultLibraries.Accounts.Unsigned(system.string) is not defined.'


Contains
FunctionReason for useOther information
Contains( )Searches for characters in a string.
  • If the statement is true it shows a value of 1, if it's false it shows 0.
  • You can use this with If statements.
  • This function is case sensitive.
Example:
  • If a customer's post code contains the letters NE, the following function displays 1. If not, it displays 0:

    Contains(SLCustomerLocations.C_AddressLine5, "NE")

  • If the customer's post code contains the letters NE, the following function displays the post code. If not, it displays nothing:

    Contains(SLCustomerLocations.C_AddressLine5, "NE") ? (SLCustomerLocations.C_AddressLine5) : ""

Count
FunctionReason for useOther information
Count( )Counts the number of instances on a report.
  • If added to a details section it shows a running count.
  • If added to a footer section it shows the total count for the group or the report.
Example:

To count the number of customer records on a report:

Count(SLCustomerAccounts.CustomerAccountNumber)


CountIf
FunctionReason for useOther information
CountIf( )Counts the number of instances on a report if the specified conditions are satisfied.
  • If added to a details section it shows a running count.
  • If added to a footer section it shows the total count for the group or the report.
  • This function is not case sensitive.
Example:

To count the number of customer records on a report that contain an A in the account reference:

Countif(SLCustomerAccounts.CustomerAccountNumber like "%A%")


CountUnique
FunctionReason for useOther information
CountUnique( )Counts the number of unique instances of a specified variable.
Example:

On the Simple Stock Transaction History report, to show the number of sources/destinations the item has been associated with:
Countunique(TransactionHistories.SourceAreaReference)


CString
FunctionReason for useOther information
CString( )Converts a numeric field to an alphanumeric string or text.
  • You can use this in Email Options > Subject to show a numeric value, as numeric variables in the email subject line generate the message:
  • 'You must enter an expression that returns a system string value.'
Example:
  • To convert an invoice number to an alphanumeric string:

    CString(SOPInvoiceCredits.DocumentNo)

  • To show the text Sales Invoice and the invoice number on an email subject line:

    "Sales Invoice" + " " + CString(SOPInvoiceCredits.DocumentNo)
DateTimeToFormattedString
FunctionReason for useOther information
DateTimeToFormattedString( )Controls how dates appear.
  • You can use this for grouping reports by date.
  • Using this function, you can separate the date values with various characters, for example / or -.
Examples:
  • To show an invoice date in the format dd/MM/yyyy with the time as hh:mm:ss:

    DateTimeToFormattedString( PLSupplierAccounts.DateOfLastTransaction, "dd/MM/yyyy hh:mm:ss")
  • To show only the month part of an invoice date, for example, 01, 02, 03 and so on:

    DateTimeToFormattedString( PLSupplierAccounts.DateOfLastTransaction, "MM")
  • To show the month and year of an invoice date, for example, September 2011:

    DateTimeToFormattedString(PLSupplierAccounts.DateOfLastTransaction, "MMMM yyyy")

  • To show the company name and invoice date on an email subject line:

    SYSCompanies.CompanyName + " " + DateTimeToFormattedString(SOPOrderReturns.DocumentDate, "dd-MM-yyyy")

DayfromDate
FunctionReason for useOther information
DayfromDate( )Returns the day part of a date.
Example:

If a customer's account was opened on 14/02/2013, the following function shows 14:

Dayfromdate(SLCustomerAccounts.AccountOpened)


EndsWith
FunctionReason for useOther information
EndsWith( )

Displays whether or not a string ends with a specified character.

  • If the statement is true it shows a value of 1, if it's false it shows 0.
  • You can use this with If statements.
  • This function is case sensitive.
Examples:
  • If the customer's account reference ends with R, the following function displays 1. If not, it displays 0:

    Endswith(SLCustomerAccounts.CustomerAccountNumber, "R")
  • If the customer's account reference ends with R, the following function displays the account reference. If not, it displays nothing:

    Endswith(SLCustomerAccounts.CustomerAccountNumber, "R") ? (SLCustomerAccounts.CustomerAccountNumber) : ""

Floor
FunctionReason for useOther information
Floor( )Determines the closest integer that is less than the specified number. It rounds down.You can use this to display pounds when displaying pounds and pence separately.
Examples:
  • The following function displays a customer account balance of £75.85 as £75.00:

    Floor(SLCustomerAccounts.AccountBalance)

FormatString
FunctionReason for useOther information
FormatString( )

Prints a string, for example, a piece of text, with one or more predefined expressions inserted into the string using placeholders.

The function is written as:

FormatString("string before placeholder zero {0} string after placeholder zero {1} string after placeholder one etc.", placeholder expression 0, placeholder expression 1)

The placeholders appear as {0}, {1} and so on. They can be individually formatted, for example:

  • {0:f2} - The value shown by placeholder zero is formatted to two decimal places.
  • {1:c2} - The value shown by placeholder one is formatted as a currency with two decimal places.
Examples:
  • To show a customer's balance and remaining credit as one string on the sales Ledger List of Accounts :

    FormatString("Customer{0} has a balance of {1} and {2} credit remaining.", SLCustomerAccounts.CustomerAccountNumber, SLCustomerAccounts.AccountBalance, (SLCustomerAccounts.CreditLimit - SLCustomerAccounts.AccountBalance))


This would show for example, Customer ABB001 has a balance of 16,003.00 and 250.00 credit remaining.

FormatString("Customer{0} has a balance of {1:c2} and {2:c2} credit remaining.", SLCustomerAccounts.CustomerAccountNumber, SLCustomerAccounts.AccountBalance, (SLCustomerAccounts.CreditLimit - SLCustomerAccounts.AccountBalance))


This example would show Customer ABB001 has a balance of £16,003.00 and £250.00 credit remaining.

If
FunctionReason for useOther information
If( )To display certain values depending on the condition specified.
  • This can be used in conjunction with other functions.
  • You can nest If statements to build up more complicated arguments.
  • The ? command is equivalent to Then.
  • The : command is equivalent to Else.
Example:
  • When viewing the sales ledger transactions report, indicate whether there has been recent activity on the account based on a date of your choosing:

    SLCustomerAccounts.DateOfLastTransaction > #2013-07-01# ? "Recent Activity" : "No recent activity"
  • The following nested If statements shows different wording depending on the gross value of the transaction:

    (SLPostedCustomerTrans.BaseGrossValue >= 0 and SLPostedCustomerTrans.BaseGrossValue <= 999) ? "LOW" : (SLPostedCustomerTrans.BaseGrossValue >= 1000 and SLPostedCustomerTrans.BaseGrossValue <= 9999.99) ? "HIGH" : "OTHER"

For further information about constructing If statement expressions, please refer to article .


Indexof
FunctionReason for useOther information
Indexof( )Finds the position of a particular character in a string.This can be combined with the Substring function to only return the value of a field up to a certain character.
Examples:
  • To find the position of the first space in a customer's contact name:

    Indexof(SLCustomerAccounts.ContactName, " ")- returns the position of the first space
  • You can then combine this function with the substring function to return the first name held in the SLCustomerAccounts.ContactName as follows:

    Substring(SLCustomerAccounts.ContactName,0,Indexof(SLCustomerAccounts.ContactName, " "))
  • Alternatively, to show only the surname of a customer's contact name:

    Substring(SLCustomerAccounts.ContactName,(Indexof(SLCustomerAccounts.ContactName, " ")))

Length
FunctionReason for useOther information
Length( )Displays how many characters exist in a string.
Example:

To display how many characters appear in a customer's account name:

Length(SLCustomerAccounts.CustomerAccountName)


Max
FunctionReason for useOther information
Max( )Displays the maximum value in a sequence.
  • If added to the details section it shows the maximum value at that point on the report.
  • If added to a footer it shows the maximum value for the group or the report.
Example:

To show the highest gross amount on a sales day book report:

Max(SLPostedCustomerTrans.BaseGrossValue)


Min
FunctionReason for useOther information
Min( )Displays the minimum value in a sequence.
  • If added to the details section it shows the minimum value at that point on the report.
  • If added to a footer it shows the minimum value for the group or the report.
Example:

To show the lowest gross amount on a sales day book report:

Min(SLPostedCustomerTrans.BaseGrossValue)


MonthfromDate
FunctionReason for useOther information
MonthfromDate( )Returns the month part of a date.
Example:

If a customer's account was opened on 14/02/2013, the following function shows 2:

Monthfromdate(SLCustomerAccounts.AccountOpened)


Now
FunctionReason for useOther information
Now( )Displays the current PC date.
  • As it is not possible to use the REPORT.DATE variable in an expression, the Now() function can be used instead.
  • Shows the PC date and not the Sage software date.
Example:
  • To show the PC date on a report:

    Now( )

  • To show a date 30 days from now:

    Now( ) + 30


PadLeft
FunctionReason for useOther information
PadLeft( )

To ensure a field contains a certain number of characters, this function inserts additional characters to the left of the value. The function is written as:

PadLeft(the value to pad, the character used to pad the field, the number of characters the field should contain)

When using this function with a numeric field, you must also use CString to convert the numeric value to an alphanumeric string.
Example:
  • On a product report, to always show stock codes with 10 characters, use the following function:

    PadLeft(StockItems.Code, "0", 10)

PadRight
FunctionReason for useOther information
PadRight( )

To ensure a field contains a certain number of characters, this function inserts additional characters to the right of the value. The function is written as:

PadRight(the value to pad, the character used to pad the field, the number of characters the field should contain)

When using this function with a numeric field, you must also use CString to convert the numeric value to an alphanumeric string.
Example:
  • On a product report, to always show stock codes with 10 characters, use the following function:

    PadRight(StockItems.Code, "0", 10)

ParseDateTime
FunctionReason for useOther information
ParseDateTime( )Converts alphanumeric fields into date fields that you can use in expressions and filters. For example, if the first line of the notes in an invoice contains a date, you can use this function to perform calculations based on the date.

For each record the relevant database value must contain a date and must be in a recognised date format. If not, when running the report, the following message appears:

'String was not recognised as a valid DateTime.'

Note: If a document contains an expression that uses the ParseDateTime() function on a text field, the document only runs for records that have a date value in the relevant field.

Example:

Example:

  • The manufacturer field on a stock item is used for dates the item was reviewed. They want a report to find out when each item should next be reviewed. Items should be reviewed every 60 days.

ParseDateTime(StockItems.Manufacturer) + 60


Previous
FunctionReason for useOther information
Previous( )To change a value based on the previous line value.You can use this with If statements.
Example:

The customer is running the Sales Order Profitability report and has noticed that some item codes are showing on the same sales order more than once. They want to investigate this further and to highlight them some way.

SOPOrderReturnLines.ItemCode = Previous(SOPOrderReturnLines.ItemCode) ? SOPOrderReturnLines.ItemCode + " *** " : SOPOrderReturnLines.ItemCode


Remove
FunctionReason for useOther information
Remove( )Removes a specified number of characters from a stated starting point in the string.You must always enter the starting position, where the first character is 0, and the number of characters to remove.
Examples:
  • Where a customer's account reference is ABC123, the following function removes the first 3 characters and displays 123:

    Remove(SLCustomerAccounts.CustomerAccountNumber, 0, 3)

Replace
FunctionReason for useOther information
Replace( )Replaces the specified character in a string with another character.This function is case sensitive.
Examples:
  • If the invoice order number is 1231, the following function displays the order number as A23A:

    Replace(SLCustomerAccounts.CustomerAccountNumber, "1", "A")

StartsWith
FunctionReason for useOther information
StartsWith( )Displays whether or not a string starts with a specified character.
  • If the statement is true it shows a value of 1, if it's false it shows 0.
  • You can use this with If statements.
  • Cannot be used as report filter.
  • This function is case sensitive.
Examples:
  • If the customer's account reference starts with A, the following function displays 1. If not, it displays 0:

    StartsWith(SLCustomerAccounts.CustomerAccountNumber, "A")
  • If the customer's account reference starts with A, the following function displays the account reference. If not, it displays nothing:

    StartsWith(SLCustomerAccounts.CustomerAccountNumber, "A") ? (SLCustomerAccounts.CustomerAccountNumber) : ""

StringToFloat
FunctionReason for useOther information
StringToFloat( )Converts alphanumeric fields to numeric fields for use in expressions and filters, when the fields contain decimal numbers.

If the report is run for fields containing non numeric information, the following message appears:

'Input string is not in correct format.'

Examples:
  • To multiply the quantity in stock by a number entered in Product Record > Part Number:

    Stringtofloat(StockItems.PartNumber) * StockItems.QuantityInStock

StringToInteger
FunctionReason for useOther information
StringToInteger( )Converts alphanumeric fields to numeric fields for use in expressions and filters, when the fields contain whole numbers.

This function only works when the report is run for records that contain numeric values in the selected field If you run the report to include records which contain no value or alphanumeric information, the following message appears:

'Input string was not in correct format.'

Examples:
  • To multiply the quantity in stock by a number entered in Product Record > Part Number:

    StringToInteger(StockItems.PartNumber) * StockItems.QuantityInStock

Substring
FunctionReason for useOther information
Substring( )

Displays part of a string from a specified starting point.

The function assigns the first character in a value the number 0, each subsequent character is numbered incrementally. For example, in the text ABCDE, A is equal to 0, B is equal to 1, and so on.

  • You can use this in conjunction with Cstring and StringToInteger to convert fields of one type to another.
  • This function only works with alphanumeric values.
  • If required, use the CString function to convert a numeric field to alphanumeric before performing the Substring function.
  • You can use this function within sorts and expressions.
  • You can also use this function to show the last characters in a string.
Examples:
  • If a sales order number is 123456, the following function displays 23456:

    Substring(SOPInvoiceCredits.DocumentNo, 1)

  • If a sales order number is 123456, the following function displays 234:

    Substring(SOPInvoiceCredits.DocumentNo, 1, 3)
    1 refers to the starting point in the string and 3 refers to the number of characters to display.

  • • To calculate the nominal code length and then display the last 4 characters:

    Substring(NLNominalAccounts.AccountNumber, length(NLNominalAccounts.AccountNumber) -4)

SumIf
FunctionReason for useOther information
SumIf( )

To total only the values that meet the condition specified. The function is written as:

SumIf(the value to sum, the condition that is to be met)

The Properties > Function should be set to None.
Example:
  • On an aged debtors report, to display the total for sales invoice (SC) transactions only, use the following function:

    Sumif(SLPostedCustomerTrans.BaseOutstandingValue, SLPostedCustomerTrans.TransactionTypeShortName like "SC")

ToLower
FunctionReason for useOther information
ToLower( )Converts the field to lower case.
Examples:
  • To convert a customer's account reference to lower case:

    ToLower(SLCustomerAccounts.CustomerAccountNumber)

ToUpper
FunctionReason for useOther information
ToUpper( )Converts the field to upper case.
Examples:
  • When printing invoices or credit notes, to convert the words invoice or credit note to upper case:

    ToUpper(SLCustomerAccounts.CustomerAccountNumber)

Truncate
FunctionReason for useOther information
Truncate( )Rounds a value to the nearest whole number in the direction of zero.
  • In the case of negative values, the number rounds up towards zero. For example, -100.30 rounds up to -100.00.
Example:
  • To round a commission value based on net amount down to the nearest whole value, use the following function:

    Truncate(SLPostedCustomerTrans.NetValue * 0.05)

YearfromDate
FunctionReason for useOther information
YearfromDate( )Returns the year part of a date.
Example:

If a customer's account was opened on 14/02/2013, the following function shows 2013:

YearFromdate(SLCustomerAccounts.AccountOpened)




Sage Business Partners can now log new cases online!

If you're unable to find the help you require from our online resources, log a new case with us without having to use phone or email. Simply select 'Manage your cases' from the dashboard or visit my.sage.co.uk/cases.


Sage 200 Services

Did you know Sage 200 customers now have access to a range of services direct with Sage. These include a bespoke Report Design Service, a library of How to Webinars and Ideas Portal just to name a few. Explore your potential using Sage 200 Services.


Steps to duplicate
Related Solutions