Photo by Constantin on Unsplash |How To Coda A Moving Average

How To Coda A Moving Average

Based on a question in the community

Christiaan Huizer
3 min readFeb 3, 2022

--

In my blog post How to Coda Rolling Total I suggested to make use of the FormulaMap()

Below the solution I proposed and a bit further the same with an extra element: a controller to select the days you want.

Moving Average

Again it is based on the FormulaMap() to first get the all the dates in step 01

This is a good start, but we need only the last 7 days and to get this we use the Slice() function with a negative number:

Instead of writing 7 in the function, I created a controller to have a more flexible approach:

using a controller to play with the numbers

Note that I first make sure the number is always positive — via AbsolutValue() and next I make it negative.

The outcome is a date range and this one I’ll use in my Filter(). First I apply a WithName() to keep the function understandable and off we go

a flexible solution for a moving average

I turn the Text Column into a Number column, put the decimals on 2 and add the IfBlank(“”) at the end.

finishing touch using IfBlank()

This solution works also when the values you deal with are not dates due to the RowIndex formula. In case you deal only with dates, Joostmineur showed me an even easier way (many thx Joost!):

solution provided by Joost using a filter

You find the table you see above over here :

I hope this article was informative and helpful. Did it help you to solve a problem you unlike would have solved other ways? What about a donation?

My name is Christiaan, and I regularly blog about Coda. While this article is free, my professional services (including consultations) are not, but I’m always happy to chat and explore potential solutions. You can find my free contributions in the Coda Community and on X. The Coda Community is a fantastic resource for free insights, especially when you share a sample doc.

Huizer Automation — Coda Expert and Consultant on “How To Coda A Moving Average”

--

--

Christiaan Huizer
Christiaan Huizer

Written by Christiaan Huizer

I write about how to Coda . You find blogs for beginners and experienced makers. I publish about 1 / week. Welcome!

No responses yet