Solved

divide by zero error

Posted on 2010-11-18
5
324 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
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 51

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 167 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 333 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 333 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Index and Stats Management-Specific tables 8 22
SQL Syntax Grouping Sum question 7 27
SQL Availablity Groups List 2 8
xml files 7 29
I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

829 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