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
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 you enjoyed this article. If you have questions feel free to reach out. Though this article is for free, my work (including advice) won’t be, but there is always room for a chat to see what can be done. Besides you find my (for free) contributions to the Coda Community and on Twitter