Solved

SSRS Divide By Null #Error

Posted on 2011-09-23
6
698 Views
Last Modified: 2012-05-12
I have the following expression in a report and thought the IsNothing would take care of null fields when dividing but it is not. I continue to get #Error for fields where Sum(Fields!SalesComp.Value)) have no value.

=IIF(IsNothing(Sum(Fields!SalesComp.Value)),0,
(Sum(Fields!Sales.Value)-Sum(Fields!SalesComp.Value))
/Sum(Fields!SalesComp.Value))
0
Comment
Question by:dk04
6 Comments
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 36591172
Need to check Isnothing before Sum.

as like

=IIF (Isnothing(Fields!SalesComp.Value),0,Fields!SalesComp.Value)
0
 
LVL 22

Expert Comment

by:Thomasian
ID: 36591242
Are you sure that you have a null value for the sum and not 0?

Try if this works
=IIF(ABS(Sum(Fields!SalesComp.Value))>0
,(Sum(Fields!Sales.Value)-Sum(Fields!SalesComp.Value))/Sum(Fields!SalesComp.Value)
,0)

Open in new window

0
 
LVL 25

Expert Comment

by:TempDBA
ID: 36592117
this is the error thrown because while summing the value, the sum function is throwing the error. The best part will be checking the data value of each row and considering it as 0 if no value is returned. You can do how PatelAlpesh\Thomasian has suggested above. You can also consider the backend to give the value of the field as 0 if the value is nothing i.e. while fetching data in the query\stored procedure itself.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:dk04
ID: 36593058
PatelAlpesh  Does not give me the else statement I need.

Thamasian the expression did not work. I still received the #error

The =IIF (Isnothing(SUM(Fields!SalesComp.Value)),0, does work provided I use a different else statement than what I need. For example, =IIF (Isnothing(SUM(Fields!SalesComp.Value)),0,
Fields!SalesComp.Value) works but the else statement is not what I need. I need ,(Sum(Fields!Sales.Value)-Sum(Fields!SalesComp.Value))/Sum(Fields!SalesComp.Value),0) or some variation to get the comp sales to work for those locations that actually have comp sales.
0
 

Accepted Solution

by:
dk04 earned 0 total points
ID: 36593516
Thanks everyone for replying I ended up working it out two different ways.
=IIf(VAL(Sum(Fields!SalesComp.Value)) > 0,(VAL(Sum(Fields!Sales.Value))-(VAL(Sum(Fields!SalesComp.Value))))
/(VAL(Sum(Fields!SalesComp.Value))),0)

=IIf(Sum(Fields!SalesComp.Value)>0, 
(Sum(Fields!Sales.Value)-Sum(Fields!SalesComp.Value))/
IIF(SUM(Fields!SalesComp.Value)=0,1,SUM(Fields!SalesComp.Value)),0)

Open in new window

0
 

Author Closing Comment

by:dk04
ID: 36890316
The attached code worked and removed the error.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question