Lesson 3: Adding Parameters to Select Multiple Values in a List (Report Builder 2.0)
In this lesson, you will learn how to change a parameter to accept multiple values. These are known as multivalue parameters. By default, a parameter accepts a single value. The parameters that you created in the previous lesson, BusinessPersonID and DayoftheWeek, accepted single values. To modify a parameter to take multiple values, you must know whether the parameter was created automatically from a query parameter, like BusinessPersonID, or whether you created it manually by using the Report Data pane, like DayoftheWeek.
To modify a report parameter to accept multiple values, you just need to set a report parameter property. If the report parameter was based on a query parameter, you must also change the query. If you use the parameter in a filter, you must change the filter operator to specify a set of values instead of a single value.
To replace the existing dataset
In the Report Data pane, right-click the dataset DataSet1, and then click Query.
The text-based query designer opens.
Replace the text with the following query into the text box:
SELECT SH.OrderDate ,DATENAME(weekday, SH.OrderDate) as Weekday ,SH.SalesOrderNumber ,SD.OrderQty ,SD.LineTotal ,P.Name AS [Product] ,PS.Name AS [Subcategory] FROM Sales.SalesPerson SP INNER JOIN Sales.SalesOrderHeader AS SH ON SP.BusinessEntityID = SH.SalesPersonID INNER JOIN Sales.SalesOrderDetail AS SD ON SH.SalesOrderID = SD.SalesOrderID INNER JOIN Production.Product AS P ON SD.ProductID = P.ProductID INNER JOIN Production.ProductSubcategory AS PS ON PS.ProductSubcategoryID = P.ProductSubcategoryID INNER JOIN Production.ProductCategory AS PC ON PC.ProductCategoryID = PS.ProductCategoryID WHERE PC.Name = 'Clothing' AND (SH.OrderDate BETWEEN (@StartDate) AND (@EndDate)) AND SH.SalesPersonID IN (@BusinessPersonID)
This is the same query as before, except that the condition has been changed from equality = to inclusion IN:
AND SH.SalesPersonID IN (@BusinessPersonID)
Click the Run (!) button. When prompted for the query parameters, use the following table to enter values. The query designer does not support testing multivalue parameters.
The result set appears for the sales person Ranjit Varkey Chudukatil with BusinessPersonID = 290.
To edit the BusinessPersonID report parameter to accept multiple values
In the Report Data pane, expand Parameters, double click the BusinessPersonID parameter.
Select the Allow multiple values option.
Click Preview. The report runs automatically. A drop-down list for BusinessPersonID shows all sales person names.
A (Select All) value is provided as the first value in an available values drop-down list for a multivalue parameter. Use this check box to select all or clear all values.
To add a new dataset to populate the valid values for a report parameter
Switch to Design view.
In the Report Data pane toolbar, click New, and then click Dataset. The Dataset Properties dialog box opens.
In Name, type WeekDaysfromQuery.
In Query type, verify Text is selected.
Click Query Designer, and then click Edit As Text.
In the Query pane, paste the following query:
SET DATEFIRST 1; SELECT DISTINCT DATEPART(weekday, S.OrderDate) as WeekdayNumber, DATENAME(weekday, S.OrderDate) as Weekday FROM Sales.SalesOrderHeader S Order by WeekdayNumber
Click the Run (!) button on the query designer toolbar. The result set shows ordinal numbers and days of the week.
Click OK twice to exit the Dataset Properties dialog box.
The dataset WeekDaysfromQuery appears in the Report Data pane.
To edit a parameter to accept multiple values, default values, and valid values
In the Report Data pane, expand Parameters, and double-click DayoftheWeek. The Report Parameter Properties dialog box opens.
Select Allow multiple values.
Click Available Values.
Select Get values from a query.
In Dataset, from the drop-down list, select WeekDaysfromQuery.
In Value field, from the drop-down list, select WeekdayNumber.
In Label field, from the drop-down list, select Weekday.
When the user selects parameter values, they select from the labels, but the report uses the values. This is important when you set default values or a filter. The values must be the integer values for the WeekdayNumber field.
Click Default Values.
Select Specify values.
In Value, replace Friday with 6. Because the values come from a dataset that supplies both a weekday number and a weekday name, the default value must specify the weekday number. The value 6 represents Saturday.
In Value, type 7. This value represents Sunday.
Before you can preview the report, you must change the filter expression for the table to use the IN operator because the DayoftheWeek parameter accepts multiple values.
To change a filter to use a multivalue parameter
In the Report Data pane, right-click DataSet1, and then click Dataset Properties.
Click Filters. There is already a filter that has been added for DayoftheWeek from Lesson 1.
In Expression, from the drop-down list, verify the value is [Weekday].
Change Operator from the equal sign (=) to In.
In Value, type [@DayoftheWeek.Label].
Specify the parameter label so that the name of the week day is compared against the label field, not the numeric field for weekday.
The filter for the table is now set to compare the value of the field Weekday with the label of the parameter DayoftheWeek using the In operator. When you choose multiple values for the report parameter, the filter will test each row of the table to see if the Weekday field exists in the DayoftheWeek collection.
Click Run to preview the report. The report shows the report parameter DaysoftheWeek with default values Saturday and Sunday, which are the labels for the default values that you specified. Use the drop-down list to select multiple values for the DayoftheWeek parameter.
You have successfully changed report parameters properties from single valued to multivalued. You have made the necessary changes in a query, a filter, and an expression to use a multivalue parameter collection. You have learned to use multivalue parameters in an expression. In the next lesson, you will learn how to create parameters whose values are populated conditionally based on a selected value from a previous parameter. See Lesson 4: Adding Cascading Parameters (Report Builder 2.0).