SSRS how to have two different condition in Action Property - reporting-services

I am working in a SSRS that needs to link a report based on the value in a textbox.
I have tried:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing)
Which works fine, but when I try to add another condition like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing) OR
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing)
Then it does not link any report. How do I do this right?

What you are trying does not work correctly as the IIF statements are not nested and what it is doing is:
IIF(this, true part, false part) OR IIF(this, true part, false part)
So when Fields!Factors.Value = "Touched Leads" the expression evalutes to SCPL OR Nothing which isn't valid.
Alternatively you could use SWITCH which has a nicer syntax, the final True statement is your catch all
=SWITCH(
Fields!Factors.Value = "Touched Leads", "SCPL",
Fields!Factors.Value = "TOTAL", "Disposition",
True, Nothing
)

I think that the expression you need will look like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing))
This checks the first condition ("Touched Leads"), if that is true, link the SCPL report, otherwise check the "TOTAL" condition. If that one is false, return Nothing.

Related

SSDT report expression IIF/SWITCH

I am trying to create an expression that checks if the condition is not correct just go to the else statement, for an easy example I did the following
=SWITCH(TRUE, "AA", FALSE, "A"/0)
=IIF(TRUE, "AA", "A"/0)
as you may guess the conditions here were set always to print (AA) but the actual result is always (#Error), how to avoid this, I just wanted it to execute if true and ignore the error in the false section.
obviously, my statement is a bit more complicated but in short, that's the situation I am in with the following code
IIF(SPLIT(Parameters!JSON.Value, chr(34) & "Text" & chr(34)).Length > 1, SPLIT(SPLIT(Parameters!JSON.Value,chr(34) & "Text" & chr(34)).GetValue(1),chr(34)).GetValue(1), "")
when there is no value it should print an empty string but it looks like SSRS looks at the true condition and prints #Error regardless of the result of the IIF true or false.
how i can avoid this, or how to check if (#Error) and print something else?

#ERROR Help, SSRS Report Builder, IIF w/ LOOKUPSET

I'm trying to compare 2 rows of data in the form of %'s. I generate and it "#Error".
=IIF(Fields!Grade.Value = "ONGRADE" > LookupSet(Fields!Grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", "Previous3Week"), "UP" ,"DOWN")
There are two DataSets.
You are using IIF incorrectly. IIF just looks at a comparison and returns the first value if TRUE and the second value if false.
=IIF(1 = 2, True, False)
Which reads as
If 1 = 2 then return TRUE else return False
You are also using LookUpSet incorrectly. The first LookUpSet argument is your current dataset field that you want to compare, the second argument is the field from the first that you want to compare to - since your using the same dataset, they might be the same. The third LookUpSet argument is the field that you want to return (you know the ONGRADE field, what value do you want back?).
Your expression reads, if Grade = ONGRADE > LookupSet(blah blah) ...
What is the value field that you want to compare? Assuming it's Fields!GRADE_VALUE.Value, your IIF might be like
=IIF(Fields!Grade.Value = "ONGRADE",
IIF(Fields!GRADE_VALUE.Value >
LookupSet(Fields!Grade.Value, Fields!grade.Value, Fields!GRADE_VALUE.Value", "Previous3Week"),
"UP" ,
"DOWN"),
"Not ONGRADE")
If you want all GRADE types (not just ONGRADE) compared, it would be simpler:
=IIF(GRADE_VALUE > LookupSet(Fields!Grade.Value,
Fields!grade.Value,
Fields!GRADE_VALUE.Value,
"Previous3Week")
, "UP"
,"DOWN")

How can I hide specific duplicate rows in SSRS 2005?

Here's my problem: I have some some duplicate rows (rows with the same ID). What I want is to hide rows based on a specific's column value. The mentioned column is obviously not the ID column (it's the Description column).
I tried this on the Row Visibility (Expression):
=IIF (Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value)
AND
ReportItems!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
So, I want to exclude the rows in which Description is not equal to 'Incident Status Change to Work In Progress from Open'.
The message that I get is:
The Hidden expression for the table 'table 1' contains an error:
Object variable or With block variable not set.
Any ideas on this?
Thanks in advance
I think you are probably getting that error because there are one or more rows in your query result that have a NULL value in the Description field.
You could test this theory by simplifying your expression to this:
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value), true, false)
just to see if you can run the report without error.
If that works, then you need to add a test for a NULL value as part of the larger condition test, to get back to the logic you intended.
Try this:
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value) AND IsNothing(Fields!Description.Value) = false AND Fields!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
This should avoid the error by preventing the evaluation of the last part of the condition, when the Description has a NULL value.
I think you're on the right track just using ReportItems instead of Fields!
=IIF(Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value) AND Fields!Description.Value <> "Incident Status Change to Work In Progress from Open", true, false)
SSRS can be wonky sometimes. Try parenthesizing:
=IIF(((Fields!Incident_ID.Value = Previous(Fields!Incident_ID.Value)) AND (IsNothing(Fields!Description.Value) = false) AND (Fields!Description.Value <> "Incident Status Change to Work In Progress from Open")), true, false)

Combobox null in if statement

I am trying to code an if statement where if a certain combobox is null, then it runs a certain part of code if it has data in it then it runs another. I wrote up this:
Private Sub ProjectAddSetDateAutoBtn_Click()
If ProjectAddAllDueDateAutoCmBx = Null Then
'Code1
Msgbox("ComboBox Is Null")
Else
'Code2
Msgbox("ComboBox Has Data")
End If
End Sub
I leave the combobox with no data, and then it doesn't run the code in the first part of the if or the code in the 2nd part of it either! If I enter data into the box, it runs the 2nd part of the if statement perfectly. There are no errors, I am quite stumped on this. Do ComboBoxes have their own "Null"? Is there a problem with this if statement?
Nothing is ever equal to Null, not even another Null.
Use IsNull() to check whether the combo box is Null.
'If ProjectAddAllDueDateAutoCmBx = Null Then
If IsNull(ProjectAddAllDueDateAutoCmBx) = True Then
I would suggest
If IsNull(ProjectAddAllDueDateAutoCmBx.Value) Then
It correctly checks for Null (IsNull instead of = Null), and it explicitly checks the value of the combo box.
(In most cases -- depending on the context -- just using the name of the control yields the value, but it doesn't hurt to be explicit.)
You cannot use a = Null comparison to get the results you want because Null propagates. To see this in action, try:
? Null = Null
in the Immediate Window and you'll see that Null is returned. Use the IsNull function, which will return true or false as you would expect.
Private Sub ProjectAddSetDateAutoBtn_Click()
If IsNull(ProjectAddAllDueDateAutoCmBx) Then
'Code1
Msgbox("ComboBox Is Null")
Else
'Code2
Msgbox("ComboBox Has Data")
End If
End Sub
While the accepted answer is totally correct, I use a different approach:
If HasValue(ProjectAddAllDueDateAutoCmBx) Then
where the HasValue function is:
Public Function HasValue(v As Variant) As Boolean
If Trim(v & "") <> "" Then
HasValue = True
Else
HasValue = False
End If
End Function
This has the advantage of treating NULL and "" (or any pure whitespace) values the same, which is many times what you want with MSAccess controls. For example entering a value in a null-valued textbox and removing it again with backspace will result in a ""-value, not NULL. From a user-perspective this is mostly meant to be the same.
[The (v & "")-part is just a trick to force conversion to a string.]
the equivalent of null in VB is Nothing so your check wants to be:
If ProjectAddAllDueDateAutoCmBx Is Nothing Then
....
it hope helps.

SSRS Enable/Disable filter based on parameter Value

I have a report parameter of boolean type.
If the value is true, a filter needs to be applied to a dataset, and if false it should not filter.
Sounds simple, but can't figure out..
Any suggestions?
In your dataset query you can add logic like:
WHERE
(
#MyBooleanParam = 1 AND <filter code>
)
OR
(
#MyBooleanParam = 0
)
So if the parameter is True, then the filter logic is applied in the query, if the parameter is false then no filter is applied.
I'd use Nathan's but an alternative would be to set up your filter as normal but wrap the expression in an IIf function that short circuits the filter:
=iif(parameter!myboolean.value = 1, parameter!myfilter.value, fields!field_im_filtering.value)