Out of the box, Reporting services does not handle divide by zero conditions gracefully.
There are plenty of posting on how to use the IIF() function to accomplish this, with some rather horrific looking code.
In order to simplify the coding process and make the resulting expressions readable by a mere mortal, I wrote the following function that can be included in any report.
1. From the menu, choose Report, Report Properties.
2. Click on the Code tab and past the function code into the window.
3. Click on OK
To use the function, you have to reference the code collection in an expression:
=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, Nothing)
Or if you want a zero instead of a blank:
=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, 0)
You recently published a script showing how to do pagination (e.g. results 20 - 30 of 100) It's also possible to do it quicker and more elegantly without having to resort to building the sql string dynamically (never a good thing IMHO). You pass in 2 parameters, @PageIndex is the first record you want (so […]