Often when working with Grid Fields, there is a need to add multiple expressions that are all of the same format for either a Data Set or a Sub Field.
For example, if we are storing financial data per month then we could be tracking the target revenue and actual revenue and want to use expressions to then calculate the variance between these two values for each month.
Using this example, we can create a Grid Field with:
Data Sets (Label - Identifier): Jan - M01, Feb - M02, .., Dec - M12
Sub Fields (Label - Identifier): Target - TargetRevenue, Actual - ActualRevenue, Variance - VarianceRevenue
What we would like to be able to do is to say that the Variance in Revenue is 'Actual - Target' but we don't want to have to write the expression for each Grid Cell.
To do this we make use of the Add Expression Template option in the Utilities bar at the bottom of the Grid Field Edit screen
Then we can build an expression structure and use the keywords {{DataSet}} or {{SubField}} in order to dynamically reference the relevant Identifiers of the Data Sets an Sub Fields within the Grid.
In this case we would select that we are adding the Expression Template for a Sub Field, then which Sub Field the Expression is for and dynamically reference the Data Set in order to populate the Variance Expression for all Months for the Variance Sub Field
The expression template will be in the Form:
[Financials_{{DataSet}}_ActualRevenue] - [Financials_{{DataSet}}_TargetRevenue]
This will then populate the Expressions for the Variance Sub Field.
All we have to do then is save the Grid Field and this will have set the expression for Revenue Variance in our Grid Field.
Tips: It may be that you have multiple Grid Fields in an App such as a highly detailed Grid Field for full financial data tracking as well as a summary Grid Field taking key Financial metrics. By using a consistent naming convention such as always using M01 format for months, this will then enable you to use expression templates to reference Grid Field cells outside of the immediate Grid that you are adding the expressions to.
e.g. If I have one Grid Field to track Budget and one Grid Field to track Cost then by having the Data Sets in the format MXX, I could use an expression template in the form:
[Budget_{{DataSet}}_Actual] - [Cost_{{DataSet}}_Actual]
Make sure to click the 'Save' button when making any changes in order for them to be added to the next app version. Once you have made all the changes you need to an application you are then ready to publish it to workspace.
Note on Field Dependencies - Read more here
Field dependencies are by definition the other field(s) that are reliant on a given field, usually dependent fields are interlinked to one another by expressions and are indicated by an atom symbol. They are a crucial tool when looking to delete Fields within an App or, when it comes to understanding the structure and data flows of an App.
Comments
0 comments
Article is closed for comments.