The Built-in Fields Collection includes the Global references in SSRS. And the references include the global variable, which is pre-defined by Microsoft. These are the standard SSRS Global References variables used in every report that we design, such as Page Numbers, Total Page Numbers, etc.
List of Global References in SSRS
The following are the list of available Global References in SSRS.
and their description is as follows
|ExecutionTime||DateTime||It will display the date and time of report execution.|
|PageNumber||Integer||It will return the current page number. It will assign 1 to the first page, and then it will increment by 1. If there are any page breaks, then this will return the result as per the page breaks. You can control the numbers by RestPageNumber property in Page Break.You have used this in either Page header, or Footer.|
|ReportFolder||String||This will return the folder path that contains the report.|
|ReportName||String||This will return the report name that you assigned while creating the report.|
|ReportServerURL||String||This will return the report Server URL on which the current report run.|
|TotalPages||Integer||It returns the total number of pages returned by the report.|
If the report doesn’t have the page breaks then this will return the same result as OverAllTotalpages
|PageName||String||It returns the name of the page.|
Use this in either SSRS Page header, or Footer.
|OverAllPageNumber||Integer||Returns the Current Page Number. This value is not affected by the ResetPageNumber property in Page Breaks. You can use this in either Page header, or Footer.|
|OverAllTotalpages||Integer||Returns the Total Number of Pages. This value is not affected by the ResetPageNumber property in Page Breaks.This is used in either Page Header or Footer|
|RenderFormat||RenderFormat||It returns the name of the renderer that we configured in the Reporting Service configuration file.|
Global References in SSRS Example
For this example, We are going to use the below-shown DataSet. Please refer to Shared Data Source and Dataset articles to understand the steps involved in creating Shared Data sources and Dataset that we used for this report.
And the Custom SQL query that we used in the above Dataset is:
-- SSRS Build-in Fields Example SELECT Prodcat.EnglishProductCategoryName, prodSubcat.EnglishProductSubcategoryName, prod.EnglishProductName, prod.Color, fact.[TotalProductCost], fact.SalesAmount, fact.TaxAmt, fact.[OrderDate], fact.[ShipDate] FROM dbo.DimProduct as prod INNER JOIN dbo.DimProductSubcategory AS prodSubcat ON prod.ProductSubcategoryKey = prodSubcat.ProductSubcategoryKey INNER JOIN dbo.DimProductCategory AS Prodcat ON prodSubcat.ProductCategoryKey = Prodcat.ProductCategoryKey INNER JOIN dbo.FactInternetSales AS fact ON fact.ProductKey = prod.ProductKey WHERE SalesAmount >= 3500
To explain the usage of the Global resources in SSRS Reports, We are going to use the below-shown report.
Please refer SSRS Table Report, Format-Table Report in SSRS article to understand the steps involved in creating and formatting Table Report, and see Grouping in SSRS Table Report article for Grouping techniques.
Let me show you the report preview
To add the SSRS Global variable, you have to drag and drop the required variable on to the Page Header or Footer.
For now, we are adding the ReportName variable to the header. I suggest you refer to Add Page Headers and footers article to understand the steps involved in adding header & Footer.
Click on the Preview tab to see the report preview. From the below screenshot, you can see that the SSRS global variable is showing the report name.
Let me format the Global variable. If you observe the Item, it is a text box. So please right-click on the variable and select the Text Box Properties option.
Once you select the Text Box Properties.. option, a new window called Text Box Properties will be opened.
Under the Font tab Please change the text box font. First, we will change the font family Property to Cambria, Size to 14pt, Font Style property to Bold, and color to dark Green. I suggest you refer Add TextBox to Report article to understand the formatting options
Click the OK button to close the properties window. Let me show you the Report Preview. Now you can see the Formatted Global Variable i.e., Report Name
Let me add two more variables to the existing report, and this time add them to Page Footer.
You can see them in the report preview.
If you require to combine one or two global variables or to create a complex variable using the Global variable, then you can use the Expression to built one.
Here we added one Empty TextBox to the page footer, and right-click on it will open the context. Please select the Expression option.
Once you select the Expression.. option, a new window called the Expression will open.
Use this expression window to combine one or more global variables. Here we will display Page Number along with the Total pages in one text box.
=Globals.PageNumber & " of " & Globals.TotalPages
Once you complete with the expression, Please click the OK button to close the expression window. Let me show you the report preview
The report is large so let me scroll down to the end of the first page
Let me navigate to the Last page. As you can see that the page number is updated.