How to: translate values of a key in an array (in my case to group by weeknumbers)?

Hi all,

Can anyone help me with a formula to translate timestamps in an array into UNIQUE (GROUPS of) weeknumbers (with use of Weweb’s “Date”-extension)?

The formula “getWeekOfYear” works fine on a specific value of an OBJECT, but I can’t figure out how to apply it to an ARRAY.

Also, my ‘standard procedure’ to create an array of GROUP-values doesn’t work yet - as the function “getWeekOfYear” seems to be a “rounding” to weeknumbers instead of actually translating the timestamp-values into an actual weeknumber. That’s why I don’t have a ‘weeknumber’ available at the Card-level to apply a “filterbyKey” on (so I still wind up with multiple groups (of different dates) that are “rounded” to the same weeknumbers).

Thanks!

1 Like

Hello @thijs,

There are two solutions to do what you want. If you want to do it fully with no-code formula, you will need to do the logic in a workflow on page load

You will create a loop with your array. For each iteration, you can modify the current index of your array or add the result to a new array. Depends on if you need the timestamp for something else. You will use your formula getWeekOfYear() to get the result.

After the loop, you can use the formula distinct to remove all the duplicates and have each week only one time

The second solution is with JavaScript, in the bind of your repeat item, you can use the formula map: yourArray.map( (x) => getWeekOfYear(x) ). Thanks to this formula, you should have the week for each timestamp. You can then use the formula distinct()

Update

You don’t need to switch to JS for the second solution, you can do the formula directly in the formula tab:
To write the first = like I did, you need to add "=" and then remove the quote

1 Like