Modifying Footers - Display Which Columns Are Being Compared

From Q
Jump to: navigation, search

This rule adds a description of the sets of columns that are being compared by the Column Comparisons to the footer of 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.


  • 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).


// Report the sets of column comparisons in the footer
includeWeb("JavaScript Array Functions");
form.setSummary("Modifying Footers - Display Which Columns Are Being Compared");
if (table.availableStatistics.indexOf("Column Comparisons") == -1)
    form.ruleNotApplicable("column comparisons are not available on this table");
var column_names = table.get("Column Names");
var columns_compared = table.get("Columns Compared");
// Get list of spans. If there are no spans
// then make one big pseudo span. Any indices
// out side of spans are also included in a psuedo span
var spans = table.columnSpans;
if (spans.length == 0)
    spans = [{ indices: table.columnIndices(true), label: "" }];
else {
    var indices_included = [];
    var indices_not_in_spans = [];
    spans.forEach(function (span_obj) { indices_included = indices_included.concat(span_obj.indices) });
    for (var j = 0; j < table.numberColumns; j++) {
        if (indices_included.indexOf(j) == -1)
    if (indices_not_in_spans.length > 1)
        spans.push({ indices: indices_not_in_spans, label: "Not in span" });
// Get text for all spans
var comparison_text =;
// Add to footer
var footers = table.extraFooters;
footers.push("Comparisons: " + comparison_text.join(", "));
table.extraFooters = footers;
// Generate the part of the footer that describes the comparisons
// in the specified span.
function generateComparisonText(span_obj) {
    // For each column, add the column name to the column comparisons, eg "A" + "BC" = "ABC"
    // Sort the string lexicographically (this helps eliminate duplicates later) and
    // separate the letters by "/". eg "A" + "CB" -> "ACB" -> "ABC" -> "A/B/C";
    var comparison_strings = (index) {
        return (column_names[0][index] + columns_compared[0][index]).split("").sort().join("/");
    // Remove any comparisons which are just one letter
    comparison_strings = comparison_strings.filter(function (s) { return s.length > 1; });
    // Remove duplicates
    comparison_strings = uniqueElementsInArray(comparison_strings);
    // If the span label is not empty then combine the span label with the set of comparisons,
    // otherwise just list the comparisons.
    return (span_obj.label == "" ? "" : span_obj.label + ": ") + comparison_strings.join(", ");

See also

Personal tools