June 18, 2012

SSRS Division Helper App. Avoid errors in division result. (SQL Server Reporting Services)

A quite common issue in SSRS is getting properly displayed values when dividing 2 numbers. When the denominator is equal to 0 or NULL you get an ugly looking error or “Infinity” in the field. Not really what the customer would like to see.
A well known solution is when dividing A / B to do something like this:
= IIF(  IsNothing( B )
        OR B = 0,
        0,
        A
        /
        IIF( IsNothing( B )
            OR B = 0,
            1,
            B
        )
)

Writing this each and every time gets a little annoying. With the not so good code editor in BIDS when we have complex expressions instead of “A” and “B” it can actually be very frustrating and unnecessarily time consuming.
Having to do this over and over again I made a small and very simple tool I would like to share.
image
All you need to do is put the required values in the top and bottom. Click [Generate] and copy the result.
It saves some time and I hope someone finds it useful.
Download from here.
Source (VS 2010)