Hello i tried using both switch as well as iif function in ssrs report. I have a column(Delta) which has values and need to set image depending on column values. Below is my switch statement
=Switch(
Fields!Delta.Value =0,"arrowzero.jpg",
Fields!Delta.Value >0,"arrowup.jpg",
Fields!Delta.Value <0,"arrowup.jpg",
Fields!Delta.Value ="CNC","arrowblack.jpg"
)
Switch statement is working for all cases except last case "CNC".
A couple of observations that might help you fix this.
You switch statement uses the same column however the first three evaluate it numerically, the last one against a string. Is this correct?
Is the image called "arrowblack.jpg", is there a typo here?
If the last option is supposed be act like an ELSE then you can replace Fields!Delta.Value ="CNC","arrowblack.jpg" with True,"arrowblack.jpg"
Related
I'm amalgamating several manual reports into one SSRS one by changing the select statements to follow a set format of:
select
'DepartmentName'
,'StatName'
,'DataType' --(Int, percentage,date,time, etc)
,'Stat'
from TablesNeeded
Now this unions together fine so I end up with a list of statistic names and their values. After this I want to have the cell showing "Stat" to change it's formatting based on the result of "DataType"
I attempted to use an IIF to determine the format, which behaved with a single IIF statement, however after nesting to accomodate different data taypes it appears to "false" every IIF result and return just the default/value:
Working
=iif(
Fields!DataType.Value="Percentage"
,Format(Fields!Stat.Value,"0%")
,Fields!Stat.Value
)
"Falsing"
=iif(
Fields!DataType.Value="Percentage"
,Format(Fields!Stat.Value,"0%")
,iif(
Fields!DataType.Value="Date"
,Format(Fields!Stat.Value,"y")
,iif(
Fields!DataType.Value="int"
,Fields!Stat.Value
,Fields!Stat.Value
)))
and using switch similarily also "Falsed"
=Switch(
Fields!DataType.Value="Percentage",Format(Fields!Stat.Value,"0%")
,Fields!DataType.Value="int",Format(Fields!Stat.Value,"#,#0")
,Fields!DataType.Value="Date",Format(Fields!Stat.Value,"y")
)
I've asked a colleague and we're both stumped. Any ideas on proper expression formats?
Assuming all your datatypes are correct then you just need to use a simplified version of your switch statement in the Format property of the cell(s).
Something like..
=SWITCH(
Fields!DataType.Value="Percentage","0%"
,Fields!DataType.Value="int","#,#0"
,Fields!DataType.Value="Date","y")
)
Note You could just use "p0" for you percentage type, "n0" for your int.
I am writing a report that needs to display a different datediff calculation based on a specific Value from a column. If the order is "Active" start time to Now or if the order is ceased start time to stop time.
The individual DateDiff expressions work but when I try to combine them in one expression using either switch or IIF I get errors.
Any suggestions would be great.
=IIF(Fields!OrderStatus.Value="Active", DateDiff("d",Fields!OrderStartTime.Value, "Now"()),
IIF(Fields!OrderStatus.Value="Discontinued", DateDiff("d",Fields!OrderStartTime.Value, Fields!DiscontinueTime.Value)
)
)
=Switch(Fields!OrderStatus.Value="Active",
DateDiff("d",Fields!OrderStartTime.Value, "Now"()),
Fields!OrderStatus.Value="Discontinued",
DateDiff("d",Fields!OrderStartTime.Value, Fields!DiscontinueTime.Value),
)
You are missing the third argument for your second iif statement (in this case, it'll be {Nothing}. This should work:
=IIF(Fields!OrderStatus.Value="Active",DateDiff("d",Fields!OrderStartTime.Value,Today()),IIF(Fields!OrderStatus.Value="Discontinued",DateDiff("d",Fields!OrderStartTime.Value,Fields!DiscontinuedTime.Value),Nothing))
I have a master that can be filtered using 4 different parameters. I used a iif statement to join all the parameters to filter the report.
The problem I am now having is when more than one paramater is selected, it tends to return values for the first parameter rather than for all
My paramter expression is as follows:
expression
iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
values
=iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
Any help will be helpful
I think what you are trying to do is something like this:
=IIF(NOT ISNOTHING(Parameters!Div.Value), Parameters!Div.Value,
IIF(NOT ISNOTHING(Parameters!St.Value), Parameters!St.Value,
IIF(NOT ISNOTHING(Parameters!Sp.Value), Parameters!Sp.Value,
Parameters!Hc.Value)))
Do you only want to check for one value?
I usually check each parameter separately so it uses all of them at once. Though there may be a situation where your theory is what you want.
If you want to evaluate all the parameters, just add them to the FILTER of the dataset, table, or group. Choose your field in the Expression and the Parameter in the Value.
I have a number of fields in one column of my table. I have it if field1 is blank display field2 and so on, What i trying to do now is if all fields are blank display N/A.
What i have tried below;
=IFF(ISNothing(Fields!field1.Value) & IIF(IsNothing(Fields!field2.Value),"N/A",VbCRLF & Fields!field2.Value))
What this sometimes displays is field1N/A.
Can anyone point me in the right direction?
Thanks,
UPDATE 1:
I have also tried;
=IFF(ISNothing(Fields!field1.Value),"N/A",Fields!field1.Value & IIF(IsNothing(Fields!field2.Value),"N/A",VbCRLF & Fields!field2.Value))
That also did not work.
There are two ways to do this. You can either handle it in SQL Server Query or in the SSRS
Method 1: TSQL
You can use the COALESCE function to find the first non null value. Replace it with N/A if all are NULLs
SELECT COALESCE(Field1, Field2, Field3, 'N/A') AS newFieldValue, ....
FROM myTable.....
WHERE ....
Method 2: SSRS
There is no COALESCE equivalent in SSRS. You can either use iif or switch to emulate the logic.
=SWITCH(NOT(ISNothing(Fields!field1.Value)), Fields!field1.Value,
NOT(ISNothing(Fields!field2.Value)), Fields!field2.Value,
NOT(ISNothing(Fields!field3.Value)), Fields!field3.Value,
1=1, "N/A")
Also remember if there is space in the field, it won't be handled by ISNULL function. In that case you will also need to use the similar logic to handle the empty spaces.
HTH.
I'd suggest what you need is ISNULL.
Example usage as follows:
ISNULL(su.address1_line2, 'N/A')
This will find null values in that column and replace them with N/A in the report
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: