Tables and axes > Statistical functions and totals > Creating totals
 
Creating totals
Quick reference
To create a total, type:
n04[element_text]
To create a subtotal, type:
n05[element_text]
More information
Totals in Quantum are sums of all rows or columns created by n01, n15, col, val, bit or fld statements. Statements which generate totals are n04 and n05.
Regardless of its position in the axis, the n04 sums all counts from the beginning of the table up to the end of the table, or until another base-creating element is read in the axis, whichever comes first. Therefore you need not put the n04 at the end of the axis if that is not where you want it to go. For example,
col 257;Base;First Row;Second Row;Third Row
n04Total
produces exactly the same total as:
n10Base
n04Total
col 257;First Row;Second Row;Third Row
If the n04 is placed between the top of the table and a base, it provides a total of all counts between the top of the table and that base. Likewise, if it occurs between a base and the bottom of the table, the total is the sum of all counts between the base and the end of the table. If it is between two bases, the n04 totals all counts between the two base rows. If one of the other rows is a subtotal (n05), the n04 will ignore the figures in that row.
There is one thing to beware of. Some tables include net rows which are counts of respondents included in the previous or following groups of rows. If the net is created using an n01;c=+ statement, the total calculated by the n04 include both the individual rows and also the nets of those rows. The n04 is a sum total of counts, just as if you had typed the figures from each row into a calculator. To produce a total which excludes nets, either replace the n04 with an n01 containing an appropriate condition, or create the net using a net statement.
For example:
l try1
n10Base
col 153;Base;hd=Overall Rating;Excellent;Very Good
n01Excellent/Very Good (Net);c=+2
col 153;Good='3';Fair='4';Poor='5';DK/Refused='&'
n04Total
The total for this axis is the sum of the two rows created by the first col statement, plus the n01 row, plus the four rows on the second col statement. To exclude the net row from the total, replace the n04 by an n01, as follows:
l try1
n10Base
col 153;Base;hd=Overall Rating;Excellent;Very Good
n01Excellent/Very Good (Net);c=+2
col 153;Good='3';Fair='4';Poor='5';DK/Refused='&'
n01Total;c=+
The condition c=+ says that anyone who has been included in any of the previous rows should be included in this total row. Each person is counted once only, regardless of the number of rows they appear in.
The n05 creates subtotals starting from the beginning of the table, or the most recent base, or the most recent n05, whichever comes last, and ending with the element immediately before the n05 itself, as illustrated in Figure 19.1.
Note Neither the n04 nor the n05 is affected by n00 statements.
The specification for the table shown below is:
/* Bread buyers have C125'1'
/* Number of loaves bought is in C(132,133)
tab ax04 loaf;c=c125'1'
ttlBase : Respondents Who Bought Bread
l loaf;inc=c(132,133)
n10Base;noinc
val c(132,133);hd=Number of Loaves Purchased Last Month
+i;1-5;6-10;11-20;21-30;31+
l ax04
n10Base
n23Bought from Supermarket
col 130;White;Wholemeal
n05Subtotal
n03
n03Bought from Baker's
col 130;White;Wholemeal
n05Subtotal
n03
n04TOTAL
Base: Respondents Who Bought Bread

                    Number of Loaves Purchased Last Month

               Base     1-5    6-10    11-20    21-30    31+
               ---------------------------------------------

Base           1105     121     319      285     204     129
Bought from Supermarket
White          1436      42     196      429     392     377
Wholemeal      1552      52     123      453     422     502
Subtotal       2988      94     319      882     814     879

Bought from Baker's
White          1934     388     233      294     469     550
Wholemeal      1504     272     287      271     329     345
Subtotal       3438     660     520      565     798     895

TOTAL          6426     754     839     1447    1612    1774
The table base is the number of people buying bread, and the rest of the table shows the number of loaves purchased by those people. The cell with the conditions ‘White’ and ‘11-20’ under the subheading ‘Bought from Supermarket’ indicates that 429 loaves were bought by people who bought white bread in a supermarket and who bought between 11 and 20 loaves of bread last month. The cell is a count of loaves bought rather than of people buying bread because of the inc= on the l statement. This says, whenever a respondent satisfies the condition for a cell, increment that cell by the value in c(132,133) rather than by 1.
Without the inc=, this cell would indicate how many people who bought 11 to 20 loaves last month bought white bread in a supermarket.
See also
Statistical functions and totals