Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zero Value

Status
Not open for further replies.

old123

MIS
Jun 1, 2005
31
US
Iam posting another problem with the same report Iam working.

I have calculated avg mean distance from the fleet however now I have noticed that quite significant data returns value 0 . i don't want to include the data in average calculation which has 0 value.

I tried suppress feature & other stuff but did'nt work.

Ver 9
Database AS400

Output is

Bus No WO Date Mileage Differnce

PB9717 xxx xxxxx 156157 0
156502 345
156502 0
164164 7662
170909 6745
172168 1259
172168 0
172618 0
172510 342

Summary Count xx Avg xxx


For Calculating Average

whileprintingrecords;
numbervar summiles;
numbervar counter;
numbervar grtotmiles :=grtotmiles + summiles;
numbervar grtotcnter :=grtotcnter + counter;
if counter > 0 then summiles/counter else 0

Sum is accumulated in this formula

whileprintingrecords;
numbervar summiles;
numbervar counter;
if({FM_300L2.FMASET})= previous({FM_300L2.FMASET})then
(
summiles:=summiles +{@DIFFERNCE};
counter:=counter +1;
)

Differnce is calculated

IF {FM_300L2.FMASET} = PREVIOUS({FM_300L2.FMASET}) THEN
(
if {FM_300L2.FMPMR} >= PREVIOUS({FM_300L2.FMPMR}) then
{FM_300L2.FMPMR}- PREVIOUS({FM_300L2.FMPMR}) else
{FM_300L2.FMPMR}
)
ELSE
0
 
I think a conditional would work:

whileprintingrecords;
numbervar summiles;
numbervar counter;
numbervar grtotmiles;
numbervar grtotcnter;
if summiles > 0 then
grtotmiles:=grtotmiles + summiles;
grtotcnter:=grtotcnter + counter;
if counter > 0 then
summiles/counter
else
0

I may not have nailed the right thing to key off of, but verifying that it isn't a zero just prior to including it is the key.

-k
 
nope , i did'nt work. adding the miles does'nt hurt however putting that record as a counter effects the average.

Like in my example. Counter is 9 It should be 5 to get more in average.
 
As I posted, I didn't really analyze it closely, but you need to disregard those rows:

whileprintingrecords;
numbervar summiles;
numbervar counter;
numbervar grtotmiles;
numbervar grtotcnter;
if summiles > 0 then
grtotmiles:=grtotmiles + summiles;
if counter > 0 then
grtotcnter:=grtotcnter + counter;
if counter > 0 then
summiles/counter
else
0

-k
 
With this formula the results does'nt change. It's still adding the rows with zero
 
Hmmm:

whileprintingrecords;
numbervar summiles;
numbervar counter;
if({FM_300L2.FMASET})= previous({FM_300L2.FMASET})then
(
if {@DIFFERNCE} > 0 then
summiles:=summiles +{@DIFFERNCE};
if {@DIFFERNCE} > 0 then
counter:=counter +1;
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top