Introduction
This article describes how to go from a standard table...
...to a table that hides rows under a specific value:
Method
1. Select your table.
2. Go to Automate > Custom Rule.
3. Paste the below into the dialog:
form.setHeading("Hide rows below specified value");
form.setSummary("Hide rows below specified value");
// Returns true if all elements of the array are below threshold
function arrayElementsBelowMin(array,threshold) {
var non_below = array.filter(function(x) { return x >= threshold; } );
return non_below.length == 0;
}
// Returns true if all elements of the array are NaN
function arrayElementsAllNaN(array) {
var not_nan = array.filter(function(x) { return !isNaN(x); } );
return not_nan.length == 0;
}
// Obtain the primary statistics to check
var primary_statistic = table.availableStatistics[0];
var values = table.get(primary_statistic);
// Check to see if the primary statistic is a % statistic.
var is_percentage = primary_statistic.indexOf('%') != -1;
// Check for rows with minimum threshold
var min_rows = [];
var threshold = 40;
for (var j = 0; j < table.numberRows; j++) {
var current_row_values = values[j];
if ((is_percentage && arrayElementsBelowMin(current_row_values,threshold)) || arrayElementsAllNaN(current_row_values))
min_rows.push(j);
}
// Remove empty rows
if (min_rows.length > 0)
for (var j = min_rows.length - 1; j > -1; j--) {
table.deleteRow(min_rows[j]);
if (typeof right_table !== 'undefined') {
if (right_table.numberRows == 1)
right_table.deleteColumn(min_rows[j]);
else
right_table.deleteRow(min_rows[j]);
}
}
- We first find the primary statistic to use for the condition. The primary statistic is the first statistic on the Statistics - Cells list for the table.
- We build an array of all the values across the columns in each row and check whether they are below the specified threshold.
- Finally, we use the
deleteRow
function to remove any row where this condition is true ordeleteColumn
when dealing with a grid question where the table dimensions are reversed. - Note, as significance testing is conducted prior to the application of the JavaScript, the significance highlighting from the cells in the original table will be shown.
4. OPTIONAL: Change threshold to the desired value. Here, it is set at 40.
5. Press the Play button > Close > OK > OK.
Next
How to Hide and Remove Categories (Missing Values)
Comments
0 comments
Article is closed for comments.