Solved

divide by zero error

Posted on 2010-11-18
5
331 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 55

Expert Comment

by:Huseyin KAHRAMAN
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

726 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