Show/Hide Toolbars

PerfectApps ® Help Guide

You may use the Footer option to display the Sum or Average of the data in a column. However if you need to have the value set into a field outside the table, which could be adjacent to the table or anywhere else on the app, then it would be necessary to use behaviors.

 

Row calculations can be set up to add all values within a table column together in order to populate the resulting value into a field outside the table. In order to do this, you must set a behavior command to run the calculation and populate the target field. For more information on setting behaviors, see the Adding Behaviors topics.

 

Example

We want to add all values in a column (Total) together to populate a field outside the table (Grand Total).

Performing Column Calculations - Example Image

 

Document Icon

1.With an app loaded in the Layout view of the App Designer, drag and drop a Table object from the Toolbox onto the Layout canvas.

2.On the Table Properties panel under Columns, change the Column Data Type to Numeric Input.

3.On the Table object in the layout canvas, select the Column. You can select a column in one of two ways.

With the Table object selected, in the columns section of the Properties panel, double-click on the header cell of the row that describes the table column you want to select.

In the Table object within the layout canvas, click in the header area of the column. You will need to de-select (click somewhere outside) the table before doing this.

4.On the Properties panel under the Behaviors section, click the Numeric Input Changes Field Data behavior event. PerfectApps launches the Behavior view.

flag_green

The Numeric Input Changes Field Data event will be called whenever data is changed in any of the rows in this column.

 

5.In the Behavior view toolbox under the Objects Commands section, drag and drop a Set Field command onto the behaviors canvas. This behavior will perform the calculation.

6.On the Set Field Properties panel, click Select to choose the target field for the calculation (e.g. Grand Total).

7.In the Value property section, select Formula and click the Compose button.

8.Delete the <empty> line (which is always shown by default when composing a new formula) and then click the Add Function button.

9.In the Function list, select the Sum function.

10.In the editor window under the newly added Sum function, select the <empty> line so we can specify the column to sum.

11.Select Field and then locate the column that you want to add (e.g. Total - All Rows).

Performing Column Calculations_Select a Field Dialog

The Formula Editor will now look as follows:

Performing Column Calculations - Compose Formula Dialog

12.Click OK. You can save and preview your app to test the behavior. Whenever a value is entered in the Total column, the Grand Total will be updated.

 

Table Column Calculations

Table Column Calculations

(3 min)

Column calculations within a table can be built to work with all data in a specific column. This would normally be to sum the data but there are other options too such as taking the maximum, minimum or average value from all data in a column.

 

See also: Using the Set Table Rows Behavior Command

 

Return to: Adding Behaviors to a Table, Adding Behaviors, Designing an App