=IIF(Fields!statusID.Value = "In Progress", "Gold", "Silver"), IIF(Fields!statusID.Value = "Rejected", "Red", "Silver"), IIF(Fields!statusID.Value = "Completed", "Green", "Silver"), IIF(Fields!statusID.Value = "Archived", "Blue", "Silver")
The above script is an effort of creating a conditional effect on rows in a report that I am building. The idea is of course to have the entire row of 13 columns to show a different color depending on the values caught from Fields!statusID
I have the condition set up under the properties of the report. My issue is when I put the condition on and run the report, I get error: [BC30205] End of Statement error. And I am unclear as to what this means and how to fix the issue.
Does it matter that the Fields!statusID is originally stored as a integer and then a =Switch is attached to it to produce a word?
Any help will be appreciated in this. Thanks in advance
Figured it out. Instead of writing it as an IIF, I wrote it using the Switch Function, while replacing the characters to integers as it is stored in my database
Related
I have three datasets in my report, I'm trying to just set an expression in a textbox for one of the datasets - I am trying to do:
if IsCompleted = 1, show dateSurveyed, otherwise show "N/A" (for testing I've been just trying to use "works" rather than a date)
I have tried:
=IIf(First(Fields!IsCompleted.Value, "CompletedSurvey") = "1", "works", "N/A")
(this one runs, but shows N/A when it should show "works"
=first(IIf((Fields!IsCompleted.Value) = "1", "works", "n/a"), "CompletedSurvey")
I've also tried removing "first", but then I get an error saying that I must have it contain in aggregate functions which specify a dataset scope.
I feel like I've tried a bunch more other options but nothing has worked.
Any suggestions?
My datasets:
Dataset CompletedSurvey
I hope my title is clear enough. I'm working in MS Report Builder, using a function that applies a regular expression to a queried value in order to get back a certain substring. The regex works fine, so I'll demonstrate a simpler version here to make this less wordy. Here's the gist of my equation:
=IIF(Len(Fields!CourtLocation.Value) < 1, "none",System.Text.RegularExpressions.Regex.Match(Fields!CourtLocation.Value, "(?:[A-Z]{2,4})").Value))
The main purpose is to get that substring, but I added the IIF so that on those occasions when the CourtLocation.Value is empty (I tried Is Nothing in my expression as well), the function returns "none" rather than "#Error"
I've been looking around for a solution, but nothing has worked; it seems like most other people who talk about this are using a mathematical equation rather than trying to get a string. Can anyone help me get rid of that stupid "#Error" value?
You could try this (untested)
=System.Text.RegularExpressions.Regex.Match(
IIF(
Len(Fields!CourtLocation.Value) < 1,
"none",
Fields!CourtLocation.Value
)
, "(?:[A-Z]{2,4})"
).Value
This way the IIF is performed on the string that you want to pass to the regex function, so it always gets a valid value to process
Iif evaluates both sides, so you can nest two Iif statements to avoid the error.
Did you already read this one?
https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/
I'll copy the text into the answer if that solves it for you.
I have a columns in my dataset that will be returning several different values. In an attempt to to use grouping in the report I am trying to clean up the data. After reading several posts I found this post that seemed to be very close to what I needed.
I set up my expressions like this
=SWITCH(
Left(Fields!T6_TOW_BY.Value,3)="ACE","ACE WRECKER",
Left(Fields!T6_TOW_BY.Value,3)="CAR","CAR STORE",
Left(Fields!T6_TOW_BY.Value,7)="THE CAR","CAR STORE",
Fields!T6_TOW_BY.Value
)
The expression does not throw an error when I preview it, but all the columns show "error" Can anyone please show me where I am going wrong here?
Thanks
The Switch statement requires pairs of arguments. You can't just have the last value by itself as an Else condition. Try this:
=SWITCH(
Left(Fields!T6_TOW_BY.Value,3)="ACE","ACE WRECKER",
Left(Fields!T6_TOW_BY.Value,3)="CAR","CAR STORE",
Left(Fields!T6_TOW_BY.Value,7)="THE CAR","CAR STORE",
True, Fields!T6_TOW_BY.Value
)
I am trying to get a column in a report, and I am having the issue where the report will show #error in the column. I think I have found the cause, but I am unsure, and I'm also unsure how to solve it.
The code I am currently using is:
=iif(SUM(Fields!ask_response.Value)>SUM(Fields!ask_totalduration.Value), "Time Met", "Time not Met")
Some of the values have 0 in the one of the 2 columns involved. Is there a way to get it to say "Time Not Met" if the value is 0?
Thanks
Joe
Nested IIf's are a true pain and I have had similar issues before. Copy this to a new location and start over, working your way from the inside out, testing at each level to make sure you do not get an error.
I am not sure you should be using sum in this instance.
I am not sure if this will work but I have...
=iif(IIf(IsNothing(Fields!ask_response.Value),0,Fields!ask_response.Value) > IIf(IsNothing(Fields!ask_totalduration.Value),0,Fields!ask_totalduration.Value),"Time Met", "Time not Met" )
I am facing very simple issue but not getting solution over it.
I have textbox in my ssrs report, I am passing value "1;prashant" or null to it. Now, if I pass value "1;prashant" to textbox then textbox should show only "prashant" and If I am passing nothing then it should be blank.
I have tried following IIF condition:
=IIF(IsNothing(FieldS!WIAPPORVER.Value),"",Split(Fields!WIAPPORVER.Value,"#")(1).ToString())
But, I above code is giving an error ["#error" shows in textbox] if I am passing blank value.
Please let me know, where I am wrong in this.
Thanks
There are probably better ways of doing this, but this is what my head came up with at the time:
=IIF(
IsNothing(Fields!WIAPPROVER.Value)
,""
,Right(Fields!WIAPPROVER.Value,Len(Fields!WIAPPROVER.Value) -InStr(Fields!WIAPPROVER.Value,";"))
)
I believe SSRS is trying to compute everything in the report at runtime, so in your case it is still trying to fetch index 1 from an array even though there is nothing in it and it crashes.
Edit: Changed parameters to Fields. I created a parameter to remake the issue at my side.
Just get the split out of the iif. Then in your iif, if field is nothing create a string that when split will return ""
=Split(IIF(IsNothing(FieldS!WIAPPORVER.Value),"#", Fields!WIAPPORVER.Value),"#")(1)
You are relying on the IIf expression short circuiting, but SSRS IIf expressions do not short circuit - the expression will try and work out Split(Fields!WIAPPORVER.Value,"#")(1).ToString() for all rows and fail when this value doesn't exist.
You can get this going by using text expressions, which don't get this error.
With test data:
And a simple table:
I have added columns with both your existing expression and a new expression:
=Right(Fields!WIAPPORVER.Value, Len(Fields!WIAPPORVER.Value) - InStr(Fields!WIAPPORVER.Value, "#"))
This new expression works for NULL values, empty strings and strings with no delimiter present: