Hey Community!
Im currently building a Strava pack and came across a problem I wanted to solve for which I developed a new formula I’ve never used before and thought I’d share it with the community! (If someone already shared a similar formula let me know, just couldn’t find one)
What the formula does generally:
Allows you to run loops of actions X number of times with each iteration having different specific and general inputs
Stated another way, it allows you to increment inputs at different rates in loops
That probably made no sense. It sure didn’t to me. Let me explain with my use case.
My use Case
In my Strava pack (and Strava Doc Template) I want a user to instantly generate a table with 12 rows per year for every year they have been using strava. This will be different per user as people begin using Strava at different times.
Therefore if a user has been on Strava since 2017 and todays year is 2022, the button will need to generate 12 rows (numbered 1-12) per year. Each row will have to be numbered 1-12 sequentially, but the first time the loop runs it should number each year as 2017.
The second time the loop runs it should once again run 12 times (numbering rows 1-12 sequentially) and then number each year as 2018.
Heres the formula I used inside the button:
WithName(
Sequence([First Strava Activity].Year(), ToDay().Year()),
allYears,
Sequence(1, allYears.Count())
.FormulaMap(
WithName(
CurrentValue,
currentNth,
Sequence(1, 12)
.FormulaMap(
WithName(
CurrentValue,
currentMonthNumber,
AddRow(
[DB Months],
[DB Months].[Month Number],
currentMonthNumber,
[DB Months].Year,
allYears.Nth(currentNth)
)
)
)
)
)
)
Heres an example doc where you can see it in action: