sbdt8631
asked on
SSRS Expressio #Error (Division bu 0?)
This is my expression
=iIf(not(isnothing(fields! MonthSales 1_LY.value )) and not(isnothing(fields!Month Sales1_LY. value)),fi elds!Month Sales1.val ue/fields! MonthSales 1_LY.value - 1,"-")
When fields!MonthSales1.value/f ields!Mont hSales1_LY .value is a null value and fields!MonthSales1.value is a positive value I get #Error as my result. I asume it means division by 0 or unknown value.
But if I remove the arithmetic calculation and substitute "100"
=iIf(not(isnothing(fields! MonthSales 1_LY.value )) and not(isnothing(fields!Month Sales1_LY. value)),"1 00","-")
I get "100" when both values exist and "-" when either does not. Why is it trying to divide by the null value in the first expression?
=iIf(not(isnothing(fields!
When fields!MonthSales1.value/f
But if I remove the arithmetic calculation and substitute "100"
=iIf(not(isnothing(fields!
I get "100" when both values exist and "-" when either does not. Why is it trying to divide by the null value in the first expression?
ASKER
The typo was just the result of frustrated changes. I get the same results with the typo corrected.
When I try isnull() in the expression, it marks it as an error called "unrecognized identifier." I used isnothing after a google search for "ssrs is null" suggested isnothing. I am open for alternatives.
When I try isnull() in the expression, it marks it as an error called "unrecognized identifier." I used isnothing after a google search for "ssrs is null" suggested isnothing. I am open for alternatives.
my error, I got confused with ISNULL() from another language.
I know this is not correct, but does it avoid the error:
=iIf(not(isnothing(fields! MonthSales 1.value)) and not(isnothing(fields!Month Sales1_LY. value)),fi elds!Month Sales1.val ue/fields! MonthSales 1_LY.value - 1,0)
I know this is not correct, but does it avoid the error:
=iIf(not(isnothing(fields!
What version of SSRS are you using? I tried to reproduce your problem in 2008 R2 and it worked fine with this expression:
=iIf(not(isnothing(fields! MonthSales 1_LY.value )) and not(isnothing(fields!Month Sales1.val ue)),field s!MonthSal es1.value/ fields!Mon thSales1_L Y.value - 1,"-")
This gave me this result:
But you might find the solution for your problem here:
http://www.sqlservercentral.com/Forums/Topic442497-150-1.aspx
=iIf(not(isnothing(fields!
This gave me this result:
But you might find the solution for your problem here:
http://www.sqlservercentral.com/Forums/Topic442497-150-1.aspx
=IIF(Fields!Order.Value >0, Fields!Order.Value, Join("-" , CStr(Fields!Order.Value))
@PatelAlpesh, I get an error when I use that expression, did you test it?
ASKER
Everyone, I attached a pdf of the output. January is the only month that applies.
Nicobo
Based on your link above I tried
=iIf(not(isnothing(fields! MonthSales 1.value)), fields!Mon thSales1.v alue /
IIF(not(isnothing(fields!M onthSales1 _LY.value) ),fields!M onthSales1 _LY.value - 1, "-"), "-")
and
=iIf(not(isnothing(fields! MonthSales 1.value)), fields!Mon thSales1.v alue /
IIF(isnothing(fields!Month Sales1_LY. value), "-",fields!MonthSales1_LY. value - 1), "-")
I still get #Error if no LY sales
PatelAlpesh
I am afraid I don't understand what you are suggesting.
I tried updating my Visual Studio 2005 to service pack 1 in case this was just a bug that might have been fixed, but that did not help.
dqmq
=iIf(not(isnothing(fields! MonthSales 1.value)) and not(isnothing(fields!Month Sales1_LY. value)),fi elds!Month Sales1.val ue/fields! MonthSales 1_LY.value - 1,0)
This was pretty much my original syntax, but I tried copy/paste and still get the #Error.
Sales-by-KAM.pdf
Nicobo
Based on your link above I tried
=iIf(not(isnothing(fields!
IIF(not(isnothing(fields!M
and
=iIf(not(isnothing(fields!
IIF(isnothing(fields!Month
I still get #Error if no LY sales
PatelAlpesh
I am afraid I don't understand what you are suggesting.
I tried updating my Visual Studio 2005 to service pack 1 in case this was just a bug that might have been fixed, but that did not help.
dqmq
=iIf(not(isnothing(fields!
This was pretty much my original syntax, but I tried copy/paste and still get the #Error.
Sales-by-KAM.pdf
ASKER
I just viewed the file I attached and it did not export very well. Page two demonstrates the problem.
Try:
IIF(not(isnothing(fields!M onthSales1 _LY.value) ),fields!M onthSales1 _LY.value - 1, "-")
Which would try to divide by "-" when MonthSales1_LY is null. That would cause an error.
You are using SSRS 2005 right?
=iIf(not(isnothing(fields!MonthSales1.value)) and not(isnothing(fields!MonthSales1_LY.value)),fields!MonthSales1.value /
IIF(not(isnothing(fields!MonthSales1_LY.value)),fields!MonthSales1_LY.value - 1, 1), "-")
You hadIIF(not(isnothing(fields!M
Which would try to divide by "-" when MonthSales1_LY is null. That would cause an error.
You are using SSRS 2005 right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked. Thank you
2. Probably should use isnull() instead of isnothing()
3. The True side of your IFF returns a number, the False side of your IIF returns a string. There may be some implicit conversion saving your butt, but it's a bad practice