Case count and Subtotals

Jones Allen (Van) allen.jones@artioslink.com
Thu, 16 Apr 1998 14:19:36 -0700


If you are using Quiz, you can do the following:

assuming you are accessing a file that has a field called
"component_id", and there are a varying number of records for each
component:

> define kount int*16 = 1
> sort on component_id
> foot at component_id component_id kount subtotal

[Define a variable (eg: kount) instead of using the predefined
function/item "count" in case you want to send your report to a subfile.
 If you use "count", when you access the subfile, powerhouse won't use
the "count" field in the subfile, but will instead use it's internal,
predefined definition.]

This will give you a report that looks something like:

Component  Kount
1111111               10
2222222                 5
3456789               12

If you want to report all counts in the same row of the report, eg:

1111111: 10    2222222:5   3456789:12

the problem becomes trickier.  In general, you may have more components
to report than will fit into one line, however, if you are willing to
determine ahead of time how many components there may be in one line,
you can do the following.  Here "linelen" holds the number of components
you want to report on one line

> define kount int*16 = 1
> define rec_num int*16 = 1
> sort on component_id
> set subfile at component_id
> report summary component_id kount subtotal &
>                rec_num subtotal at component_id noreset
> go
> access *quizwork
> define linelen int*2 = 2
> define srec float*4 = rec_num / linelen
> define msrec int*8  = mod(rec_num,linelen)
> define skey int*16  = ceiling(rec_num / linelen)
> define cid1 char*10 = component_id if msrec <> 0
> define cno1 int*8   = kount if msrec <> 0
> define cid2 char*10 = component_id if msrec = 0
> define cno2 int*8   = kount if msrec = 0
> sorted on skey
> foot at skey cid1 max cno1 max cid2 max cno2 max
> go

If you have more than 2 components on one line, you will have to change
the "if msrec" conditions because there will be more than one define
where "msrec <> 0".

Hope this helps.

>-----Original Message-----
>From:	powerh-l-owner@lists.swau.edu [SMTP:powerh-l-owner@lists.swau.edu]
>Sent:	Thursday, April 16, 1998 2:13 PM
>To:	Watt Peter (Van); Rohde Dirk (Van); Shaw Ronda (Van); Deppiesse Brian
>(Van); Sanderson Dan (Van); Jones Allen (Van); powerh-l@lists.swau.edu
>Subject:	Case count and Subtotals
>
>Good Afternoon,
>
>        I am currently working on a program that has to count different 
>components.  Do I have to use case, if, else, when or can I define an item
>and 
>increment it by 1 and get a subtotal?   
>
>Sgt Dennis, O.E.
>Marine Corps Institute
>E-mail: Dennis@Dpi@Mci or DennisO@mqg-smtp3.usmc.mil
>Work Phone: (202) 433-2351 ext. 101
>= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
>Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
>powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
>This list is closed, thus to post to the list, you must be a subscriber.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
This list is closed, thus to post to the list, you must be a subscriber.