?
Solved

divide by zero error

Posted on 2010-11-18
5
Medium Priority
?
337 Views
Last Modified: 2012-05-10
I have a report where I calculate cost as a percent to sales on a monthly basis. Sometimes(like this month) I have cost but the revenue figures have not been submitted yet so I get a #error. What can I do so it says 0 or nothing?
=sum(
	iif(
		Fields!Entry_type.Value = "Transcost",
								             Fields!ID11.Value,
								             nothing))
/
sum(
	iif(
		Fields!Entry_type.Value = "Sales",
										 Fields!ID11.Value,
										 nothing))

Open in new window

0
Comment
Question by:k1ng87
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34170031
I am not sure about Reporting.

From SQL Query you can manage this error.

For eg: for this calculation - marks / years
eg: CASE WHEN ISNULL(years, 0) = 0 THEN 0 ELSE ISNULL(marks, 0) / ISNULL(years, 0) END

Raj
0
 
LVL 58

Expert Comment

by:HainKurt
ID: 34170050
try this:

= iif(sum(iif(Fields!Entry_type.Value = "Sales", Fields!ID11.Value, 0))=0, nothing,
sum(iif(Fields!Entry_type.Value = "Transcost", Fields!ID11.Value, 0)) / sum(iif(Fields!Entry_type.Value = "Sales", Fields!ID11.Value, 0))
)
 
0
 
LVL 14

Accepted Solution

by:
leoahmad earned 668 total points
ID: 34170060

=iif(Fields!Entry_type.Value =0,nothing,sum(iif(Fields!Entry_type.Value = "Transcost",Fields!ID11.Value,nothing))
/
sum(iif(Fields!Entry_type.Value = "Sales",Fields!ID11.Value,nothing)))

Open in new window

0
 
LVL 27

Assisted Solution

by:planocz
planocz earned 1332 total points
ID: 34178451
Hers a sample for you just change the Field names.
Fix  DIV BY ZERO
=IIF(CInt(Fields!Conversion.Value)=0,  Fields!PostQuantity.Value,Fields!PostQuantity.Value/IIF(CInt(Fields!Conversion.Value)=0,1,Fields!Conversion.Value))
0
 
LVL 27

Assisted Solution

by:planocz
planocz earned 1332 total points
ID: 34178456
If you want to use the Code tab window, then you could use this sample....
Public Function SafeDivide(Numerator as Double, Denominator as Double) as Double
 If Denominator = 0 then return 0
 Return (Numerator / Denominator)
End Function
=Code.SafeDivide(1,2)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

765 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