Using Built-in Field References in Expressions (Reporting Services)

The Built-in fields collection, which includes both the Globals and the User collections, represent global values provided by Reporting Services when a report is processed. The Globals collection provides values such as the name of the report, the time when report processing began, and current page numbers for the report header or footer. The User collection provides the user identifier and language settings. These values can be used in expressions to filter results in a report.

Using the Globals Collection

The Globals collection contains the global variables for the report. On the design surface, these variables appear prefixed by an & (ampersand), for example, [&ReportName]. The following table describes the members of the Globals collection.

Member

Type

Description

ExecutionTime

DateTime

The date and time that the report began to run.

PageNumber

Integer

The current page number that can be used only in page header and footer.

ReportFolder

String

The full path to the folder containing the report. This does not include the report server URL.

ReportName

String

The name of the report as it is stored in the report server database.

ReportServerUrl

String

The URL of the report server on which the report is being run.

TotalPages

Integer

The total number of pages in the report that can be used only in page header and footer.

Members of the Globals collection return a variant. If you want to use a member of this collection in an expression that requires a specific data type, you must first cast the variable. For example, to convert the execution time variant into a Date format, use =CDate(Globals!ExecutionTime). For more information, see Working with Data Types in Expressions (Reporting Services).

Examples

The following examples show how to use a reference to the Globals collection in an expression:

  • This expression, placed in a text box in the footer of a report, provides the page number and total pages in the report:

    =Globals.PageNumber & " of " & Globals.TotalPages

  • This expression provides the name of the report and the time it was run. The time is formatted with the Microsoft .NET Framework formatting string for short date:

    =Globals.ReportName & ", dated " & Format(Globals.ExecutionTime, "d")

Using the User Collection

The User collection contains data about the user who is running the report. You can use this collection to filter the data that appears in a report, for example, showing only the data of the current user, or to display the UserID, for example, in a report title. On the design surface, these variables appear prefixed by an & (ampersand), for example, [&UserID].

The following table describes the members of the User collection.

Member

Type

Description

Language

String

The language of the user running the report. For example, en-US.

UserID

String

The ID of the user running the report. If you are using Windows Authentication, this value is the domain account of the current user. The value is determined by the Reporting Services security extension, which can use Windows Authentication or custom authentication.

For more information about supporting multiple languages in a report, see Solution Design Considerations for Multi-Lingual or Global Deployments (Reporting Services).

Using Locale Settings

You can use expressions to refer to the locale settings on a client computer through the User.Language value to determine how a report appears to the user. For example, you can create a report that uses a different query expression based on the locale value. The query may change to retrieve localized information from a different column depending on the language returned. You can also use an expression in the language settings of the report or report items based on this variable.

Note

While you can change the language settings of a report, you must be careful about any display issues this may cause. For example, changing the locale setting of the report can change the date format in the report, but it can also change the currency format. Unless there is a conversion process for the currency, this may cause the incorrect currency symbol to be displayed in the report. To avoid this, set the language information about the individual items that you want to change, or set the item with the currency data to a specific language.

Identifying UserID for Snapshot or History Reports

In some cases, reports that include the User!UserID variable will fail to show report data that is specific to the current user who is viewing the report. For more information, see Troubleshooting Reports: Reports Exported to a Specific File Format.