How To Coda A Moving Average
Based on a question in the community
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.
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:
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
I turn the Text Column into a Number column, put the decimals on 2 and add the IfBlank(“”)
at the end.
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!):
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.