Perform calculations with decimals
In apps and dashboards, you can perform numeric calculations and specify whether the results are in integer or decimal format. You can also round the results to a certain number of decimal places.
Example
This example application tracks monthly revenue, customers and customers lost, and calculates the monthly customer attrition rate.
Form Field Calculation
- Create two numeric fields, "Customer Count Month Start" and "Customers Lost" for the data values we will use in the calculation
- Create another numeric field called "Customer Attrition Rate" where we will do the calculation
- Click on "Abc" to the right of field Type and select "Formula Calculation"
- In the formula section, divide the field "Customers Lost" by "Customer Count Month Start." Press the Control+Spacebar keys to bring up a list of all fields in the app you can select from
- Check the "Format result as decimal value" checkbox
- Next, use Flowfinity's "Decimal" function to force the calculation to treat the two numbers being divided as decimals, rather than integers. This is important to ensure an accurate result because the customer data fields will contain whole numbers which will otherwise be interpreted as integers. The function is written as: Decimal(field)
- Multiply by 100 to get percentage
- Use Flowfinity's "Round" function to round the result to one decimal place.
- The function is written as: Round(field, number of decimal places)
Here is the resulting Attrition Rate field shown in a View.
Dashboard Calculation
You can also perform calculations within dashboards, on data in your database or aggregated data. For example, if you only wish to view the customer attrition rate in a dashboard instead of having a separate field in the application for it, you can perform the calculation directly within the dashboard.
- Customize the dashboard, from the Configure tab or by clicking the dashboard menu
- Click on the table icon to display the data in a table
- Right click and select "Add calculated measure" from the menu
- Name the measure, and for "Apply formula to", select "aggregated measures." This will perform the calculation on the data that has already been aggregated in the table
- Enter the formula to divide "Customers Lost" by "Customer Count Month Start" and multiply by 100 to calculate "Customer Attrition." Be sure to use the Decimal function for each field
- Select the number of decimal places you would like to round the result to, from the "Decimal places" drop-down menu
- Click on the chart/table icon at the top right to display the data as a chart
- Right click in the chart area and select "Add Level" to chart the Customer Attrition data
- Name the level, and delete all the measures except "Customer Attrition." Select Line to display the data in a line chart