When I run my expression, I get 6 inside of 5 as the expression is counting space. Can anyone please help to amend my expression
=CountDistinct(IIF(Fields!EnrolmentAtRiskStatus.Value ="No Risk", Fields!RefNo.Value,""))
CountDistinct counts non null values. An empty string is not null.
try the following
=CountDistinct(IIF(Fields!EnrolmentAtRiskStatus.Value ="No Risk", Fields!RefNo.Value,nothing))
Related
I'm trying to calculate the total of cost in RDLC report using expressions
I applied the following and it works fine :
=SUM(Val(Fields!PCOST.Value))
But I tried to apply another expression to calculate the cost but with a condition like below :
=IIf(Fields!Active.Value =False, SUM(Val(Fields!PCOST.Value)),0)
but only I got 0.00?
can anyone explain why?
the table [Active] field type is bit
You need to sum the result of the IIF rather than the other way round. I've not tested this but I think the following should work...
=SUM(IIf(Fields!Active.Value =False, Val(Fields!PCOST.Value),0))
I am trying to piece together a nested "IIF" statement to produce one of three Values but my line is not working
=IIF(Fields!LeaseNumber.value = "", "Vacant",Fields!tenantName.value) AND (IIF(Fields!tenantName.Value ="",Fields!LeaseDBA.Value, Fields!tenantName.Value))
My expected outcome should be:
If No lease# - "Vacant"
if no tenantName - "LeaseDBA"
all other rows just give me - "tenantname"
All the other questions I reviewed didn't seem to match this type of IIF clause.
Any help really is appreciated.
I've actually recently just tried to expalain how the IIF expression works and how to nest them. https://stackoverflow.com/a/35289515/4579864
To check if a value is null or empty, you're better off using one of these functions:
You can use IsNothing() to check if there is a value. Applied to your example would result to this:
=IIF(IsNothing(Fields!LeaseNumber.value)
,"Vacant"
,IIF(IsNothing(Fields!tenantName.Value), Fields!LeaseDBA.Value, Fields!tenantName.Value))
You can calculate the length of your value with Len() and then check if it is larger than 0.
=IIF(Len(Fields!LeaseNumber.value) > 0
,IIF(Len(Fields!tenantName.Value) > 0, Fields!tenantName.Value, Fields!LeaseDBA.Value)
,"Vacant" )
If No lease# - "Vacant" (If there is no LeaseNumber then show "Vacant" -String only)
If no tenantName - "LeaseDBA" (If there is not tenantName then show Fields!LeaseDBA.Value
And for other rows just give me Fields!tenantName.Value
If this is you want then try below expression.
IIF(Trim(CStr(Fields!LeaseNumber.Value))="","Vacant",CStr(Fields!tenantName.Value)) & IIF(Trim(CStr(Fields!tenantName.Value))="",Fields!LeaseDBA.Value,CStr(Fields!tenantName.Value))
I had to display one value on the basis of expression i.e. If column value =1 Print Y, if value=0 print N if value='' print N and value=NULL print N on to the column.
I tried the Below Code
=IIF(IsNothing(Fields!MyColumnName.Value),"N",IIF(Fields!MyColumnName.Value=1,"Y","N"))
But this is not working for the NULL values and Blank values in the column.
Thanks in advance...!!
Your problem comes from the fact that SSRS evaluates all potential paths of an expression before executing it. Therefore, when it tries to compare '' to the integer 1 it fails, reporting the #Error
To protect against this you can wrap your fields in a CStr (Convert to String), giving the expression
=IIF(IsNothing(Fields!MyColumnName.Value),
"N",
IIF(CStr(Fields!MyColumnName.Value)=CStr(1),
"Y",
"N"
)
)
The example below shows the value for myColumnName, the result with your current expression, a description of the value it is evaluating, and then the result of the above expression in the final column
Hopefully this will assist you. Let me know if you require further help, or have more questions on this.
I have a row group of STATUS fields. There is a group that returns null that I would like to change to chat. I have tried:
=Iif(IsNothing(Fields!STATUS.Value), "Chat", Fields!STATUS.Value)
but the group still returns blank. Would anyone have any ideas on how to help me resolve this?
Your code is right. Are you sure it's returning nothing, and not something like a space or carriage return?
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: