August 22, 2006, 10:56 AM
.erichelp computing totals
I was trying to get some help computing an average in the totals line (without using RECAP) for my report. I am currently using:
ON TABLE RECOMPUTE AVE. FIELDNAME.
But I need the average to only compare values where it does not equal zero. So if the 5 row values are 0 1 1 1 1 the average should be 1 not .8 .
If this is possible any help would be great, thanks.
August 22, 2006, 04:10 PM
smithsEric,
I think this might be the idea you are looking for:
DEFINE FILE CAR
CNT/I4 = IF SALES EQ 0 THEN 0 ELSE SEATS;
END
TABLE FILE CAR
PRINT
COUNTRY
CAR
MODEL
SALES
SEATS
COMPUTE SOMEAVG/I5 = IF CNT EQ 0 THEN 0 ELSE SALES/CNT;
WHERE COUNTRY EQ 'ITALY'
ON TABLE RECOMPUTE AND SUB-TOTAL
END
Regards,
Sean
August 22, 2006, 05:08 PM
.ericI may have said it wrong, but I need column totals for that specific row. The results of the code you posted are (with sales showing an average in the column total instead of summed totals):
COUNTRY CAR MODEL SALES SEATS SOMEAVG
ITALY ALFA ROMEO 2000 4 DOOR BERLINA 4800 4 1200
ITALY ALFA ROMEO 2000 GT VELOCE 12400 2 6200
ITALY ALFA ROMEO 2000 SPIDER VELOCE 13000 2 6500
ITALY MASERATI DORA 2 DOOR 0 2 0
TOTAL 7550 10 3775
Where 7550 is ther average sales of 4800,12400,13000,0. I need that number to say 10066 which is the average of 4800,12400,13000.
August 22, 2006, 05:13 PM
smithsThen just simplify it to this...
DEFINE FILE CAR
CNT/I4 = IF SALES EQ 0 THEN 0 ELSE 1;
END
TABLE FILE CAR
PRINT
COUNTRY
CAR
MODEL
SALES
COMPUTE SOMEAVG/I5 = IF CNT EQ 0 THEN 0 ELSE SALES/CNT;
WHERE COUNTRY EQ 'ITALY'
ON TABLE RECOMPUTE AND SUB-TOTAL
END
August 24, 2006, 09:36 AM
.ericIt worked, I would never have thought of that ... Thanks smiths!