I have an expression in a table that checks if there was a return value.
If the query returns empty or null I want to set the value to 0.
=IIF(IsNothing(Fields!DndCount.Value),0,Fields!DndCount.Value)
But if the query returns empty IsNothing() does not work.
I have tried this code and it worked for me.
IIF(Sum(Fields!DndCount.Value)Is Nothing, "0", Sum(Fields!DndCount.Value))
Alternative solution to avoid using expressions, change the cell format to #,##0 in properties. Easier then to pair it up with count or sum.
Try this:
=IIF(Fields!DndCount.Value=0 OR
IsNothing(Fields!DndCount.Value)=0 OR
Fields!DndCount.Value="null",0,Fields!DndCount.Value)
Since IsNothing will return a True or False value you need to set your expression as:
=IIF(IsNothing(Field1) = True, 0, Field2)
Hope it helps.
You can also try to use the IsMissing expression of the field,
like this:
=IIF(Fields!Accounting_Amount.IsMissing, 0, Fields!Accounting_Amount.Value)
Related
I have two parameters , let's say P1 and P2. The sample expression I used for P2 is
IIF(P1.Label="string", "null" ,Split(P1.Label," ").GetValue(0))
When the condition is false, the split expression is working fine. But if the condition is true, I'm getting 'Index was outside the bounds of the array' error. If the condition is true, I need to pass the value "null" as varchar type.
Can someone please advice on this?
The problem with the IIF function is that it is a function not a language construct. This means that it evaluates both parameters before passing the parameters to the function. Consequently, if you are trying to do a Split on a parameter that can't be split, you will still get the 'Index was outside the bounds of the array' error, even when it looks like that code shouldn't be executed due to boolean condition of the IIF statement.
The best way to solve this is to create a safe string splitter function in custom code where you can use real language constructs. Also, check that the string is splittable by checking it contains a space instead of checking for a special string:
Public Function SafeSplit(ByVal SplitThis As String) As String
If InStr(SplitThis, " ") Then
Return Split(SplitThis, " ")(0)
End If
Return "null"
End Function
and then use this in your report for the Value expression instead of IIF:
=Code.SafeSplit(Parameters!P1.Label)
I'm getting a problem with one of my expression in my report. It always gives me #Error and I think I know why but don't know how to set my expression.
Here's my expression :
=IIF(Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
The Fields CMMTTEXT can be null sometimes and I'm getting an error on all of my rows except the one that has data in the CMMTTEXT field.
So I need a isnothing but I've tried couple ways of doing it but doens't seem to work
=IIF(IsNothing(Fields!CMMTTEXT.Value.Contains("*Return*")) AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
also this that I've seen on this forum :
=IIF(IsNothing(Fields!CMMTTEXT.Value) OR Fields!CMMTTEXT.Value.Contains("*Return*") AND Fields!SOPTYPE.Value = "INVOICE", "*** See return ***", "")
I have no idea at this point.
Thanks for the help!
The Contains function doesn't work with NULL values. Once it throws an error, the IsNothing function subsequently can't evaluate the results. Separating these out using the OR operator also doesn't work because it tries to evaluate both conditions even when the first one was true.
One way to work around this is to first check for NULL values and replace them with an empty string. Then use the Contains function on the results of this expression:
=IF(IsNothing(Fields!CMMTTEXT.Value), "", Fields!CMMTTEXT.Value).Contains("*Return*")
I am working in a SSRS that needs to link a report based on the value in a textbox.
I have tried:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing)
Which works fine, but when I try to add another condition like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",Nothing) OR
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing)
Then it does not link any report. How do I do this right?
What you are trying does not work correctly as the IIF statements are not nested and what it is doing is:
IIF(this, true part, false part) OR IIF(this, true part, false part)
So when Fields!Factors.Value = "Touched Leads" the expression evalutes to SCPL OR Nothing which isn't valid.
Alternatively you could use SWITCH which has a nicer syntax, the final True statement is your catch all
=SWITCH(
Fields!Factors.Value = "Touched Leads", "SCPL",
Fields!Factors.Value = "TOTAL", "Disposition",
True, Nothing
)
I think that the expression you need will look like this:
=IIf(Fields!Factors.Value = "Touched Leads","SCPL",
IIf(Fields!Factors.Value = "TOTAL","Disposition",Nothing))
This checks the first condition ("Touched Leads"), if that is true, link the SCPL report, otherwise check the "TOTAL" condition. If that one is false, return Nothing.
->andFilterWhere(['=>',"invoiceDate - dueDate",$this->overDueLimit])
i need this filter to extract overDue invoices in gridview. "invoiceDate - dueDate" should be a sql function which returns a number. but Yii2 takes this as a string(as a field name).
How to perform the same task in a correct way? Thanks
Thanks Scais Edge.I found the solution based on your suggestion. I added the following lines to the search method and it solved my problem.
if(!empty($this->overDue))
{
$terms=MyFunc::validate($this->overDue);// sanitize and get number
$query->andFilterWhere(['>=',"DATEDIFF(CURDATE(),`dueDate`)",$terms])
->andFilterWhere(['=', 'status', self::$pending]);
}
seems the filterWhere don't allow calculated value so you can use instead andWhere() that admit literal where condition. So you can create your where condition for the query you need .. in this case you must check if the value of $this->overDueLimit is setted ..
if ( isset($this->overDueLimit ) ) {
$query->andWhere("invoiceDate - dueDate => " . $this->overDueLimit);
}
check obviusly for a proper sanitaze of the var $this->overDueLimit
I have a report parameter of boolean type.
If the value is true, a filter needs to be applied to a dataset, and if false it should not filter.
Sounds simple, but can't figure out..
Any suggestions?
In your dataset query you can add logic like:
WHERE
(
#MyBooleanParam = 1 AND <filter code>
)
OR
(
#MyBooleanParam = 0
)
So if the parameter is True, then the filter logic is applied in the query, if the parameter is false then no filter is applied.
I'd use Nathan's but an alternative would be to set up your filter as normal but wrap the expression in an IIf function that short circuits the filter:
=iif(parameter!myboolean.value = 1, parameter!myfilter.value, fields!field_im_filtering.value)