The Math Column allows you to perform instant calculations on the data in your table, from basic arithmetic functions to more complex ones. You can then show the output by displaying it in various components in your app.
In the Data Editor, open the table you want to edit.
Add a new column by clicking the plus (+) symbol to the right of the table.
New columns added with the plus button will always appear on the right. If you'd like to add a column somewhere else in your data, you can select the dropdown menu on an existing column and choose Add column right. You can also click and drag columns to rearrange them.
Name the column.
For Type, search for Math or navigate to Computed -> Math.
Write your calculation or formula in the Configuration field. You can use regular text for this. For example, "price + shipping" (entered without the quotation marks) is all you need to calculate total cost of both price and shipping.
Add Replacements for every word in your configuration. This lets your app know which columns to pull from for each value.
You can specify the precision of decimal points, whether to use a group separator, and if you want to display units as part of the calculated result.
As you start typing in the Configuration field, Glide will guess which column you are referring to and add a new replacement. But you can easily change what is being replaced.
You can also replace parts of your formula with other values such as the values from the User Profile table or the value of Now, which is very useful for date calculations.
Addition, subtraction, multiplication, division, exponentiation, parenthesis
LOG, ABS, MIN, MAX, FLOOR, CEILING, ROUND, TRUNC, ASIN, COS, ACOS, ATAN, MOD, SECOND, MINUTE, HOUR, DAY, WEEKDAY, MONTH, YEAR
The Math column can also do calculations with dates and times. For example, subtracting two dates/times produces a duration.
You can use the Now value to calculate the time until something will happen or how long ago something was.
Now and a Date will give you how long ago a date is (if that date is in the past)
A Date and Now will give you how long until a particular date (if that date is in the future)
When the output of your math column is a date/time value you will also be able to format it.
In Google Sheets, it may not be obvious, but dates are actually stored as numbers. It’s not until cells are formatted as Dates that we can actually read the day, month, year, and time of day from the data.
Date values in Google Sheets are long strings of numbers that represent the number of days since December 31st, 1899. For example, the number 1, when formatted as a date, will display as December 31, 1899.
If you’re working with a value that has a date and time, the Date Value will contain a decimal value that represents the portion of a single day. For example, December 31, 1899 12:00PM would be represented by 1.5 if the cell is formatted as a number.
If you’re working in Microsoft Excel, the Date Value is calculated one day later than in Google Sheets. That is, in Excel, the number 1 represents January 1, 1900 (and not December 31, 1899).
In Glide, you can use the Math column to calculate the difference, or duration, between dates. By default, Glide will display the duration in this format: HH:MM:SS (Hours:Minutes:Seconds), which is the same format as you’d see in Google Sheets when formatting as a Duration.
If you need this data to be displayed differently,you can use some familiar Math functions. For example, by using the FLOOR function, we can display the duration as the number of days as opposed to hours.
Here are some of the most common ways to use the Math column in your apps beyond simple calculation.
As mentioned above, the Now value enables you to calculate the duration between now and the past, or now and the future.
The problem with this, though, is that the output is a duration type, which is not necessarily that readable.
You can use floor() to reduce this to the number of days since/until another date. You can do this by surrounding your original calculation with floor. Now, you can use this value in your app and it will update as time progresses.
Let’s say you have a project management app with a list of projects and tasks. When someone completes a task, the completed column is marked True.
In the project table, you have a Relation bringing back all the tasks for that project.
First, you create a Rollup using that relation and count all the tasks with the value of true.
Next, you create another Rollup counting all the unique tasks so you have the total number of tasks in that project (completed or uncompleted).
Finally, you add a math column that calculates the percentage using the formula Completed/Total*100. Make sure that Completed and Total are replaced by the correct columns.
You can change the precision to 1 and add the percentage sign.
Now you can add a text component in your app that shows the progress on each project.