Lesson 4: Adding a Multivalue Parameter with Select All
New: 17 July 2006
In this lesson, you will change the SalesOrderID and DayoftheWeek parameters from single value parameters to multivalue parameters. Multivalue parameters allow you to select more than one value for a report parameter. To modify the report parameter SalesOrderID, you will change the query for the AdventureWorks dataset to test for @SalesPersonID in the set of selected values instead of equal to a single value, and check the report parameter multivalue property. To modify the DayoftheWeek report parameter, you will check the multivalue property, set the available values from a new dataset, and provide an expression for the default values. You will create a new dataset to provide available values for the DayoftheWeek parameter. Finally, you will add a text box to the report to display parameter values for the DayoftheWeek selections made.
To open the Sales Orders report
In SQL Server Business Intelligence Development Studio, open the Tutorial Report Server project created in the previous lesson.
In Solution Explorer, double-click the Sales Orders report. The report opens in Layout view.
Click the Data tab.
To modify the dataset query to test for inclusion in a set of values
From the Datasets drop-down list, choose AdventureWorks.
Modify the WHERE clause of the existing query by changing the
@SalesPersonID
test from equality (= (@SalesPersonID)
) to inclusion(IN (@SalesPersonID)
).Replace the query string for this dataset with the following query.
SELECT S.OrderDate, DATENAME(weekday, S.OrderDate) as Weekday, S.SalesOrderNumber, S.TotalDue, C.FirstName, C.LastName FROM HumanResources.Employee E INNER JOIN Person.Contact C ON E.ContactID = C.ContactID INNER JOIN Sales.SalesOrderHeader S ON E.EmployeeID = S.SalesPersonID WHERE ( S.OrderDate BETWEEN (@StartDate) AND (@EndDate) AND S.SalesPersonID IN (@SalesPersonID) )
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.
@StartDate
20010101
@EndDate
20030101
@SalesPersonID
286
Click OK. The result set appears for the sales person Ranjit Varkey Chudakatil with SalesPersonID = 286.
To set the properties of the report parameter SalesPersonID
On the Report menu, select Report Parameters. The Report Parameters dialog box opens.
In the Parameters pane, select SalesPersonID.
In the Properties section, check Multi-value.
In the Prompt text box, type Select Sales Persons:.
Click OK.
Click the Preview tab. The report shows a drop-down list with sales person names.
Note
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.
Note
The Select All option was disabled in SQL Server 2005 Service Pack 1, but restored in SQL Server 2005 Service Pack 2.
To add a new dataset for available values for DaysoftheWeek
On the Data tab, from the Datasets drop-down list, choose <New Dataset>.
Set the data source to the AdventureWorks data source.
In the Name field, type WeekDaysfromQuery.
Paste the following query string in the query pane.
SET DATEFIRST 1; SELECT DISTINCT DATEPART(weekday, S.OrderDate) as WeekDayNumber, DATENAME(weekday, S.OrderDate) as Weekday FROM Sales.SalesOrderHeader S Order by WeekDayNumber
DATEFIRST
sets which day of the week you want to use as the first day. For example,SET DATEFIRST 7
changes the order of the days of the week so that Sunday is the first day. For more information, see SET DATEFIRST (Transact-SQL).In this tutorial, Monday is the first day of the week.
Click OK.
Click the Run (!) button on the query designer toolbar. The result set shows ordinal numbers and days of the week.
To set the properties of the report parameter DayoftheWeek
On the Report menu, select Report Parameters. The Report Parameters dialog box opens.
In the Parameters pane, select DayoftheWeek. This parameter was created in Lesson 2.
In the Properties section, check Multi-value.
In the Prompt text box, type Filter on which days of the week:.
In the Available values section, from the Datasets drop-down list, select WeekDaysfromQuery.
From the Value field drop-down list, select Weekday.
From the Label field drop-down list, select Weekday.
For the Default values, in the first Value text box, type Saturday in the second Value text box, type Sunday.
Click OK.
Before you can preview the report, you need to change the filter expression defined for the table data region to use the IN operator because the DayoftheWeek parameter is now multivalued.
To change the filter to use a multivalue parameter
In Layout view, select the table. The table appears with a grey outline.
Right-click on the table outline and select Properties. The Table Properties dialog box opens.
Click the Filter tab.
In the Expression column, from the drop-down list, verify the value is
=Fields!Weekday.Value
.Change the Operator from the equal sign (=) to the In operator.
In the Value text box, from the drop-down list, verify the value is
=Parameters!DayoftheWeek.Value
.Click OK.
The filter for the table is now set to compare the value of the field Weekday with the value 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 the Preview tab. The report shows the report parameter DaysoftheWeek with default values Saturday and Sunday.
Note
A (Select All) value, with the exception as noted in a previous procedure, 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 text box to display parameter values
In Layout view, select the table. Press the down arrow key several times to move the table down and expand the report height.
From the toolbox, drag a text box above the table. Select one edge of the text box and expand its width to match the width of the table.
Paste the following expression into the text box:
="From " & Parameters!StartDate.Value & " to " & Parameters!EndDate.Value & vbCrLf & "For the following " & Parameters!DayoftheWeek.Count & " days of the week: " & Join(Parameters!DayoftheWeek.Value,", ") & vbCrLf & "First and last selected salespersons: " & Parameters!SalesPersonID.Label(0) & " and " & Parameters!SalesPersonID.Label(Parameters!SalesPersonID.Count-1)
There are several things for you to note about this expression:
- You can refer to the parameter label instead of the value. For example:
Parameters!SalesPersonID.Label
instead ofParameters!SalesPersonID.Value
. - To address an individual member of a parameter collection, use the zero-based index. For example:
Parameters!SalesPersonID.Label(0)
. - To address the entire collection, use no index. For example:
Parameters!SalesPersonID.Value
. - To find the number of values, use
Parameters!SalesPersonID.Count
. - You can also find out if a parameter is multivalue. For example:
Parameters!SalesPersonID.IsMultivalue
. - You can concatenate all the selected values in a multivalue parameter by using the Visual Basic Join function. For example,
Join(Parameters!DayoftheWeek.Value,", ")
.
- You can refer to the parameter label instead of the value. For example:
Click Preview. Verify that when you click View Report, the text box shows the values you have selected in the parameters.
Next Steps
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 accommodate using a multivalue parameter collection. You have learned to use multivalue parameters in an expression. In the next lesson, you will learn to create a Boolean parameter to control how much detail to see in a report. See Lesson 5: Adding a Parameter to Control Row Visibility.
Change History
Release | History |
---|---|
12 December 2006 |
|
See Also
Tasks
Lesson 1: Creating a Report Server Project for the Parameter Tutorial
Other Resources
Working with Parameters in Reporting Services