SSDT report expression IIF/SWITCH - reporting-services

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?

Related

IIF statement with null value and multiple condition

I'm getting a problem with one of my expression in my report. It always gives me #Error and I think I know why but don't know how to set my expression.
Here's my expression :
=IIF(Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
The Fields CMMTTEXT can be null sometimes and I'm getting an error on all of my rows except the one that has data in the CMMTTEXT field.
So I need a isnothing but I've tried couple ways of doing it but doens't seem to work
=IIF(IsNothing(Fields!CMMTTEXT.Value.Contains("*Return*")) AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
also this that I've seen on this forum :
=IIF(IsNothing(Fields!CMMTTEXT.Value) OR Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
I have no idea at this point.
Thanks for the help!
The Contains function doesn't work with NULL values. Once it throws an error, the IsNothing function subsequently can't evaluate the results. Separating these out using the OR operator also doesn't work because it tries to evaluate both conditions even when the first one was true.
One way to work around this is to first check for NULL values and replace them with an empty string. Then use the Contains function on the results of this expression:
=IF(IsNothing(Fields!CMMTTEXT.Value), "", Fields!CMMTTEXT.Value).Contains("*Return*")

Trying to display expression if state exists, getting #Error

In my SSRS report, I'm trying to display the City and State if the city exists and I'm doing so with this expression
=IIF(Fields!Ship_To_City.Value, Fields!Ship_To_City.Value & "," & Fields!Ship_To_State.Value, "")
the conditional part of it works, but whenever it's supposed to output the City, State, I get #Error. Any reason why?
An IIF conditional goes like this:
=IIF(boolean_condition, value_if_true, value_if_false)
Now, your IIF looks like this:
=IIF(Fields!Ship_To_City.Value, Fields!Ship_To_City.Value & "," & Fields!Ship_To_State.Value, "")
That is, Fields!Ship_To_City.Value is operating as a boolean value in the boolean_condition part but then as a string in the value_if_true part. One of these isn't going to work.
I assume you want to test that the field isn't null before outputing it, so you want to have an actual boolean condition in your IIF like this:
=IIF(Fields!Ship_To_City.Value <> Nothing, Fields!Ship_To_City.Value & "," & Fields!Ship_To_State.Value, "")

SSRS how to have two different condition in Action Property

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.

SSRS - Formula inside IIF statement

Im trying to create an IIF statement on SSRS where one of the results have an expression inside. I could only find examples with plain text but wanted to no how i can mix text and this expression as a result:
This is an example of what I'm trying to do:
=IIf(Sum(Fields!BytesTotal.Value, "dataset_traffic") = 0,
"No data available",
"Your data is 'Sum(Fields!BytesTotal.Value, "dataset_traffic")/1073741824'"
)
How can i declare an expression inside an IIF result?
Try this:
=IIf(
Sum(Fields!BytesTotal.Value, "dataset_traffic") = 0,
"No data available",
"Your data is " & Sum(Fields!BytesTotal.Value, "dataset_traffic")/1073741824
)
Let me know if this helps.

conditional filter SSRS

My situation is
I have a parameter, this is a list, allowing multi values. That mean the first record in the list is 'Select All'
When user select All I need to include in my report all records that match with the list plus those that are blank. (My dataset is returning these)
When user select only 1 or a few I want to include only these records. No those that are blank
My problem:
I have a filter in my dataset that evaluate a parameter in a list, but I need to add a conditional filter to include a blank records when the selection will be "Select All"
I tried to use expression but this doesn't work
Filter expression
Fields!NAME.Value in = Parameters!List.Value !!!!!!!!!!!! Work Fine
But I need to change it like as
If Parameters!List.Value = 'Select All' Then
Fields!NAME.Value in = Parameters!List.Value or Fields!NAME.Value = " "
Else
Fields!NAME.Value in = Parameters!List.Value
End
Can you give an advice who can I resolve it please !!!
I'm working in SSRS R2
Thanks!!
This worked for me
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, FALSE)
Operator: =
Value: =IIF(Parameters!pLocation.Value <> " All Locations", Parameters!pLocation.Value, FALSE)
If you use Filter on your Dataset, try this:
Expression: [NAME]
Operator: IN
Value (fx): =Split(Replace(Join(Parameters!List.Value, ","), "Select All", " "), ",")
Try to work along this path. Basically you can reconstruct the multi value items into a string with Join(), and deconstruct it again into array by using Split(); where in between, you can manipulate them, for modifying (e.g. converting "Select All" into " "), adding (imitating "OR"), or removing extra items.
There is an alternative for this.
Add one more item to the paramater dataset values say "Not Available" as Label and value with the null. then there will be no change in the stored procedure and you can retrieve the data.
If the user select the specific item then he will get those values only. If he selects all then he will get the data for the null also with the all the others.
Hope this will help
You can put the logic in just one location if you do it this way.
You filter on the parameter, unless it's all values then the filter always matches.
Just a little cleaner.
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, " All Locations")
Operator: =
Value: =Parameters!pLocation.Value