vb.net - how to avoid #Error and NaN in SSRS -


i have expression in report in order calculate ratios:

= sum(fields!paidlosses.value) /  lookup(fields!yearnum.value & fields!monthnum.value, fields!yearstartrisk.value & fields!monthnum.value, fields!earnedpremium.value, "earnedallcoverages") 

when choosing parameter not enough data got #error , nan. result of nan division of "-" on "-" values. , result of #error division of "-" on 0 values. enter image description here

try:

=sum(fields!paidlosses.value) /  iif( isnothing(   lookup(fields!yearnum.value & fields!monthnum.value,   fields!yearstartrisk.value & fields!monthnum.value,   fields!earnedpremium.value, "earnedallcoverages") ) or  lookup(fields!yearnum.value & fields!monthnum.value, fields!yearstartrisk.value & fields!monthnum.value, fields!earnedpremium.value, "earnedallcoverages") = 0,1, lookup(fields!yearnum.value & fields!monthnum.value, fields!yearstartrisk.value & fields!monthnum.value, fields!earnedpremium.value, "earnedallcoverages") ) 

this caused because cannot divide number 0 or nothing (ssrs nulls)

also can use custom code provided in this great answer safely perform divisions.

add below code in custom code textarea in report menu / report properties... / code tab

public function safedivide(byval numerator decimal, byval denominator decimal) decimal     if denominator = 0         return 0     end if     return (numerator / denominator) end function 

then in tablix call function numerator , denominator arguments:

=code.safedivide(   sum(fields!paidlosses.value),   lookup(     fields!yearnum.value & fields!monthnum.value,     fields!yearstartrisk.value & fields!monthnum.value,     fields!earnedpremium.value, "earnedallcoverages"     )   ) 

let me know if helps.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -