[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

divide by zero error

Posted on 2010-11-18
5
Medium Priority
?
342 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 61

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:
Muhammad Ahmad Imran 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

830 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