This post describes one way to let users select all values in a filter in a data area such as a Tablix in Microsoft SQL Server Reporting Services.
During a recent Reporting Services 2008 course (6236) I was asked about how to use filtering in a data region, such as a Tablix, and present an option for the user to select all filter values.
A search for doing this with parameters gives you quite a few tutorials, such as Chris Hays’s from 2004. Searching for the same approach for filtering doesn’t yield the same amount of tutorials. So here is a quick guide for a similar approach for select all in filters.
This guide will use SQL server 2008 r2 and BIDS based on Visual Studio 2008.
Initial tasks for demo
Step 1, start BIDS and create your empty Reporting Services project
Above: Screenshot of the new project dialog.
Step 2, Create a new empty report (not through the wizard)
Above: Screenshot of Add New Item dialog.
Step 3, Create a demo dataset (with an empty data source)
Above: Dataset dialog.
Step 4, Create a Tablix and bind it to our dataset
Above: Screenshot of report body with a Tablix bound to our dataset and with the detail row showing our data field
Step 5, Preview report
To verify that we are still on track, check the preview of the report and make sure it displays our demo data
Above: Screenshot of preview of our not so impressive report
Step 6, Create a Parameter
To be able to filter our dataset through a prompt we need a parameter. We will create a manual one. Please use proper datasets mapped to your data for production reports.
Above: Manual filter items for all and for each of our demo data values.
Step 7, create filter in Tablix
Go to Tablix properties and choose the filter tab.
For our Filter Expression we want to create a filtering expression that can evaluate to true. In a traditional filtering expression we would just choose our field and choose to compare it to our parameter. In this scenario we want to do the logic in this expression so that we can do whatever logic is needed. In this case we choose to compare either to one of the parameter values , or check if the parameter is 0 (our “All” value from the parameter settings)
Above: Expression for Filter
For our Value expression we want to evaluate true so that we can compare the two. Note that we need to enter “=true”, not just “true”.
Above: Screenshot of Filter value expression.
Once we have our two expressions our filter properties for the Tablix will show as this:
Above: Filters dialog in Tablix properties
Step 8, test filtering
Run report and choose All in parameter:
Above: All data visible with All filter
Verify functionality with a specific parameter:
Above: Only some data is visible when filtering with parameter
More on filtering
The whole point on using data area filtering versus using data set parameters can be expanded on quite a bit. There are loads of resources on that around.
But trying to be complete: One aspect is how much data you want to generate from data source on initial report run, another is if you want to be able to run the same report with different data without generating another trip to the source. By using parameters and filtering on the data set you only retrieve a limited amount of data. By using filters you can run your report once against the data source and then filter on the intermediate result in a cache or on a report snapshot.