asTable
Converts the output of a script to a table region.
When you have a script that returns a table region and you call it in another script (e.g. Main), the return value is an HTML string representing the table region. Although the HTML string looks like a table region when you preview, other functions won't recognize it as a table region until you convert the HTML string to a table object.
Important
FUNCTION DEPRECATED
If you want a script to return a table object (not an HTML string), the better option is to make the script a #value script. See Deprecation of asTable for further guidance.
Parameters
SCRIPT (script)
The script whose output you wish to convert.
Example
Assume a "Describe the Table" project with this data:
ID | Region | Branch | Sales | |
---|---|---|---|---|
Row 1 | 1001 | South | Atlanta | 357589.32 |
Row 2 | 1002 | Northeast | Boston | 294293.49 |
Row 3 | 1003 | Midwest | Chicago | 403603.17 |
Row 4 | 1004 | South | Dallas | 324722.58 |
Row 5 | 1005 | South | Houston | 306555.26 |
Row 6 | 1006 | West | Los Angeles | 457359.45 |
Row 7 | 1007 | Midwest | Milwaukee | 192238.52 |
Row 8 | 1008 | Northeast | New York | 468745.37 |
Suppose you create a script called SouthBranches with this ATL:
[[filterRows(WholeTable, 'Region', eq('South'))]]
When you preview the SouthBranches script, you see this table region:
ID | Region | Branch | Sales | |
---|---|---|---|---|
Row 1 | 1001 | South | Atlanta | 357589.32 |
Row 4 | 1004 | South | Dallas | 324722.58 |
Row 5 | 1005 | South | Houston | 306555.26 |
Though the preview shows a table, the script's return value is actually a string of HTML. Therefore, any attempt to call the script when using a function that requires a table region returns an error. For example:
In the South, total sales were $[[totalVal(columnsInRegion(SouthBranches,'Sales'))]].
This returns an error because the first parameter for columnsInRegion requires a table region but the input (SouthBranches
) returns a HTML string. To fix this, convert SouthBranches
using asTable
.
In the South, total sales were $[[totalVal(columnsInRegion(asTable(SouthBranches),'Sales'))]].
The output text is:
In the South, total sales were $988,867.16.
Deprecation of asTable
The asTable
function was created before we introduced #value scripts in Studio 3.2.0.
When you use a #value script to get a table region, no conversion with asTable
is necessary. For this reason, we have deprecated the function, meaning it's no longer supported in the Function Builder.
Here's how to write the SouthBranches script as a #value script:
#value SouthBranches() [[filterRows(WholeTable, 'Region', eq('South'))]]
And here's how you'd call it in another script:
In the South, total sales were $[[totalVal(columnsInRegion(SouthBranches(),'Sales'))]].
In this case, the SouthBranches script is function that takes zero parameters.