Hi guys I have a simple IFF expression
=IIF(Fields!MYCOLUMN.Value = true, "Yes", "No")
which is working fine, except other rows that have a blank or NULL in it's place are returning "No".
Is there a way to adapt my expression so that it ignores Null values? I have tried incorporating ISNOTHING but having trouble getting the syntax right.
IFF, IIF, or IF? If this is in the SQL query/stored proc and not the report itself, the answer below just changes to a SQL CASE statement.
Use a switch statement to define what you want displayed in the third case.
=Switch(
Fields!MYCOLUMN.Value = true,"Yes",
Fields!MYCOLUMN.Value = false,"No",
true,"")
Related
I have a database which tracks employee QA. I'd like to be able to search by a single Staff Member, a whole team, or a Unit. I have three controls that correspond to those fields and only one can ever have a value at once. In my quesry I'd like to have threee expressions that will limit my results by one of those three fields. I'm adding just one to start and I've hit a problem.
I found this https://www.acuitytraining.co.uk/microsoft-training-courses/access/if-statements/ which seems to do what I want. Here is the code I'm trying.
IIf(IsNull([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect]),
[UserLogin] Like "*",[UserLogin]=[Forms]![MainMenu]![btnManagersMenu].
[Form]![cmbStaffSelect])
Which works fine if the control has a value. (condition is false) If the dropdown has no value (condition is true) I get zero results. I suspect the problem lies with the Like "*" on my UserLogin field. Here is my query wizard and the buildler wizard for the IIF expression
Can anyone see why I'm not getting any results for the dropdown control being empty. To my thinking this should give me an unfiltered list of results. I have double checked my data and there are 137 records that should appear if I'm not limited by the staff selection.
The short version of this is if cmbStaffSelect has a value I want my records limited by that value. If cmbStaffSelect is blank I want to get all records.
Keep in mind that the iif function will always evaluate both the then and else arguments, before returning the appropriate value depending on the value returned when evaluating the supplied test expression.
As such, if either the then or else arguments have the potential to error when evaluated (regardless of the result of the evaluation of the test expression), then the iif expression has the potential to error.
As an alternative, you could use the Nz function to achieve the same result:
[UserLogin] LIKE Nz([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect],"*")
Perhaps your IsNull([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect]) is always returning false because cmbStaffSelect might be equal to empty string?
Try something like this:
IIf(Trim([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect] & "") = "",
[UserLogin] Like "*",[UserLogin]=[Forms]![MainMenu]![btnManagersMenu].
[Form]![cmbStaffSelect])
This checks to see if the cmbStaffSelect is "" ... if cmbStaffSelect is null - it converts it to "" by appending an "" to the null value.
I believe your hunch is exactly correct. If you want your query result to return the * symbol for the UserLogin field; then alter your IIF statement to be: [UserLogin] = "*"
I am hoping someone can help me here. I am using the PMT function to calculate mortgage payments in SSRS. I am using the following Formula
=IIF(Note = "Present",-PMT(Rate/12,Term,Balance,0,DueDate.EndOfPeriod),Nothing))
The formula works perfectly when Note = Present. However on all other loans it is producing #ERROR. I don't understand why this is happening.
Is there some other error handling that needs to be done to simply leave the cell blank if the note is not present?
I'm not familiar with PMT but it could be that the values passed to PMT are invalid for loans where Note is not "Present". If this is the case then I would use a SWITCH statement instead. SWITCH will stop at the first expression that evaluates to True, whereas IIF evaluates all expressions, even the expression that does not get used!
try this..
=SWITCH(
Note <> "Present", Nothing,
True, -PMT(Rate/12,Term,Balance,0,DueDate.EndOfPeriod)
)
This way, if note is not "Present" then return nothing and only if it IS "Present" evaluate the PMT function and return its value. The True just acts like an else to save us writing Note = "Present" for the second condition
SSRS will always evaluate both sides of a conditional expression, no matter what the result of the first parameter boolean test. This means that
-PMT(Rate/12,Term,Balance,0,DueDate.EndOfPeriod)
must be a valid calculation for rows where Note <> "Present" as well or you will get an expressions error. I would suggest that probably some of the other fields aren't populated with appropriate "dummy" values in this scenario.
What is Nothing in your code?
=IF(Note = "Present",-PMT(Rate/12,Term,Balance,0,DueDate.EndOfPeriod),0))
The field is taken from the table and is the source of data for the textbox, in which I want to apply conditional formatting. Almost always it is NULL. The expression for the conditional formatting:
Not IsNull ([duedate])
Always returns true, I do not understand why. Field [duedate] belongs to the parent form.
I think you need to check the length also along with IsNull like
Len(Field) = 0
I am using below expression in SSRS but is not giving expected result.
=IIf(Fields!Completed_Date.Value Is Nothing,
Nothing,
IIf(First(Fields!TIMEFORMAT.Value,"dsPreferences") = True,
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy hh:mm:ss tt"),
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy HH:mm:ss")
)
)
It has to check if Date is null.If it is null just leave field blank.If it is not null then it has to return value according to Time zone value that it is getting from another dataset.This expression works fine when there is non null date but it returns #error when there is Null date.
Try using this syntax:
=IIf(IsNothing(Fields!Completed_Date.Value), "", <yourFalsePart>)
This syntax probably doesn't solve your issue because Completed_Date is also used in the false part. IIf operator will always evaluate both expressions before deciding which one to use: so if Completed_Date is Nothing it will broke your expression anyway.
Try using a Custom Function as explained here: SSRS expression giving error with iif condition
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: