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.  
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
Post a Comment