'Division by zero' Error (1 Viewer)

The Odyssey

Registered User.
Local time
Today, 02:27
Joined
Jan 15, 2015
Messages
34
I have a single expression that seems to be causing this error. At it's current state this is what it looks like:

Code:
IIf([Year_Total_T]=0,0,Sum(([Year_Total_A]-[Year_Total_T])/([Year_Total_T])))

This isn't the first time I have gotten this error. I initially had this expression:

Code:
Sum([Quarter3_A])/Sum([Quarter3_T]))

This gave me the same error. So after searching online fixed the error using 'IIf':

Code:
IIf([Quarter3_T]=0,Null,Sum([Quarter3_A])/Sum([Quarter3_T]))

As you can see I am using the exact same method here as I am in my other expression, so why is this different and how can I fix the code?

Thanks
 

spikepl

Eledittingent Beliped
Local time
Today, 11:27
Joined
Nov 3, 2010
Messages
6,142
What is the data type of year_total_t? It needs to be Currency or Long, or else you might get stuff like you are getting.
 

spikepl

Eledittingent Beliped
Local time
Today, 11:27
Joined
Nov 3, 2010
Messages
6,142
Err .. so you have records with various Year_total_T that you sum? You then need to sum an IIF and not IIF a Sum or else you get what you got :D
 

The Odyssey

Registered User.
Local time
Today, 02:27
Joined
Jan 15, 2015
Messages
34
The data type is currency.

What do you suggest the expression should look like?
 

spikepl

Eledittingent Beliped
Local time
Today, 11:27
Joined
Nov 3, 2010
Messages
6,142
You got a hint - take a crack at it, or wait for someone else to do it for you.
 

The Odyssey

Registered User.
Local time
Today, 02:27
Joined
Jan 15, 2015
Messages
34
Just to report back, I managed to get rid of the error by moving the sum prior to the 'IIf'. This however gave me completely incorrect results.

I decided to scrap the 'IIf' and moved the expression from the query and just put it in the textbox. This defaults divided by zero results to "#Div/0"" which is nice to now know.
 

GinaWhipp

AWF VIP
Local time
Today, 05:27
Joined
Jun 21, 2011
Messages
5,899
Hmm, you might also have a look at the Nz() Function.
 

Users who are viewing this thread

Top Bottom