Solved

divide by zero error

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now