Focal Point
Distinct Count in a subhead

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/6801038331

February 02, 2005, 02:58 PM
RB
Distinct Count in a subhead
Hi,
I would like to display the distinct count of a field in subheading. Does any one has ideas on how to do this?

Thanks.
February 02, 2005, 03:33 PM
j.gross
CNT.DST.itemkey, as a verb object, gives the count. Not sure you can imbed such a construct in a header/footer, as " <CNT.DST.itemkey " If not, substitute a COMPUTEDd field, like so:

TABLE ...
SUM CNT.DST.itemkey NOPRINT
COMPUTE distinct/I5C= CNT.DST.itemkey; NOPRINT
BY XXX
BY YYY
BY ZZZ
ON XXX SUBHEAD
"... <distinct ..."
END
February 02, 2005, 03:38 PM
Leah
The DST operator is picky in the sense that is only on SUM or WRITE verbs and it must be at the lowest level on the aggregation chain.
So this works

SET STYLEMODE= FIXED
TABLE FILE CAR
SUM CNT.DST.MODEL
BY COUNTRY
END

but this doesn't
SET STYLEMODE= FIXED
TABLE FILE CAR
SUM CNT.DST.MODEL
PRINT COUNTRY MODEL
BY COUNTRY
END

0 ERROR AT OR NEAR LINE 28 IN PROCEDURE _ADHOCRQFOCEXEC *
(FOC1867) DST OPERATOR MUST BE AT THE LOWEST LEVEL OF AGGREGATION


So for unique counts you may want to create a unique counter field and ensure the file is in the order wanted when creating.

This works
SET STYLEMODE= FIXED
TABLE FILE CAR
PRINT COUNTRY MODEL
COMPUTE CNTR/I4 = IF MODEL EQ LAST MODEL THEN 0 ELSE IF COUNTRY NE LAST COUNTRY
THEN 1 ELSE 1;
BY COUNTRY NOPRINT
BY MODEL NOPRINT
ON TABLE HOLD AS HOLD1
END
TABLE FILE HOLD1
SUM CNTR NOPRINT
BY COUNTRY
PRINT MODEL
BY COUNTRY
ON COUNTRY SUBHEAD
" "
"UNIQUE MODELS ARE <CNTR"
" "
END

Of course the car file doesn't have a lot of models and you may not want to use a hold file.
A define would work if the input file is in the order wanted.
February 02, 2005, 05:50 PM
<WFUser>
The simplest way that I can see to put the number of unique instances in a subhead of a sort is to get that count and then join to it as follows:

TABLE FILE CAR
SUM CNT.DST.MODEL AS DSTMODS
BY COUNTRY
ON TABLE HOLD AS DSTMODS FORMAT FOCUS INDEX COUNTRY
END
JOIN COUNTRY IN CAR TO COUNTRY IN DSTMODS AS J1
TABLE FILE CAR
PRINT BODY MODEL CAR
BY COUNTRY
ON COUNTRY SUBHEAD
"<COUNTRY HAS <DSTMODS MODELS"
END
February 02, 2005, 07:15 PM
RB
Both solutions are great. Thank you very much guys!