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
)
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
having a small issue here.
I have a Switch function in a report as shown below:
=Switch(
Fields!Duration.Value > 0, Round(Fields!Duration.Value / 60),
Fields!LastTime.Value = nothing, "Still Occupied",
Fields!LastTime.Value = Fields!FirstTime.Value, "Passing By"
)
This is for a column that is showing the total "Fields!Duration.Value" in minutes (rounded up), and it is working other than the second line:
If the Last Time value is the same as the First Time value, then it is assumed the object was just passing by and outputs "Passing By" and it does this correctly.
However, if the Last Time value is equal to nothing (it is defined in the column for "Last Time" that if it IsNothing, it is 'nothing', and it should output in this report with "Still Occupied" - which it's not doing. The cell is left blank, as if I have it written as Fields!LastTime.Value = nothing, nothing,
Why is this line of code not working?
Fields!LastTime.Value = nothing, "Still Occupied",
Thank you
You cannot test for Nothing using the = operator. There are two ways for which Nothing can be tested; using the IsNothing inspection function like this IsNothing(Fields!LastTime.Value) = True, or by using the Is operator like this Fields!LastTime.Value Is Nothing.
If these tests do not produce the expected result you may be dealing with a field that is set to something other than NULL, like empty '' or an arbitrary value. You can open the Query Designer on your Dataset properties to run your query and check the results.
You could also be looking at a mismapping with your dataset. Use the Refresh Fields button on your Dataset properties to verify your Field Mappings and then double-check that the name being used in your expression matches.
I found that using an IIF statement instead of a Switch statement worked for me, at least for this specific case:
=IIF(Fields!Duration.Value > 0, Round(Fields!Duration.Value / 60),
IIF(Fields!LastTime.Value = Fields!FirstTime.Value, "Passing by", "Still Occupied"))
Going to try to explain it for future people that might not understand (like me when I eventually forget it - I am very new to this sort of stuff) -
Rather than using the Switch statement I had in place to see if Fields!LastTime.Value is a number, equal to Fields!FirstTime.Value, or nothing, it now just asks if it is a number or if it is equal to Fields!FirstTime.Value, and if neither of those are true, it marks it as "Still Occupied" thus removing the need to reference nothing entirely. Like I said, this is pretty case specific, but you never know.
Thank you for the help #JamieSee and #SuperSimmer 44. Cheers!
Could be that nothing should be surrounded by " "
=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
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:
How to write multiple if statement in SSRS. I have written like this.
=IIf(Parameters!MyDuration.Value="ThisMonth" & Parameters!Transactions.Value="Sale", Sum(Fields!ThisMonthSal), True,False)
this is throwing an exception that multiple parameter used. Please guide me how to write this multiple if statement.
The & operator concatenates two strings. You're looking for the And operator. Refer to this msdn article.
In addition, note that IIF has three parts (see decision functions here), and works like this:
=Iif(test, truepart, falsepart)
I'm not sure what you're trying to do with the "SUM" bit (or what you're trying to achieve at all, the question's not clear on that), but something like this would work:
=IIf(Parameters!MyDuration.Value="ThisMonth" And Parameters!Transactions.Value="Sale",
Iif(Sum(Fields!ThisMonthSal.Value) = 0, "Zero sum", "Non-zero sum"),
"Not thismonth or sale")
Finally, you're not entirely clear about the error you're getting. If you're also having a problem with accessing the parameter you may have to investigate that seperately. In any case, the above should explain the Iif bit.