Joe Resler
Joe Resler

Reputation: 101

Avoid divide by zero in SSRS expression

I am working on a report that is attempting to find a percentage. Initially my code would look like:

= (Fields!Margin.Value) / (Fields!TotalSales.Value) * 100

However the problem is that in some scenarios TotalSales = 0.00 so this is giving me the error. I am not proficient in VBS. How do I do a NULLIF type function to avoid this?

Upvotes: 0

Views: 5710

Answers (1)

Ross Bush
Ross Bush

Reputation: 15155

This should work for null and 0.

=IIF(Fields!TotalSales.Value <> 0 , (Fields!Margin.Value) / (Fields!TotalSales.Value) * 100 , 0)

Upvotes: 2

Related Questions