SSRS Parameter show 1 and 0 - reporting-services

Using SQL Server 2016 & SSRS. I may be missing something simple here, but I have a field (called Errors) in a report that has an Integer value of either 0 or 1.
I've added a parameter to my SSRS report called Errors and added 3 options:
1 = show error
0 = no error
1 or 0 = both
The Both option is not working - it doesn't return any records. I must be missing something. In Available Values I have a Label called 'Both'. On the value I enter the expression:
= 1 OR 0
What am I missing?

The parameter doesn't work the way you want it to.
The 1 or 0 value is probably being evaluated as a text value.
My suggestion is to use -1 for both if it can't be in the data and change your parameter to an integer.
If you are using the parameter in a query, you add an OR to check for your both selection (-1).
WHERE (ERROR_FIELD = #ERRORS OR #ERRORS = -1)
This will check to see if the field matches the parameter or if the parameter = -1.
If you are using the FILTER on the dataset or table,
=IIF(Fields!ERROR_FIELD.Value = Parameters!ERRORS.Value OR Parameters!ERRORS.Value = -1, 1 , 0)
And set the Type to Integer and the value to 1.

If anyone is interested, I got this working using an IN within the WHERE:
WHERE ERROR_FIELD IN (#Error)

Related

Parameter filter SSRS Expression Dataset

I have a dataset created from an expression that takes parameters from 3 other datasets.
I need to add a parameter to this that allows the user to input a value, and then the dataset will add that value to the where clause to filter the results displayed. If the value "Any" is input then the results will be unfiltered for this section of the Where clause (If that makes sense).
I wrote this and added it to the expression Where clause, but it is not working.
+ IIf(Parameters!RCode.Value = "ANY", "", " AND h.rcode = " + Parameters!RCode.Value + " ")
I can provide the rest of the where clause if it is needed, but if i remove this line, the whole thing works, if i add this line, it bombs out with
An error has occurred during report processing. (rsProcessingAborted)
Cannot set the command text for dataset 'DS'. (rsErrorSettingCommandText)
In the dataset query you can use parameter names by simple prefixing them with # eg. #RCode
To make it work, your WHERE clause should be look like (I assume your column name is rcode):
WHERE ....
AND (#RCode = 'ANY' OR rcode = #RCode )
For multivalue parameters
WHERE ...
AND ('ANY' IN (#RCode) OR rcode IN (#RCode) )

Obtain list of occurring field values in report footer - ssrs

I'm trying to obtain a list of the different field values within an SSRS Report, and then display the result set on the page header.
See link below for an example.
I know that usually this would be completed simply with groups but the user does not want the Tasks split out.
Thanks
Example Report:
To get the unique values into a single cell, you will need to utilize the code behind functionality in SSRS.
Click on the background of your report and go to report properties -> Code. Paste this function into the window:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As String = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
In the expression in your table where you want the unique values list, insert this expression:
=Join(Code.RemoveDuplicates(LookupSet(1,1, Fields!ID.Value, "DataSet1")), ",")
"Fields!ID.Value" is a reference to the field in your dataset that you want unique values from.
"DataSet1" is the name of the dataset that your field is located in.
What happens is that at runtime, the entire set of values from your query column are passed to the VB function which uses returns an array of unique values. The expression in the report Joins the unique array values back together with a comma deliminator.

SSRS Visibility

Having trouble with my SSRS Visibility expression:
=IIF((SUM(Fields!Rooms_Off_2) = 0 AND (IsNothing(Fields!actual_end.Value)))
OR (SUM(Fields!Rooms_Off_2) = 0 AND (Fields!actual_end.Value >= DATEADD("d",-7,TODAY()))), false, true)
Keeps giving me the error message: "The Hidden expression for the tablix ‘Tablix1’ uses an aggregate function with an expression that returned a data type not valid for the aggregate function. (rsProcessingError)"
Any ideas?
It seems Rooms_Off_2 field is set to Text data type which cannot be used in an aggregation function like SUM. You can convert that field to a Double data type in order to get the aggregation working.
Try:
Switch(
SUM(CDbl(Fields!Rooms_Off_2)) = 0 AND IsNothing(Fields!actual_end.Value),False,
SUM(CDbl(Fields!Rooms_Off_2)) = 0 AND Fields!actual_end.Value >= DATEADD("d",-7,TODAY()),False,
True,True
)
Let me know if this helps.

Hiding table or assigning temp data based on visibility expression ssrs 2008

I have a table in ssrs 2008. This table has a row visibility expression like:
=IIF(max(Fields!VExpected.Value) <> "", 1, 0) +
IIF(max(Fields!MExpected.Value) <> "", 1, 0) +
IIF(max(Fields!PExpected.Value) <> "", 1, 0) = 3, false, true)
Sometimes the datasource returns no data, or the returned data is not matching with this expression. In this case what I see is that a table with borders and column names but no data on it like:
id Vex Mex Pex
However, I want to show it as
id Vex Mex Pex
- - - -
Or if possible:
id Vex Mex Pex
No Data
Another question is, is there any way to hide the complete table if there is no returning data or any matching data with the expression?
Thanks
You can use CountRows function to determine how many rows your dataset is returning. If it is zero hide the table otherwise show it.
=iif(CountRows("DataSetName")=0,true,false)
Replace DataSetName by the actual name of your dataset.
For not matching expression data you can use the this expression.
=IIF(
max(Fields!VExpected.Value) <> "" AND
max(Fields!MExpected.Value) <> "" AND
max(Fields!PExpected.Value) <> "",False,True
)
The whole expression for matching expression and no rows cases could be something like this:
=Switch(
CountRows("DataSetName")=0,true,
max(Fields!VExpected.Value) = "",true,
max(Fields!MExpected.Value) = "",true,
max(Fields!PExpected.Value) = "",True,
true,False
)
Supposing VM, ME and PE expected values are numeric type I'd use ISNOTHING() function to determine when null values are being returned.
=Switch(
CountRows("DataSetName")=0,true,
ISNOTHING(max(Fields!VExpected.Value)),true,
ISNOTHING(max(Fields!MExpected.Value)),true,
ISNOTHING(max(Fields!PExpected.Value)),True,
true,False
)
Additional you can set a message when no rows are being returned from your dataset. Select the tablix and press F4 to see properties window. Go to NoRowsMessage property and use an expression to say your users there is no data.
="There is no data."
In this cases the tablix will not appear in your report but the message you set will be rendered in the location where the tablix should be.
Let me know if this helps.

Replace #Error or NAN with -(hyphen) in SSRS

When i get a value into the text box (say "NAN" or "#Err") i want to replace it with -(hyphen).
How to achieve this in SSRS reporting ?
Thanks in advance.
You'll need to write an expression to handle it. Ideally, you would have some custom code function in your report (ie. Code.SafeDivision())
=iif(Fields!denominator.Value = 0, "-", Numerator / Denominator)
To elaborate on cmotley's answer, add the following as custom code to your report (to do this go to report properties, then code and then paste this in):
Function SafeDivide(value1 As Decimal, value2 As Decimal) As Decimal
If (value1 <> 0.0 And value2 <> 0.0) Then
Return value1 / value2
Else
Return 0
End If
End Function
Then you can use this in your textboxes to divide without receiving not a number and/or error, for example, adding the following as an expression (changing textbox names as required):
=Code.SafeDivide(ReportItems!Textbox186.Value, ReportItems!Textbox184.Value)
Divides two textboxes using our function.
To show a dash you can simply change the formatting of your textbox to 'number' and tick the box indicating that you'd like to replace '0' with '-'.
Alternatively if for some reason 'NaN' is coming through explicitly from a datasource (rare but not impossible when referencing a loaded table in SharePoint) you could use the following:
Function evalutator(value as String) as String
Select Case value
Case "NaN"
Return "-"
Case "NAN"
Return "-"
End Select
Return value
End Function
What about:
=IIF(Fields!yourcolumnname.Value = 0, "-", Fields!yourcolumnname.Value*1)
Or if you wanted zero's where you get NAN/#ERROR then you could use:
=IIF(Fields!yourcolumnname.Value = 0, Fields!yourcolumnname.Value*1, Fields!yourcolumnname.Value)