SSRS Switch statement expression for multi value parameters - reporting-services

I have the following switch statement within an SSRS report, but it errors out when I run the report.
Basically Parameter 1 is a multi value parameter, and when the parameter has two values selected where they are two distinct values, I want a certain text to appear.
=SWITCH(Parameters!Parameter1.Count = 2 AND Parameters!Parameter1.Value(0) = "TEXT1-NY" AND Parameters!Parameter1.Value(1) = "TEXT2-LA" , "Combined (NY & LA)"
, True, JOIN(Parameters!Parameter1.Label,"& ")
)
Additionally, regardless of the numbers that are selected (i.e if there were 6 parameters that were selected), is it possible that these two parameters would be replaced with that particular text followed by , and then names of other parameter values?

First of all, good job working out the expression that you have. You're on the right track, but expressions don't have a programmatic way to loop through the values of the parameter.
One option to do specifically what you asked would be to add a custom function to the Code section of your report that could loop through the parameter values.
Another option would be to simply UNION this "Combined (NY & LA)" value to your dataset so that it is available as one of the options.

Related

Using SWITCH on a parameter that allows multiple values (report builder 3.0)

I am trying to build a little dynamic expression that changes a word in my report based on the parameter chosen. I followed along with this question and answer
Report Builder 3.0 SWITCH expression DEFAULT/ELSE
with the expression
=Switch
(
Parameters!LineCalled.Value = "01156842190","Order Line",
Parameters!LineCalled.Value = "01156842191","Overflow Line",
true, "Both Lines"
)
but I got #Error when it ran. I think the reason is that by default my parameter picks both of the possible options (order and overflow). Is there a way to write a SWITCH (or I guess some nested iifs) such that it will detect a primary option a secondary option and a third case where both options are picked and change the words shown accordingly?
EDIT :
As per request I have added a view of the available and default values for my parameter.
As mentioned in your edit, you have multi select parameter.
Assuming form your parameter you have 2 values
01156842190" and "01156842191
Parameters!LineCalled.Count will give your count if you have selected 2 values or 1 or all.
In your case 2 is All which is also your default.
Below expression will get you desired result
=IIF(Parameters!LineCalled.Count<>2,IIF(Parameters!LineCalled.Value(0) = "01156842190","Order Line","Overflow Line"),"Both Lines")

SSRS: Toggle Report via a parameter

I'm creating a single SSRS report that is composed of data drawn from different Datasets. What I'm wanting to do is have a drop down menu where the user selects the dataset they wish and have the appropriate table turn on and show them the dataset information.
Right now I'm testing with two tables and in there Visibility property I have the following expression:
=IIf(Parameters!AppSelection.Value = "STRAW", false, true)
The other table has the exact same line in the same place but with a different value between the quotes.
With my parameter, I created a new one and called it AppSelection and gave it 2 Available Values that matched the words between the quotes in my above expression. The data type for my parameter is Text and the Value of the each Available Value is left at null.
When I preview my report and select the different values in the parameter, nothing happens. What is it I'm doing wrong?
Change the null in the available values to your text, ie STRAW.
You may find that the tables show the other way round from expected, switch the true and false.

Using optional multi-value textbox as dataset filter

I have a report which returns list of product names and other product specs. This report currently has different search options. My users now also want to be able to search by product number by putting in multiple product numbers.
How can I add a filter by product number which is an optional multi-value textbox?
I have tried to add a multi-value textbox. The report doesn't seem to work when no values are entered. If I put one or more product number in the text box, it seems to work fine. Is there a way I can tell the report doesn't filter on the Null value parameters? Or any other idea to work with optional multi-value parameters?
Here is the setting for my multi-value textbox
Name = ProductNumber
Prompt = Product Number
Data Type = Text
Allow Blank Value (checked)
Allow Null value (not checked)
Allow Multiple Values (checked)
Here is the data set filter
Expression = [ProductNumber]
Operator = In
Value = [#ProductNumber]
Thanks
TL
I think you should trick the dataset filter by:
Expression should check to see if the parameter is blank and if so give expression a 1 else the field.
Value should do the same check and if parameter is blank set value to 1 else set it to the parameter.
But keep your operator.
Alternatively you could do this similarly in the SQL and with more flexibility and performance.
So as you've seen in your own testing, at least one value must be selected with multi-value parameters. You can't set Allow null value to true at design time and if you run a report without selecting any values it will throw an error message.
So you can't really have a report where users can run it with no values selected.
Taking a step back, what you're trying to achieve when ignoring the parameter is to include all Product Numbers by default. So why don't you set the parameter to have a default value of all Product Numbers selected? That way, users can just ignore and leave them all ticked if they don't want to filter by Product Numbers. Seems like a good workaround to me.
To do this, set the default value for the parameter using the same dataset that populates it:
All Product Numbers are now selected and users only need to take action if they want a subset of these returned.

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)

SSRS: Can I know if user selected "ALL" in multivalued param?

Customer wants me to repeat the parameter values in the page header of the report. But if they just choose "Select All" on a multi-valued parameter, they want the text "Any" listed.
For example, one parameter has a fixed set of 9 values. I hard-coded the expression for a text box to:
="Room Size: " &
iif(Parameters!pRoomCap.Count=9,
"Any",
Join(Parameters!pRoomCap.Value, ", "))
How can I do this if the parameter source is a query of unknown size?
Try this out. You need to compare the total number of parameters in the dataset to the count of selected parameters. The following assumes that your multivalue parameter is using a dataset called "dsRoomSizes"
="Room Size: "
& iif(Parameters!pRoomCap.Count = count(Fields!pRoomCap.Value,"dsRoomSizes"),
"Any",
Join(Parameters!pRoomCap.Value, ", "))
This expression will work in the page header/footer.
UPDATE
In the interests of finding a solution to your problem, the following should work for you. It feels hackish and I encourage you to keep research alternative methods but this will work:
Create a second multivalue parameter and name it something like "pRoomCap_hidden".
The source of the parameter is the exact same query
In the parameter properties, setting the default values to the same query
Important: Set the parameter visibility to hidden
This will create a second multivalue parameter in your report that is exactly the same as your initial multivalue parameter only this parameter list will have all values selected by default.
Enter the following expression in a textbox in your header:
=IIF(Parameters!pRoomCap.Count = Parameters!pRoomCap_hidden.Count,"All",Join(Parameters!ReportParameter1.Value,", "))
The above will compare the selected values in each parameter list. If the lists contain the same selected values then that indicates that "All" have been selected in the first list.
Like I said, it is hackish but it definitely works. Until you are upgraded to 2008, this might not be a bad workaround for you.
Can you compare the count of the parameter to the count of the dataset you pull the parameter values from?
I unioned my dataset for the parameters with one which I created manually with a "select" statement - I was then able to force the value to be something like -1 or null.
Then simply check if the parameter contains -1 or null and replace the value in the header with the replacement text.
BTW- I am now using SSRS 2008 R2 and this solution worked for me. My report uses three datasets; but only one in the tabilx that I needed to hide a row in. After long hours of searching and many, many, many unhelpful for wrong answers; the solution of creating a identical parameter only hidden (I marked it as internal) and then comparing to the exposed one is brilliant and easy.
Thank you very much!