SSRS complex IIf expression - reporting-services

I'm stuck on an expression. Below is programmatically what i want to do, but SSRS is not having it... How can I get this to work?
=IIf(Fields!TransTypeLabel.Value = "Hour", Fields!SalesAmount.Value, IIf(Fields!TransTypeLabel.Value = "Fee" AND Fields!CategoryId.Value = "TIME_FEE", Fields!SalesAmount.Value, 0), 0)

ake the final " , 0" out (but not the end brace). You also have missed .Value (or .Label depending on what you actually want) from the end of some field references. e.g. Fields!TransTypeLabel should. be Fields!TransTypeLabel.Value . Or maybe that was a type and should have read Fields!TransType.Label ?

Related

IIF statements with Multiple conditions in SSRS Expression

My expression is different than the ones I looked at already. MY code looks like this and I am having a hard time logically reading it. The code works but is part of another larger IIF statement that is used to filter out certain values on a given table column on the report.
I want to be able to "learn" how to read this type of IIF statement as it really does not make sense to me as written.
=IIF(Fields!DMDeptARCFlag.Value=1,
IIF(Fields!CloseFlag.Value=1,"",
IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment","")),"")
This expression is called "InvalidPaymentLoaded" and is used in the following expression
=TRIM
(IIF(IsNothing(Reportitems!WTBTIClosure.Value)=0 AND Fields!SrMgmtStatus.Value = 1 AND Fields!DMDeptARCFlag.Value = 1, Reportitems!WTBTIClosure.Value, "") +
IIF(IsNothing(Reportitems!ARCPaymentNotLoaded.Value)=0 AND Fields!DMDeptARCFlag.Value <> 1, Reportitems!ARCPaymentNotLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidARCClose.Value) =0, Reportitems!InvalidARCClose.Value , "") +
IIF(IsNothing(Reportitems!BCDPayementNotLoaded.Value)=0, Reportitems!BCDPayementNotLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidPaymentLoaded.Value)=0, Reportitems!InvalidPaymentLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidMISCClosure.Value)=0, Reportitems!InvalidMISCClosure.Value, "") +
IIF(IsNothing(Reportitems!InvalidMCFClose.Value) =0, Reportitems!InvalidMCFClose.Value , "") +
IIF(IsNothing(Reportitems!InvalidDeductionClose.Value)=0, Reportitems!InvalidDeductionClose.Value, ""))
Your IIF is not that complex if you break it down....
Remember basic syntax for IIF is...
IIF([This is true], [then this], [else this])
So in you expression you have
"If DMDeptARCFlag =1 then do some more work, else return ""
=IIF(
Fields!DMDeptARCFlag.Value=1,
IIF(Fields!CloseFlag.Value=1,"", IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment",""))
,"")
If DMDeptARCFlag does equal 1 then we look at the first nested IIF which reads
If CloseFlag = 1 return "", else do some more work
IIF(Fields!CloseFlag.Value=1,"", IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment",""))
So if CloseFlag does not equal 1 then we look at the final nested IIF which simple reads
If ARCPaymentRequested = 0 return "Invalid ARC Payment", if not return ""
I think you could simplify the expression though as really you only ever return 1 of 2 values so if you work out all the conditions for returning one value you should be able to get rid of all those nested IIFs
Something like this
=IIF(
Fields!DMDeptARCFlag.Value=1 AND Fields!CloseFlag.Value <> 1 AND Fields!ARCPaymentRequested.Value=0
, "Invalid ARC Payment"
, "")

Argument not specified for parameter 'FalsePart' of 'Public Function

I'm trying to get a field condition to give me N/A when blank. Also to give me Fail on certain conditions. In addition, on a variable,pass/fail give me PASS or fail per the variable.
What is missing from my syntax?
=IIf(IsNothing(Variables!PassFail.Value),"N/A", iif(Variables!NameVer.Value = " x") Or (Variables!levPassFail.Value = "FAIL") Or (Variables!countPassFail.Value = "FAIL"),"FAIL", Variables!PassFail.Value)
The syntax was wrong but it's difficult to know exactly what you want to achieve.
The following will reproduce your original attempt
=IIF(
IsNothing(Variables!PassFail.Value)
,"N/A"
, IIF(Variables!NameVer.Value = " x" Or Variables!levPassFail.Value = "FAIL" Or Variables!countPassFail.Value = "FAIL"
,"FAIL"
, Variables!PassFail.Value
)
)
Note: I'm not sure if = " x" is a typo and should be = "x" but I left your original code in there.
If this does not help, please list the possible scenarios and the required output in each, then I can offer a more accurate solution.

Replace #Error or NAN with -(hyphen) in SSRS

When i get a value into the text box (say "NAN" or "#Err") i want to replace it with -(hyphen).
How to achieve this in SSRS reporting ?
Thanks in advance.
You'll need to write an expression to handle it. Ideally, you would have some custom code function in your report (ie. Code.SafeDivision())
=iif(Fields!denominator.Value = 0, "-", Numerator / Denominator)
To elaborate on cmotley's answer, add the following as custom code to your report (to do this go to report properties, then code and then paste this in):
Function SafeDivide(value1 As Decimal, value2 As Decimal) As Decimal
If (value1 <> 0.0 And value2 <> 0.0) Then
Return value1 / value2
Else
Return 0
End If
End Function
Then you can use this in your textboxes to divide without receiving not a number and/or error, for example, adding the following as an expression (changing textbox names as required):
=Code.SafeDivide(ReportItems!Textbox186.Value, ReportItems!Textbox184.Value)
Divides two textboxes using our function.
To show a dash you can simply change the formatting of your textbox to 'number' and tick the box indicating that you'd like to replace '0' with '-'.
Alternatively if for some reason 'NaN' is coming through explicitly from a datasource (rare but not impossible when referencing a loaded table in SharePoint) you could use the following:
Function evalutator(value as String) as String
Select Case value
Case "NaN"
Return "-"
Case "NAN"
Return "-"
End Select
Return value
End Function
What about:
=IIF(Fields!yourcolumnname.Value = 0, "-", Fields!yourcolumnname.Value*1)
Or if you wanted zero's where you get NAN/#ERROR then you could use:
=IIF(Fields!yourcolumnname.Value = 0, Fields!yourcolumnname.Value*1, Fields!yourcolumnname.Value)

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

How can you check for null in a VBA DAO record set?

I have an optional field in a database that I'm pulling out using a DAO Record Set. I need to check whether or not the field is set before I concatenate it with other fields. So far I have the following code snippet which I've tried with both Is and = (that's the obviously wrong syntax [[Is | =]]) to no avail. It appears that if I use = it will not correctly compare with Null and if I use Is then it complains that it's not comparing with an Object.
While Not rs.EOF
If rs.Fields("MiddleInitial") [[Is | =]] Null Then thisMiddleInitial = "" Else thisMiddleInitial = rs.Fields("MiddleInitial")
If prettyName(myLastName, myFirstName, myMiddleInitial) = prettyName(rs.Fields("LastName"), rs.Fields("FirstName"), thisMiddleInitial) Then
MsgBox "Yay!"
End If
rs.MoveNext
Wend
If there's a simpler way to do this I'm totally open to it. prettyName takes 3 Strings as parameters and initially I was just trying to pass rs.Fields("MiddleName") directly but it threw up at a Null value. I'd prefer to do something more direct like that but this is the best I could come up with.
How about:
IsNull(rs.Fields("MiddleInitial").Value)
You could also have a look at this article which has some explanation about Null values in Access VBA apps and how to handle them.
For the example you show, Nz would work:
thisMiddleInitial = Nz(rs!MiddleInitial,"")
Or simply concatenating the string with an empty string:
thisMiddleInitial = rs!MiddleInitial & ""
Your question has been answered by Remou, seems to me, but it occurs to me that you may just be trying to get proper concatenation of the name fields. In that case, you could use Mid() and Null propagation in VBA to get the result.
I don't use separate middle initial fields, so my usual name concatenation formula is:
Mid(("12" + LastName) & (", " + FirstName), 3)
The "12" string at the beginning is going to be tossed away if LastName is Not Null and ignored if it is null, because the + concatenation operator propagates Nulls.
To extend this to include middle intials would look like this:
Mid(("12" + LastName) & (", " + FirstName) & (" " + MiddleInitial), 3)
Assuming your UDF is not doing some kind of complicated cleanup of nicknames/abbreviations/etc., this could replace it entirely, seems to me.
If rst.Fields("MiddleInitial").Value = "Null" Then
This works for me. I use MS SQL Database.
I think the NoMatch option might work in this situation:
If rs.NoMatch = True Then
I prefer using the below to account for both Null and Empty string values. It's a good check to use you have forms collecting values from users.
If Trim(rs.Fields("MiddleInitial") & "") = "" then