Using a list parameter in SSRS - sql-server-2008

I need to be able to set an SSRS parameter to contain multiple values.
In TSQL, I can have a where clause that states:
where Attribute in ('Value1', 'Value', 'Value3')
What I need is in SSRS to have:
where Attribute in (#Attribute)
Where I am getting hung up is how to format the parameter value expression so that SQL sees it as: 'Value1', 'Value', 'Value3'
I have had some luck making the where clause look at only the first value, but I need it to look at all 3. How would I format the expression to do that?
I would just allow it to accept multiple values, and check each value individually, but I need the drop down list to have groups. So, if the user selects GroupA, the where clause uses: IN ('Value1', Value2') and if the user selects GroupB, the where clause uses a different list for the IN.
Hopefully it's just a matter of formatting the expression correctly.

Well, if you didn't have the requirements about groups, this wouldn't be an issue since all you need is to make your parameter a multi-valued one, and on your dataset query do WHERE Attribute in (#Attribute). But taking that requirement into account, the only way I can think of, is to have two multi-valued parameters: #Group and #Attribute. You'll need to make #Attribute not visible and create a dataset to populate it. That dataset would be something like this:
SELECT Attribute
FROM Attributes
WHERE Group IN (#Group)
And create another dataset for your report data:
SELECT <all your data>
FROM YourTable
WHERE Attribute IN (#Attribute)

Related

Filters Multiple values directly on report

I wanted to instead of defining the parameter in the query but use the filter to work as parameters.
I have configured SSRS filter expression like
The parameter is called "Locations" and i am allowing multiple values
From the datasets: The field is called Location
Filter from the dataset
Expression:[LOCATION]
Operator: IN (i tried Like)
Value =Parameters!Location.Value(0)
When i run, it works when i pick one item from my drop down option. But when i pick more than 1 location i get values of the first value picked from the drop down only. It doesn't recognize the multiple choice.
You have enabled the multiple parameter, so you could use expression like below to see whether it works or not(it will recognize all parameters)
Expression:[LOCATION]
Operator: IN
Value =Parameters!Location.Value
Zoe

Filter Multivalue Parameter on Dataset

So I have a multiple value parameter than contains 3 options. >250K, <250K, >2M.
I also have a table that consists of multiple columns.
. Because the parameter is a multivalue, i am having difficulties filtering the dataset.
I need to filter the dataset by checking, (if > 250K is selected, filter the dataset accordingly), (if < 250K is selected, filter the dataset accordingly) and (if > 2M is selected, filter the dataset accordingly).
I was told to use a join and split on the parameter within the (>250K condition, then do a contains to see if it contains any of the parameter values) but I am not as advanced in my knowledge of coding to be able to do that.
Any Suggestion? Thanks in Advance
I previously tried the method below but then i came to realise that it wont work because the parameter is a multi value.
I know its been a while since you raised this, you were on the right track but all you should need to do is add a filter to the Tablix on the field you will be filtering, use the 'in' operator and in the Value type [#Yourparametername] the square brackets and case sensitivity are important. Also ensure the expression type is correct, in your case it looks like you are using Integer. The image should help.
If you want to use multi-parameters, In the dataset, you can read parameter value using JOIN.
Example:
If you want to read multiple values for #MyParamter in a dataset given in the following example:
Dataset Parameters
you need to use =JOIN(Parameters!myMultiParamter.Value,",") as an expression to read all selected values in CSV form.
Expression
Now the #ParameterValues param has all selected values as comma separated values and you can use them in your dataset code as per design requirements.
Note: It's not necessary to use a comma but u can use anything you want to separate values.
Your sql query where should look like
Where
(
(0 IN (#Parameter) AND ValueColumn<250000)
OR
(1 IN (#Parameter) AND ValueColumn>=250000)
OR
(2 IN (#Parameter) AND ValueColumn>=2000000)
)
One parameter
Two parameters
All parameters
Once you return the value you can also use charindex or patindex* and look for where the value in your where clause is a pattern where the index number is > 0 . For instance if the returned string from SSRS is '01,02,03' and then your where clause has something like this right(field, 2) which would result in value '03'. you change your where clause to be where patindex('%' + right(field, 2) + '%', #returnedstring) > 0 which will give you results. The keeps you from having to parse apart the #returnedstring parameter in your sql code.

SSRS expression issue using iif function

I have a data set that is returning two properties, a name and a total units. I am trying to set an iif expression on a data bar where iif(field!Name.Value = "Name", field!Total.Value, 0)
this is not working I get an error of rsFieldReferanceAmbiguous, the fields refers without specifying a dataset aggregate. And the only option that it gives me as an aggregation is First, but I do not want to get the first name, I want the bar to display the total units base on the name field that is in the iif expression.
rsFieldReferenceAmbiguous refers to trying to match something that is not in local scope. Therefore you have to aggregate it. You are probably wanting something like this:
=Sum(IIF(Fields!Name.Value = "Name", Fields!Total.Value, 0))
The function you are trying to use would be better suited to a calculated field in your dataset. Then you can just refer that that field in your report. This allows you to filter the data line by line instead of by groups.
Right-click on the dataset and go to Dataset Properties.
Go to Fields.
Click Add then Calculated Fields.
Enter the name of the field and then the expression here.
Make sure your tablix has the dataset specified under General -> DataSetName on the properties pane. If you have more than one data set on the report you will need to specify which data set your reffering to like so:
(Fields!Name.Value, "NameDataSet")
If your useing tables you may need to ckeck if you have grouping and if so how your grouping your data.

SSRS Multi Value Parameter. Check whether "Select All" is selected

I have a multi value parameter in my SSRS Report. I want to find out whether (Select All) is checked in that parameter.
In other words, whether all the values in the parameter are checked or only some values are checked.
Is it possible?
I am able to find out number of selected values through Parameters!Parameter.Count. Is there a way to find out total of items in that parameter?
In case anyone is still having issues doing this, I just coded this easy fix.
=IIF(COUNTROWS("dataset").Equals(Parameters!parameter.Count),"it is equal","this is not equal")
For the specific use-case of showing the selected filter on your report in a textbox, here's the expression that will show "All" if "(Select All)" is selected, otherwise it will show all the selected values as a comma-separated list:
=IIF(
Parameters!YourMultivalueParam.Count = countrows("YourDataset"),
"All",
Join(Parameters!YourMultivalueParam.Label,", ")
)
(split onto multiple lines for readability)
countrows reference: https://technet.microsoft.com/en-us/library/dd255215.aspx
Credit to other answers, just want to extend them for this common scenario.
Your approach sounds good: I would make the options for the parameter come from a dataset.
Then you can use =COUNTROWS("DataSetName") to return the total number of options for your parameter and compare this with Parameters!*Parameter*.Count as you suggest.
I also faced this problem and I solved it this way.
I have one multivalued parameter named "Carrier". Then I have added one parameter "CarrierHidden" which is same as "Carrier" only thing is I made its Visibility as Hidden.
="Carrier=" & Switch(Parameters!CarrierHidden.Count = Parameters!Carrier.Count, "All",
Parameters!Carrier.Count > 1 And Parameters!CarrierHidden.Count > Parameters!Carrier.Count, "Multi",
Parameters!Carrier.Count = 1, Parameters!Carrier.Label(0))
The easy way will be to count the number of the selected parameters and compare them to the dataset
=IIF(Parameters!company_number.Count = CountRows("Dataset1"), True, False)
The problem is if you're trying to pull something for another data set then cross referencing the row count in another dataset won't work. You will have to go with what the previous post states. Create an internal parameter of the exact type and assign the default value to the entire dataset. That way you have the max count of the rows since the hidden parameter.count = rowscount. That way you can use it within another dataset also provided that dataset is AFTER the first one is populated.
According to Microsoft's SSRS help search:
=Parameters!<ParameterName>.Count
Returns the integer value 1. For a single-value parameter, the count is always 1.
I verified this does indeed work, check the integer returned for the built-in parameter count field.
Allow multiple values on a parameter selection. Checking the value of the above field will let you know how many values the user actually chose.
In my situation, I allow multiple values on company number. This gives users the ability to choose one company to report on or several at once. Per client request, if they choose more than one, display data horizontally. If only one company is chosen in the parameter list, show the data vertically and hide the other tablix.
So my visibility show or hide expression looks like this in the one tablix:
=IIF(Parameters!company_number.Count > 1, True, False)
and like this in the other:
=IIF(Parameters!company_number.Count = 1,True,False)

"Select All" with SSRS 2008 Parameters

I want a parameter to load available values from a query (or whatever) and "allow multiple values." When I do so the list begins with "Select All."
That's great, but there appears to be no way to default the parameter to "Select All" which is not acceptable in my case. This particular report will have 8 optional parameters and if htey have to select "Select All" multiple times, this is hardly optional.
Therefore, I create my own "..All" option and the code to accept it. I can default to that, but then the user sees:
(Select All)
..All
This looks unprofessional. I've scoured the net and there doesn't appear to be an answer to this problem.
Is there any way to suppress (Select All) or achieve what I need? Any ideas?
Actually, the answer turned out to be that you have to set your Available Values and Default Values to the same Dataset and field.
If you do that, SSRS automatically selects every option in the list. It's not pretty, but it works.
Coincidentally you have to handle nulls in your dataset query too and replace them with some value such as "None." SSRS parameters will not allow the user to select "Allow multiple values" and "allow null values" at the same time. If your field contains nulls, SSRS will not throw an error but it will not default either.
I'm going to follow up with a blog post on this problem in the near future.
You can also use the Split() function to return multiple values.
For example, if the dataset is a bunch of varchars like
SELECT 'A' UNION SELECT 'B'
The following default value to select all for the multiple value parameter would be:
=Split("A,B",",")