Use SSRS Expression to Hide Tablix Based on Parameter Selection - expression

I have a report that displays sales by county or by agent - but the user cannot select both. The #AgentOrCounty parameter is hard-coded: Agent = 0 and County = 1. And the #AgentID parameter only accepts one value but the #CountyID accepts multiple values. And my report has two tablixes: one for the dataset and one to display an error message if the user selects both an #AgentID and #CountyID
What I hope someone can help me with is how I can write two expressions to hide the tablixes based on the user selection.
One additional issue I am experiencing is that the #CountyID parameter is a multi-value parameter that I have to pass a NULL value to to allow the report to run if the user wishes to display by Agent.
Right now, on my Error Message tablix, I have the following expression:
=IIF(LEN(Parameters!AgentOrCounty.Value)=0,TRUE,FALSE) OR IIF(LEN(Parameters!AgentID.Value)=0,TRUE,FALSE)
But this doesn't hide the Error Message tablix when the user runs the report correctly for Agents.
When I think in logical terms, I would like the Error Message table to be hidden if the #AgentOrCountyID = 0 and #CountyID is NULL or the #AgentOrCountyID = 1 and #AgentID is NULL.
And I would like the report data tablix to be hidden if #CountyID and #AgentID are both not NULL.
Any suggestions?

To hide the error message tablix, I used the following expression:
=IIF((Parameters!AgentOrCounty.Value=0 And Parameters!CountyID.Value(0)="NULL")
Or (Parameters!AgentOrCounty.Value=1 And Parameters!AgentID.Value Is Nothing),True,False)
And to hide my data set tablix when the user selected both an agent and a county, I used the following expression:
=IIF(Len(Parameters!AgentID.Value)>0 And Len(Parameters!CountyID.Value(0))>0,True,False)

Related

Limit the number of Multivalue parameter selections SSRS

I have a report with a parameter with about 12 multivalue parameters. Is there a way to select 5 parameters and when selecting the 6th parameter displaying 5 is the limit ??
Any ideas are appreciated.
As a work around , you could try using a combination of a visibility expression to count the parameters chosen and a separate text box with a warning message, such as :
=IIF(Count(Parameters!XYZ.Value(0),"DataSet1") > 5 , "too many parameters selected", "ok")
and using a variation of the expression to hide / show your original report.
There is no way to give immediate feedback when the limit is exceeded. One option would be to show a message once they click the View Report button. It's a bit of a workaround, but you would have to have the dataset return no rows. Then for the message, you could either have a texbox with conditional visibility somewhere on the report OR you could use the NoRowsMessage property on a table to show the appropriate message.
If you have a more complex situation such as multiple parameters, you can just add in more conditional logic to the dataset and message to check if all the conditions are met and which message should appear.

SSRS show parameter values in header

I am trying to add an expression in header section, which would display parameter value chosen by users (if everything selected, display "ALL" instead). I am having trouble with "Property" parameter.
Report structure:
Report is a matrix report that shows data by year and grouped by refBuildingID. Parameter "Property" is based on RefBuildingID. I want to show these parameter values in header when users run this report.
Expression:
=IIF(Countrows("BuildingID")=(Parameters!refBuildingID.Count),"All",Join(Parameters!refBuildingID.Value,", "))
Error:
The Value expression for the text box ‘Textbox31’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset.
Is there a way to get around this error?
Try this method:
=IIF(Count("BuildingID")=Count(Parameters!refBuildingID.Value),"All",Join(Parameters!refBuildingID.Value,", "))
i think CountRows will work
=IIF(COUNTROWS("BuildingID").Equals(Parameters!refBuildingID.Count),"ALL",Join(Parameters!refBuildingID.Value,", "))

IIF Statement in TablixFilter issue

I'm trying to filter a matrix in my report. I have names of 4 drivers and I want the Matrix5 to show the name of a default driver in case SELECT ALL is checked in filter. Otherwise I want the matrix to show whoever is checked.
I set an expression at matrix filter as;
=IIF(Parameters!Sofor.Count=4,"abcdef",Parameters!Sofor.Value)
-abcdef is the name of the default driver for the tablix
-Sofor is the driver name parameter and has 4 total possible name options, 5 if we consider SELECT ALL too.
It works well if I check SELECT ALL but stops working if I select only one option.
Error I'm getting is as follow;
"The processing of FilterExpression for the tablix "Tablix5" cannot be performed. Cannot compare data of types System.String and System.Object[]. Please check the data type returned by the FilterExpression"
Though the error sounds pretty self explanatory I still can't understand what I'm doing wrong. Any help please?
Parameters!Sofor.Value is an array of values (the object) because its a multi-select parameter. (what happens when the user chooses 2 drivers?)
Try
=IIF(Parameters!Sofor.Count=4,"abcdef",Parameters!Sofor.Value(0))

Browse field data shows value, but displays another value

I have a formula written for a field in Crystal Reports. When i refresh the report, i get a different value from the formula. The required value is always the last value in Browse Field Data dialog for that formula.
Isnt the formula supposed to have only one value as output? why are multiple values shown in browse field data dialog.? Is there a way to retrieve last value of Browse File Data dialog?
My formula looks like below:
WHILEREADINGRECORDS;
NumberVar CODTOTAL;
if {XXX.YYY} = 1 then
( CODTOTAL := CODTOTAL + {XXX.ZZZ};
);
CODTOTAL;
Browse field data shows all the values "CODTOTAL" acquires as a result of that formula and displays a random value amongst the assigned value.
Please help me out. I am amateur in crystal reports.
Any help would be highly appreciated.
~Regards.
First observation should be where have you placed the formula (Details, Footer.. etc).
why are multiple values shown in browse field data dialog.?
Browse field shows the data that is present in the table but in your case you are applying "If" condition of the filed. It can be possible that there is only one record that satisfies your condition.
I would suggest to run the report without the codition, Check the results and apply the condition and check results again.

ReportViewer - how to filter on Multi Value Parameter

I have a report that uses a Multi Value parameter. I have added this to the report and can specify the parameter values in code.
Now I want to filter the data on the report by the multiple value parameter. Eg, I pass in a list of account no's and I want to filter the data on the report so only records with the passed in account no's are shown.
In the tablix properties there is a filters option which looks like the place I need to set up the filters.
I have added a new one, selected the Account Number column on the report. The operator that seems relevant to me is the 'in' operator. So show records that a 'in' this list. However, If i select the 'in' filter the expression text box is disabled. Is this what im meant to use?
Found it:
You should filter on The name of the parameter rather than an expression.
eg:
[#CostCentres]
rather than:
=Parameters!CostCentres.Value

Resources