FormulaMap() is a powerful formula in Coda that lets you apply the same formula to every item in a list, whether it's numbers, text, or rows. In this article, we'll explore how to leverage FormulaMap() to streamline your workflows and tackle complex data manipulation tasks.
Within this article, you’ll find...
Understand FormulaMap()
FormulaMap() is an essential formula in Coda, enabling users to apply a consistent formula to each item in a list, much like a "for each" loop in programming. With this formula, you’re essentially saying: “for each item in this list, do XYZ.”
The FormulaMap() formula takes two inputs:
A list of items: this could be a list of numbers, a list of rows (aka a table or a filtered table), or a list of text inputs.
A formula to apply to each item in that list.
When using FormulaMap(), we’ll use CurrentValue to refer to the current item in the list.
CurrentValue explained
In Coda, when using the FormulaMap() formula, CurrentValue is a special term that helps you work with each item in a list one at a time. Imagine you have a list of items, like numbers, and you want to do something specific to each one, such as multiplying by 10.
CurrentValue acts like a placeholder for each item as you go through the list. So, if you're multiplying numbers, CurrentValue represents the number you're currently looking at in the list.
This way, you can apply the same action to every item without having to write separate instructions for each one. It's like saying, "For each item in my list, do this,” where CurrentValue is the item being worked on at the moment.
A simple example
Imagine you have a list of numbers and you'd like to perform the same operation on each one. For example, you might want to multiply every number by 10. You could accomplish that with FormulaMap(), where the specified action is CurrentValue * 10. Check out the two different ways to write this formula below. The first example uses dot notation for easy comprehension, but the second example works as well.
In the example above, FormulaMap() is looking at the given list of numbers, starting at the first value, 1, and then multiplying by 10. Once it takes that action, it moves to the second value, 2, and multiplies that value by 10.
This cycle continues until FormulaMap() has taken that action for every value in the given list.
💡 Tip: If you have a background in programming and are more familiar and comfortable with that terminology, you can make a direct swap from FormulaMap() to ForEach() in Coda’s formula language. The two formulas work exactly the same 😃
Apply FormulaMap() in your docs
Looking at the simple example above, you might wonder why one wouldn’t simply use a table with a list of numbers and a column formula to multiply those values by 10 — and you know, that’s a really simple solution!
However, there are times when creating a table with the data you want to apply a formula to can be quite tricky or more time-consuming than using FormulaMap()
FormulaMap() in buttons
You can use the FormulaMap() formula within buttons to achieve more complex actions - such as adding rows or sending notifications - for each item in a list.
This example demonstrates how to use FormulaMap() in conjunction with a button to automatically add a row to a specified table for each row listed in another table.
FormulaMap() for summarizing table data
This example uses FormulaMap() to generate a bulleted list of incomplete tasks and their due dates by filtering and summarizing data from a tasks table.
💡 For more interesting and advanced examples of how you might use FormulaMap(), check out our community.
Related resources
How to use FormulaMap in Coda docs | Coda YouTube
currentValue vs. thisRow formulas explained | Coda YouTube
Basics of Coda formulas | Coda Help Center
Troubleshoot your formulas | Coda Help Center
Button basics | Coda Help Center