# ForEach in combination with Loop

Hi,

I’ve already checked out multiple topics, but I just can’t manage to solve the following problem:

My goal is to create an audiobook tracker. In order to make my goals more specific, I would like to create a table based on various inputs that calculates the goals for each day.

I imagine the whole thing is that I press a button (outside the table) and then all the data is calculated automatically.
However, it is important that the entire playing time is completed on the last day and that it is not calculated beyond the total playing time.

Here is my doc:

1 Like

Interesting exercise to get the morning started

Calculate:

Sequence(0, Duration - 1).ForEach(WithName(CurrentValue, i, [Table].AddRow([Table].Date, Start + i, [Table].[Playtime (Start)], i * [Daily Playtime] + Seconds(i), [Table].[Playtime (End)], (i + 1) * [Daily Playtime] + Seconds(i))))

Updated Daily Playtime

Playtime / Duration.ToNumber() - Seconds((Duration - 1) / Duration)

Since you wanted exclusive segments we need to subtract (days - 1) / days seconds from the daily playtime.
Then it’s a matter of iterating every day and keeping track of the index

3 Likes

Thank you, @Rickard_Abraham,

that works perfect!

Jannis

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.