Calc
Performs a calculation on either a frame or the table items inside the frame.
Parameters
Name | Default | Meaning |
---|---|---|
name | The name of the final attribute/column | |
value | The value to be written. Substitutable. | |
where | A condition that must be met for the calculation to happen. | |
else | The value to set if the where condition is not true. If blank, no value is set. | |
target | frame to force the calculation to run on frame values instead of table columns |
Description
This function performs a calculation on a frame, or - if the frame contains a table - the individual items within the table.
This will normally be applied to every column/frame, unless a where condition is specified. If a 'where' condition exists, the calculation will only happen on frames and columns that match the condition.
Example
If the frame contains the following attributes…
Attribute | Value |
---|---|
Width | 100 |
Height | 100 |
{ "type": "calc", "name": "Area", "value": "{Width} * {Height}" }
The final results will include the Area attribute with a value of 10,000. If 'Width' and 'Height' were in the table instead, a new column called 'Area' would be added.
Target
Calculations can happen in two places - in the rows of the table or in the data in the frame.
By default, the calculation will run on rows of the table if the frame contains a table. You can force it to perform a calc on the frame data by setting the target parameter to 'frame'.
Where, Else & Empty Values
Note that if you are using the where condition, values aren't written to the frame/table rows unless…
1) The condition is true, 2) The condition is false and column is empty (a blank value is added to the column), 3) The condition is false and else has been set, in which case the 'else' value is written.
This means that the calc function will create empty values, but not replace existing values.