This SSRS article shows how to add page numbers to a report using the global variables. To do this, we must use the Page Numbers to combine PageNumber and TotalPages variables.
Right-click on the Datasets folder to create a new DataSet. The code below shows the data set we will use for this Add Page Numbers to SSRS Report example.
The Sql query that we used in this SSRS example is:
SELECT SubCat.[EnglishProductSubcategoryName] AS SubCategory,
Prod.EnglishProductName AS ProductName, Prod.Color,
SUM(Fact.OrderQuantity) AS Orders, SUM(Fact.TotalProductCost) AS ProductCost,
SUM(Fact.SalesAmount) AS Sales, SUM(Fact.TaxAmt) AS Tax
FROM FactInternetSales AS Fact
INNER JOIN DimProduct AS Prod ON Fact.ProductKey = Prod.ProductKey
INNER JOIN DimProductSubcategory AS SubCat ON Prod.ProductSubcategoryKey = SubCat.ProductSubcategoryKey
GROUP BY SubCat.[EnglishProductSubcategoryName],Prod.EnglishProductName, Prod.Color
How to add Page Numbers to the SSRS Report?
We designed a simple table report and formatted the font and colors to demonstrate the process of adding page numbers.
Since the numbers have to be repeated on each page, we have to place them in the page footer or header. So, right-click on the empty space, choose the insert option, and select Page Footer.
Right-click within the page footer, choose Insert, and then select the text box option to add a text box field.
Right-click on the empty text box and select the expression option from the context menu. Write the following expression to add or display page numbers in the SSRS table report.
="Page Number = " + CStr(Globals!PageNumber)
Now you can see the page numbers on each page of the report.
However, we need to find out how many pages are left. To get this, we have to alter the above expression so that it will display the total pages along with the page number.
="Page Number = " + CStr(Globals!PageNumber) + " Of " + Globals!TotalPages
Looking at the preview now, you can see the page number and the total number of pages the report has generated.
If you visit the last page, it shows Page Number = 4 of 4. Please adjust the text as per the requirement.