Bonus Exercise 2: Adding calculations
Duration: 30 minutes
In this bonus exercise, you will learn how to use Excel like formulas to add cost calculations for a travel request. Our goal here is to use a per diem rate multiplied by number of days, added to the estimated airfare cost to get an estimated trip total cost.
Part 1: Creating our formulas
-
Navigate back to your App Home screen if you are not currently on it, then click the Travel request table to open table builder
-
Click the Forms button to get to form builder
-
Click Add a field in the table
-
In the pop-up, enter Travel days in Column label, and change Type to Integer. Leave the auto-populated field under Column name
-
Click Add
-
Click Add another one
-
Enter Estimated trip cost in Column label, and change Type to Decimal. Leave the auto-populated field under Column name
-
Click Add
-
Click Done
-
You should notice now on the left sidebar two form elements highlighted with a purple left border. These are your new fields you added
-
Drag and drop the Travel days and Estimated trip cost form elements onto your form
-
Click Save
-
Click the Travel days form element
-
On the rightside bar, you should see the options change
-
Click Formula
-
Click Add
-
In the pop-up Formula box, enter the following formula:
TIMEDIFF(return_date,departure_date)
-
Click Submit
-
On the top right, click Save
-
Click Estimated trip cost
-
Click Formula, then Add
-
In the pop-up Formula box, enter the following formula:
SUM(estimated_airfare,MULTIPLY(travel_days, 150))
Our formula here takes into account that each travel day, the employee is given a $150 per diem
-
Click Submit
-
On the top right, click Save
Part 2: Testing our formulas
-
Go back to App Home
-
Click PREVIEW on the Travel request row
-
A new tab opens up to show the list of Travel requests
-
We did not format this list view back in Exercise 1, so let’s go ahead to do that quickly
-
Right-click anywhere on one of the column headers
-
Click List Layout under Configure
-
On the right Selected section, remove everything except Number and State. Do this by double-clicking on each line to be removed
-
Add Opened by, Reason for travel, Departure date, Estimated trip cost from the left Available section onto the right Selected section
-
Click Save
-
You should now return to the list layout (your records will be slightly different based on what you entered in the exercise 4)
-
Click New on the top right
-
Fill up the form, ensure that you enter information for Departure date, Return date and any numerical figure for Estimated airfare
-
Right-click on the form header, then click Save
-
Notice that the Travel days and Estimated trip cost fields are automatically populated, ensure that the values are correct
-
In the screenshot above, the following was calculated
(4 * 150) + 1,390.50 = 1,990.50
Well done, you now understand how to build excel-like formulas into your application! Here are some other possible formulas that are currently supported, but more are on the way:
- AND Performs a logical AND operation on the arguments.
- AVERAGE Returns the average value of the arguments.
- CONCATENATE Joins one or more input strings into a single string.
- DIVIDE Returns the quotient value after dividing argument 2 by argument 1.
- IF Executes the specified statements based on the Boolean output of the conditional expression.
- ISBLANK Finds white spaces or blank values in the string and returns true if there are any.
- LENGTH Returns the total number of characters in the input string.
- LOWERCASE Converts the input string to all lowercase characters.
- MAX Returns the highest value in the specified arguments.
- MIN Returns the lowest value in the specified arguments.
- MULTIPLY Returns the multiplied value of the arguments.
- NOW Returns the current date and time of the instance in ISO format.
- OR Performs logical OR operation on the arguments.
- POWER Returns the result of the base value raised to the power of the exponent value.
- REPLACE Replaces characters in the source string with the characters in the target string.
- SUBTRACT Returns the result value after subtracting argument 2 from argument 1.
- SUM Returns the sum of all the arguments.
- TIMEDIFF Finds difference between 2 dates for Duration field.
- TITLECASE Converts the input string to all title case characters.
- UPPERCASE Converts the input string to all uppercase characters.