I recently came across an application where I needed to use a multi-value parameter in SQL Server Reporting Services (SSRS). I always seemed to have trouble with these in the past. This time I found them very easy to use because I found (re-discovered?) a simple way.
The basic idea is to set up a parameter as if it were going to be a single value parameter with the topmost row selected by default. I will walk through the steps of this scenario.
I chose the AdventureWorks database to do this sample and focused on June 2004 Sales to get an easy dataset to work with.
1. Create the basic dataset:
2. Set up the layout for the report:
3. Preview the report with no parameters:
4. Create a new dataset for the territories list:
5. Set up the parameter, TerritoryID, like a normal single-value parameter. Be sure to set the default value to make it default to the topmost row in the list. In this case, the topmost is “Australia”, TerritoryID of 9.
6a. Apply the filter to the table. Notice that I am not editing the dataset, but simply adding a filter to the table properties. If you are usually the type to edit the dataset (like myself), just hang with me for a second. Right-click the edge of the table and then choose Properties:
6b. Modify the table properties to add the filter. Since you can’t read it all, it says
=Fields!TerritoryID.Value = Parameters!TerritoryID.Value
7. Check the finished result. We now have a report with a single parameter. The topmost selection, Australia, is automatically selected and our filter is applied by default.
8. So far, so good–there is nothing extraordinary about what we’ve done so far. Now, we simple make the parameter multi-value by changing the report parameters and checking the Multi-value box:
9. Don’t rush off just yet, or you’ll see this error message when you choose Preview:An error occurred during local report processing. An error has occurred during report processing. The processing of FilterExpression for the table ‘Sales’ cannot be performed. Cannot compare data of types System.Byte and System.Object. Please check the data type returned by the Filter Expression.
10. You need to make one small change to the filter. Open the table properties again, but this time change the operator from equals (=) to IN. Since the Parameters!TerritoryID.Value now contains a comma separated list, we need to search IN instead of comparing.
11. Now, preview your report. The left image shows the initial preview, the right image shows the drop-down list blown out, you can see that Select All is selected by default.
One caveat is that performance is not going to be top notch because Reporting Services is filtering on the entire dataset every time. It would (most likely, depending on your implementation) be faster to filter in the dataset. However, this approach often requires a lot of development work on the T-SQL side to get it working. This approach is easy and quick enough for many applications. Enjoy.
Update: I found a good example of the hard way to do multi-value parameters (by using SQL). If you scroll down to the second post, there is source code there for converting a delimited string into a table variable. I have re-formatted the charlist_to_table source code to make it more legible.