reporting services - Converting string to decimal if string isNumeric in SSRS to calculated weighted average -
i have dataset in ssrs column contains both decimals , string value of 'n/a'. sql casts column string (varchar(10)).
example of dataset:
board urgency ticketcounty averestime averesoltime support open - priority 2 4 5.766666 n/a support priority 1 2 1.833333 0.125925 priority 1 3 2.733333 0.875925 priority 2 1 0.000000 0.294444
in total row need calculate weighted average averesoltime each board. expression created:
=sum(fields!ticketcountbypriority.value * iif(isnumeric(fields!averageresolutiontime_busdays.value)=1, cdec(fields!averageresolutiontime_busdays.value), 0))/sum(iif(isnumeric(fields!averageresolutiontime_busdays.value)=1, fields!ticketcountbypriority.value, 0))
for support board value displayed #error
total value nan
.
i believe problem string values in averesoltime not being converted when numbers , when value 'n/a' throws error. how convert strings decimals can , set value 0 when value 'n/a'?
i corrected 1 issue if of values numeric, weighted average computed. removed `=1'
=sum(fields!ticketcountbypriority.value * iif(isnumeric(fields!averageresolutiontime_busdays.value), cdec(fields!averageresolutiontime_busdays.value), 0))/sum(iif(isnumeric(fields!averageresolutiontime_busdays.value), fields!ticketcountbypriority.value, 0))
if value n/a
, 0 value not used in calculation , still getting #error
in result.
update got weighted average calculate using code:
=iif(isnumeric(fields!averageresolutiontime_busdays.value), sum(fields!ticketcountbypriority.value * cdec(iif(isnumeric(fields!averageresolutiontime_busdays.value), fields!averageresolutiontime_busdays.value, 0)))/sum(iif(isnumeric(fields!averageresolutiontime_busdays.value), fields!ticketcountbypriority.value, 0)), 0)
i had put calculation within if statement. still have take care of case of values 'n/a' , @alan states, there divide 0 error.
the second part of expression says if fields!averageresolutiontime_busdays.value not number, divide zero. might easier if expression working instances numeric , wrap in if numeric test. can't test @ moment . iif(isnumeric(fields!averageresolutiontime_busdays.value), yourworkingexpressionhere, 0). replace final 0 'nothing' (no quotes) if want show blank instead of zero
Comments
Post a Comment