# Formula to add up hours in a 4-week period?

**URL:** <https://community.glideapps.com/t/formula-to-add-up-hours-in-a-4-week-period/30384>\
**Category:** Ask for Help\
**Created:** [August 12, 2021, 2:40pm UTC](https://community.glideapps.com/t/formula-to-add-up-hours-in-a-4-week-period/30384 "2021-08-12T14:40:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tasina\_Westberg](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/tasina_westberg/32/29533_2.png) [@Tasina\_Westberg](https://community.glideapps.com/u/Tasina_Westberg)\
**Post date:** [August 12, 2021, 2:40pm UTC](https://community.glideapps.com/t/formula-to-add-up-hours-in-a-4-week-period/30384/1 "2021-08-12T14:40:06Z")

</div>

Hello, we are making a timesheet app.  
We’d like to create a formula that adds up the total hours worked from a 4-week period, but we only want to include the past 4 CONSECUTIVE weeks. How can we make a formula for this? I’ve included screenshots below showing my current attempts-- basically, I’ve multiplied my weekly totals by 4, but since I don’t know how to limit it so that we only have the past 4 weeks, I have ALL weekly totals multiplied by 4. How can I solve this?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 12, 2021, 2:52pm UTC](https://community.glideapps.com/t/formula-to-add-up-hours-in-a-4-week-period/30384/2 "2021-08-12T14:52:01Z")

</div>

4 weeks from _now_, or 4 weeks from a specific date? (ie yesterday, last Monday, etc)

I’ll assume the later.

- Create a date column to store that value
- Next create a math column to calculate the date 4 weeks prior to that. Use the formula `date - 28` where `date` is the value in the first column
- Now create an if-then-else column that compares the timesheet date to the respective start and end dates of your 4 week period (the first two columns).
  - If it’s before the start date, return empty
  - If it’s after the end date, return empty
  - Else return `true` (it’s in the goldilocks zone)

- Now you can use that column as a filter to only return rows within your 4 week window.

Edit: ugh… just re-read and realised you want to sum the hours… okay, a couple of extra steps required:

- create a template column that returns the single word `true`
- create a multi-relation column that joins the template column to the if-then-else column mentioned above
- now create a rollup column, that does a sum of hours through that relation.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 13, 2021, 12:31am UTC](https://community.glideapps.com/t/formula-to-add-up-hours-in-a-4-week-period/30384/3 "2021-08-13T00:31:21Z")

</div>

> [@Tasina\_Westberg](#):
>
> but we only want to include the past 4 CONSECUTIVE weeks

So you mean this 4-week can be user-specific right?

Say I work week 1, 2, 7, 100, 500 then we look at 2, 7, 100, 500 data?
