Get Counts uses the $_counter
and get
Perl methods to return the current number of respondent records for a given question (or variable) option.
set list: DRINKS
1. Coke
2. Pepsi
3. RC
4. A&W
5. Sprite
6. Cactus Cooler
7. 7-Up
1. Which soda is your favorite?
type: radio
optsfrom: DRINKS
show text: INTRO
text: Thank you for your participation so far.
1C3. Count for RC cola
type: number
invisible: y
datatype: whole
cvalue: $_counter->get(field_id => 'Q1', option_id => 3)
In this example, the cvalue
in Q1C3 calculates the number of Completed respondents (the default) who selected 'RC' (option 3) in Q1.
Note: Get Counts should only be employed when all other possible solutions have been exhausted. Programmers might consider instead using the quotaOpen
function ("quota look ahead"), which examines how full upcoming quota buckets are, rather than the current number of Completes.
Details
- Get Counts is useful when standard
selectby
or quota methodology is not quite capable of meeting the needs of the survey designer. Use cases often involve logical statements which require counting the number of complete records fulfilling a given condition. - The parameters for
get
should be enclosed in parentheses, with each parameter being followed by a '=>' and its input — e.g.,$_counter->get(field_id => 'QX', option_id => 3, filter_condition => {QCOUNTRY => $QCOUNTRY})
. - The
field_id
parameter is required to use Get Counts so that it knows which question to reference. - If no
option_id
is specified, Get Counts returns a hash reference, allowing multiple option IDs to be used for calculations. - The variable checking the counts (Q1C3 above) and the variable it is checking (Q1 above) must be on separate survey pages.
Parameters
Parameter | Description | Example syntax |
field_id |
Required; specifies the question or variable ID that Get Counts will examine. Surround the ID in single quotes. | field_id => 'Q1' |
option_id |
Optional; specifies the question or variable's option ID that Get Counts will examine. For non-numeric or string option IDs, include single quotes (e.g., '5A'). If not included, Get Counts will return a hash reference. |
|
filter_condition |
Optional; specifies any additional conditions to place on counted records. |
(only include records who punched '99' at Q1 in the count) |
Additional examples
Counting all responses
While the default behavior of Get Counts is to count only Completed respondents, by adding base_filter_id => 1
as shown below, it can be set to count all responses instead.
set list: DRINKS
1. Coke
2. Pepsi
3. RC
4. A&W
5. Sprite
6. Cactus Cooler
7. 7-Up
1. Which soda is your favorite?
type: radio
optsfrom: DRINKS
show text: INTRO
text: Thank you for your participation so far.
1C3. Count for RC cola
type: number
invisible: y
datatype: whole
cvalue: $_counter->get(field_id => 'Q1', option_id => 3, base_filter_id => 1)
Although already the default, adding base_filter_id => 2
will also result in only Completes being counted.
Comments
0 comments
Please sign in to leave a comment.