Need to exclude zero values from SSRS SSDT Report calculations in Field expression window

491 views Asked by At

I have Productivity calculation as TotalMinutes/(TotalHours*60) Some of my TotalHours values=0 and I need to exclude them from calculation.

How do I write it in Field Expression window?

My current expression is (I am also setting zeros to "99" values in this field):

=IIf(Fields!TotalHours.Value=0,99,
 Sum(Fields!TotalMinutes.Value/(Fields!TotalHours.Value*60)))

Thank you for help

1

There are 1 answers

0
Alan Schofield On BEST ANSWER

This is untested but should work...

The problem is that IIF will evaluate both expressions even if one is never used so to avoid a divide by zero we need to swap the potential zero for a 1. This won't affect the result as it will never be used as the final output.

=SUM(
IIF(Fields!TotalHours.Value=0,99
    , IIF(Fields!TotalHours.Value=0,0, Fields!TotalMinutes.Value) 
        /  IIF(Fields!TotalHours.Value=0, 1, Fields!TotalHours.Value * 60)
    )
)

So what happens here is that if TotalHours is zero we do a 0/1 in the False part of the outer IIF just to satisfy the IIF statement (it will never actually be used)