Introduction
This article describes how to append the maximum base size to a table's name in the Report tree.
Method
1. Select your table.
2. Go to Automate > Open QScript (Macro) Editor.
3. Paste the below into the editor:
includeWeb('QScript Table Functions');
var tables = [];
var hidden_char = "\u200b ";recursiveGetAllTablesInGroup
(project.report, tables); // get all tables
for (var j = 0; j < tables.length; j++) { // for each table
var stats = getStatisticsFromTable(tables[j], ["Base n"]) // get all 'Base n' statistics for table
var base = [].concat.apply([], stats["Base n"]); // collapse statistics array
var max = Math.max.apply(null, base); // find max 'Base n'
var table_name = tables[j].name.split(hidden_char)[0]; // retain original table name
tables[j].name = table_name + hidden_char + "(Base=" + max + ")"; // append base size to table name
}
In this code:
- We use the
recursiveGetAllTablesInGroup
function to return all tables in the report astables
. - We then loop through every item in
tables
:- The
getStatisticsFromTable
function returns all the Base n values. - The
concat.apply
method collapses thestats
array into a simpler form. - The
Math.max.apply
method finds the maximum Base n. - The
split
function ensures the original table name is kept by referencing a hidden character which is added on the next line. - We then append a hidden character to the table name and add the base size. This allows us to re-run the code without re-appending the base size multiple times.
- The
4. Press the Play button.
Next
How to Automatically Change Table Names in a Report
See Also
How to Create a Custom QScript