This article describes how to reference table parameters within a Rule such as the data set variables and variable sets that appear in the rows and columns of the table.
- A table with a Rule applied.
- You have read How to Create a Custom Rule.
Referencing variables in a table
Following the naming conventions of Displayr’s sister product, Q, row variable sets are referred to as blue questions and column variable sets are referred to as brown questions due to the input colors in Q’s interface.
In this example, the following would return the names of the input variable sets in our table:
table.blue // 'Row' variable set
table.brown // 'Column' variable set
Note, if the table is not a crosstab then the latter will return RAW DATA or SUMMARY according to the table setup.
We can also access details about these variable sets by using
brownQuestion to find out their Structure, for example:
Note, in Displayr we use
variableSetStructure instead of Q's
Calculating temporary tables
There are times when you may wish to pull values from a different table with the same dimensions or a modified version of your table that has been filtered or weighted differently. The way this works in Displayr is you need to calculate a temporary table in order to access these values, as a Rule can’t reference another table in your document. Note, this approach could lead to slow-running tables, especially when used on a large table, a large data set, or both, so care needs to be exercised.
Displayr allows you to do this using the
calculateTable function which references variables by name (found under Properties > GENERAL > Name):
calculateTable(ROWS, COLUMNS, filter, weight)
To create a table using the same original input variables and filters but with a weight variable applied (called weighting), you would do the following:
var tab = calculateTable(table.blue, table.brown,['!UseQFilters'], weighting);
To create a table using the same original input variables but with a different filter applied (called target segment):
var tab = calculateTable(table.blue, table.brown, "target segment", null);
To create a table using different input variables and no filters or weight:
var tab = calculateTable("Q1b - Awareness", "Q3 - Preferred cola", null, null);
As with obtaining the statistics from the current table, here we could likewise pull the % statistic from our temporary table called
tab like so:
var vals = tab.get("%");