# Simple thing I can't work out

**URL:** <https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993>\
**Category:** Ask the Community\
**Created:** [January 23, 2019, 7:21pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993 "2019-01-23T19:21:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Unwin1](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/josh_unwin1/32/5885_2.png) [@Josh\_Unwin1](https://connect.superhuman.com/u/Josh_Unwin1)\
**Post date:** [January 23, 2019, 7:21pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/1 "2019-01-23T19:21:49Z")

</div>

Hi guys,

I know I’m going to kick myself when I get an answer, but I haven’t used Coda in a while so I’m a bit rusty at best.

I’m simply trying to make a formula that calculates days between a date in a cell in the row above, verses the cell in the current row (they are in different columns).

To help explain, see my screenshot below. I want ‘Time between visits’ to show number of days between the last rows end date and the current rows start date.

 ![2019-01-23%2019_20_27-Coda](https://global.discourse-cdn.com/coda1/original/2X/f/fbba23b6dad7e6a17e1f16bf521bdf734f767cac.png)

Help much appreciated!

---

<div class="post-metadata">

**Author:** ![tomavatars](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/tomavatars/32/6130_2.png) [@tomavatars](https://connect.superhuman.com/u/tomavatars)\
**Post date:** [January 23, 2019, 7:29pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/2 "2019-01-23T19:29:16Z")

</div>

Hello.  
I believe End-Start should work?

---

<div class="post-metadata">

**Author:** ![Josh\_Unwin1](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/josh_unwin1/32/5885_2.png) [@Josh\_Unwin1](https://connect.superhuman.com/u/Josh_Unwin1)\
**Post date:** [January 23, 2019, 8:52pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/3 "2019-01-23T20:52:20Z")

</div>

Yeah, but it needs to be End from the previous row minus the Start from the current row if that makes sense, that’s the bit I’m stuck with

---

<div class="post-metadata">

**Author:** ![Ander](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ander/32/9134_2.png) [@Ander](https://connect.superhuman.com/u/Ander)\
**Post date:** [January 23, 2019, 8:55pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/4 "2019-01-23T20:55:07Z")

</div>

@Josh_Unwin1

You might try something like this:

 ![calc_off_previous_row_2019-01-23_1439](https://global.discourse-cdn.com/coda1/original/2X/9/92b0994fc1c444ec0b7e9e1ab26a416735fb4370.png)

---

<div class="post-metadata">

**Author:** ![Josh\_Unwin1](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/josh_unwin1/32/5885_2.png) [@Josh\_Unwin1](https://connect.superhuman.com/u/Josh_Unwin1)\
**Post date:** [January 23, 2019, 9:14pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/5 "2019-01-23T21:14:56Z")

</div>

Fantastic, thank you! That was more involved than I thought it would be!

---

<div class="post-metadata">

**Author:** ![Krunal\_Sheth](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/krunal_sheth/32/5936_2.png) [@Krunal\_Sheth](https://connect.superhuman.com/u/Krunal_Sheth)\
**Post date:** [January 24, 2019, 5:57am UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/6 "2019-01-24T05:57:31Z")

</div>

@Josh_Unwin1, @Ander

A word of caution for the solution - that solution works only if rows were created in order.

If you have rows created out of order - you might want to actually pick the record with highest `end date` that is earlier than current records’ start date.

here’s a document that shows results with both approaches and you can see when rows are created out of order- you might get odd results.

https://coda.io/embed/KIMI00uemd/_suCuQ?viewMode=embedplay

---

<div class="post-metadata">

**Author:** ![Ander](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ander/32/9134_2.png) [@Ander](https://connect.superhuman.com/u/Ander)\
**Post date:** [January 24, 2019, 2:42pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/7 "2019-01-24T14:42:28Z")

</div>

Thanks @Krunal,

I was unclear on this `RowId()` issue.

This method is a pretty big ask for everyday Excel users coming over who just want to run calcs based on preceding values, which is a mundane task in Excel.

$.02 🕶

* * *

Also, while playing with this I arrived at another question.

The `Filter()` formula documentation contains this:

> If list is a table, use “`thisRow`” to reference the current row being evaluated. Otherwise, use “`currentValue`” to reference the current item being evaluated.

EXAMPLE STATEMENTS  
`If(thisRow = thisTable.First(), start - start, start - thisTable.Filter(` **thisRow** `.period = ` **thisRow** `.period - 1).end.First())`

`If(thisRow = thisTable.First(), start - start, start - thisTable.Filter(` **CurrentValue** `.period = ` **thisRow** `.period - 1).end.First())`

When list is a table and `thisRow` is used to reference the current row being evaluated, it makes it difficult to `Filter()` using a logic statement that compares the `thisRow` that’s being evaluated by `Filter()` and the `thisRow` that holds the formula in which `Filter()` is being run (unless the two instances of `thisRow` are unique under the hood?). Whereas, if the former were `CurrentValue` (as with other lists) then `thisRow` would still be free to use in the latter, and the two could be compared…??

What’s the correct way to think about this? (Because I’m confused 🤪 !!)

---

<div class="post-metadata">

**Author:** ![Ander](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ander/32/9134_2.png) [@Ander](https://connect.superhuman.com/u/Ander)\
**Post date:** [January 31, 2019, 9:42pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/8 "2019-01-31T21:42:49Z")

</div>

@Josh_Unwin1 @Krunal_Sheth

I just tried something that I learned from Krunal’s post here: [Visual Position of the row in table](https://connect.superhuman.com/t/visual-position-of-the-row-in-table/3404)

This works, even when dragging rows out of the order in which they were created. `thisTable.Find(thisRow)` appears to be a stable way to reference relative row position.

It seems too simple, like I must be missing something.

![calc_off_preceding_row_2019-01-31_1524](https://global.discourse-cdn.com/coda1/original/2X/2/2b2a3ddc05669a0f3e3c730ec2e871975bae7d72.png)

NOTE: Rows “week 4” and “week 5” were dragged out of position and then their dates were populated.

---

<div class="post-metadata">

**Author:** ![Krunal\_Sheth](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/krunal_sheth/32/5936_2.png) [@Krunal\_Sheth](https://connect.superhuman.com/u/Krunal_Sheth)\
**Post date:** [January 31, 2019, 10:52pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/9 "2019-01-31T22:52:55Z")

</div>

how does week4 start before week1 in that sample data? if you change the data of start, end it would be not be correct.

---

<div class="post-metadata">

**Author:** ![Ander](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ander/32/9134_2.png) [@Ander](https://connect.superhuman.com/u/Ander)\
**Post date:** [January 31, 2019, 11:31pm UTC](https://connect.superhuman.com/t/simple-thing-i-cant-work-out/5993/10 "2019-01-31T23:31:55Z")

</div>

@Krunal_Sheth

Poorly communicated on my part. I should have clarified that I was only solving for basing a calculation off of a preceding row value, without using `RowId()`.

It was not intended to also solve for the case when start/end dates are changed in such a way that they are no longer in sequence, which your formula does.
