# Modifying Tables or Plots - Show Maximum Column n In Statistics Below

This rule modifies the Column n shown in the Statistics - Below so that it always shows the largest value of Column n from each column (i.e., the highest sample size). Ordinarily, the value of Column n is determined from the NET row, and so can be smaller than expected when some cases have Missing Data. This Rule is one method for addressing situations where the Column n Is Too Small.

## Example

In the table on the left the Column n varies within each column due to the pattern of Missing Data, and the value of Column n shown at the bottom of the table is the number of respondents that have complete data for all the rows. The table on the right shows the result from applying this Rule - the value of the Column n has been replaced with the largest value within each column.

## Technical details

Changing the Column n that is shown has no effect on the calculation of other statistics in the table.

## How to apply this rule

### For the first time in a project

- Select the table(s)/chart(s) that you wish to apply the rule to.
- Start typing the name of the Rule into the
**Search features and data**box in the top right of the Q window. - Click on the Rule when it appears in the
**QScripts and Rules**section of the search results.

*OR*

- Select
**Automate > Browse Online Library**. - Choose this rule from the list.

### Additional applications of the rule

- Select a table or chart that has the rule
*and*any table(s)/chart(s) that you wish to apply the rule to. - Click on the
**Rules**tab (bottom-left of the table/chart). - Select the rule that you wish to apply.
- Click on the
**Apply**drop-down and choose your desired option. - Check
**New items**to have it automatically applied to new items that you create. Use**Edit > Project Options > Save as Template**to create a new project template that automatically uses this rule.

## Removing the rule

- Select the table(s)/chart(s) that you wish to remove the rule from.
- Press the
**Rules**tab (bottom-right corner). - Press
**Apply**next to the rule you wish to remove and choose the appropriate option.

## How to modify the rule

- Click on the
**Rules**tab (bottom-left of the table/chart). - Select the rule that you wish to modify.
- Click
**Edit Rule**and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).

## JavaScript

```
form.setSummary("Show Maximum Column n In Statistics Below");
// Checking to see where column n is available
if (!belowTableExists())
form.ruleNotApplicable("this rule only works on tables with Statistics - Below available")
if (table.availableStatistics.indexOf('Column n') == -1)
form.ruleNotApplicable("this rule only works on tables with Column n in Statistics - Cells");
if (below_table.availableStatistics.indexOf('Column n') == -1)
form.ruleNotApplicable("this rule only works on tables with Column n in Statistics - Below");
var n_rows = table.numberRows;
var n_columns = table.numberColumns;
var cell_stats = table.get('Column n')
var below_stats = below_table.get('Column n')
var below_is_transposed = below_stats.length > 1;
for (var c = 0; c < n_columns; c++){
var new_column_n = 0;
for (var r = 0; r < n_rows; r++) {
var cell_column_n = cell_stats[r][c];
if (!isNaN(cell_column_n) && cell_column_n > new_column_n)
new_column_n = cell_column_n;
}
if (below_is_transposed)
below_stats[c][0] = new_column_n;
else
below_stats[0][c] = new_column_n;
}
below_table.set('Column n', below_stats);
// Returns true if Statistics - Below are available for this table.
function belowTableExists() {
var exists = true;
try {
below_table.statistics;
} catch (e) {
exists = false;
}
return exists;
}
```

## See also

- User Input for Rules for technical information on Rules.
- Rule Online Library for other examples of Rules.
- Table JavaScript and Plot JavaScript for the JavaScript that is used to write custom rules.
- JavaScript for information about the JavaScript programming language.

Pages with syntax highlighting errors

Q Technical Reference

Q Technical Reference

Q Technical Reference > Creating And Modifying Tables

Q Technical Reference > Setting Up Data > Creating New Variables

Q Technical Reference > Updating and Automation > Automation Online Library

Q Technical Reference > Updating and Automation > JavaScript > Table JavaScript and Plot JavaScript

Rule Online Library