# Outer CurrentValue access

**URL:** <https://connect.superhuman.com/t/outer-currentvalue-access/8048>\
**Category:** Ask the Community\
**Created:** [May 13, 2019, 11:34pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048 "2019-05-13T23:34:06Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Stefan\_Singer](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/stefan_singer/32/12491_2.png) [@Stefan\_Singer](https://connect.superhuman.com/u/Stefan_Singer)\
**Post date:** [January 25, 2020, 8:24pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/42 "2020-01-25T20:24:30Z")

</div>

Ah, I see now, it’s based on my formula above. Do take note, if there’s only one member on a date, the bulleted list will become:

- Stefan
- 50%

Because the data then is [Stefan, 50%]

---

<div class="post-metadata">

**Author:** ![anon41554251](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@anon41554251](https://connect.superhuman.com/u/anon41554251)\
**Post date:** [May 7, 2020, 9:27am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/43 "2020-05-07T09:27:41Z")

</div>

Hi @shishir, is there any progress on this matter? I’m running into the same issue and would like to know if I can avoid the reported work-arounds by waiting for the solution from Coda’s side. I do vote for the colored distinction too as I don’t use API… Thanks!

---

<div class="post-metadata">

**Author:** ![shishir](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/shishir/32/6017_2.png) [@shishir](https://connect.superhuman.com/u/shishir)\
**Post date:** [May 7, 2020, 8:02pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/44 "2020-05-07T20:02:42Z")

</div>

Unfortunately no. I don’t think we’ve arrived at a new pattern we feel confident in yet. Would be great to keep suggesting alternatives (like the ones above) to help when we pick this back up.

---

<div class="post-metadata">

**Author:** ![Paul\_Danyliuk](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/paul_danyliuk/32/27228_2.png) [@Paul\_Danyliuk](https://connect.superhuman.com/u/Paul_Danyliuk)\
**Post date:** [May 16, 2020, 4:10pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/45 "2020-05-16T16:10:33Z")

</div>

Meanwhile one more approach to work with multiple CurrentValue contexts in a live formula: make a full product of all combinations of inner and outer CurrentValue and iterate over that:

> [@Dedupe an array of arrays based on a common key/object with formulamap()](https://connect.superhuman.com/t/dedupe-an-array-of-arrays-based-on-a-common-key-object-with-formulamap/15936/16):
>
> Alright, here’s an explanation (also noticed a problem with my solution while writing this post, lol, so fixed and also simplified). Normally the solution would look like this: Get the list of unique emails as [List of lists].FormulaMap( CurrentValue.Last() ) given that emails are last in each list. Run a simple formula map: [Unique emails].FormulaMap( [List of lists].Filter(CurrentValue.Last() = uhm… CurrentValue).First() ) i.e. for each email (CurrentValue) filter the list of li…

---

<div class="post-metadata">

**Author:** ![Paul\_Danyliuk](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/paul_danyliuk/32/27228_2.png) [@Paul\_Danyliuk](https://connect.superhuman.com/u/Paul_Danyliuk)\
**Post date:** [May 17, 2020, 1:15pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/46 "2020-05-17T13:15:24Z")

</div>

Also, while working on that previous post I discovered the reason why this CurrentValue issue is not so easy to address, from design point of view.

First, I think everyone in Coda wants to avoid going with `CurrentValue1`, `CurrentValue2` etc. From a software engineer point of view this doesn’t look elegant at all. Not only the suffixes `1` `2` etc bear no meaning other than telling variables apart, I can see how this would break many formulas relying on `CurrentValue` being the one from current context.

However, with the way how Coda currently works with variables, we cannot have multiple `CurrentValue` (with different color coding) either.

The first reason is logical: what if the outer loop and the inner loop use values from the same table, e.g. `Tasks.FormulaMap(Tasks.Filter(...))`? The colors and types of an inner and an outer CurrentValue would be the same then.

The second reason, however, is technical. Turns out, variables (`$$[variable:...]` items) are actually distinguished by their name, not an ID (and it makes sense):

 ![ezgif.com-optimize (80)](https://global.discourse-cdn.com/coda1/original/2X/0/0c435ae7d27e685243ca34084f63d0ac42868a0a.gif)

Even if you supply some random arguments to the `$$[]` reference formula in place of actual grid ID and object ID, Coda will ignore those and replace them with the grid ID of the collection that CurrentValue is iterating over (I believe for coloring purposes only). And if you keep the IDs but rename the variable, it will resolve to blanks:

![ezgif.com-optimize (81)](https://global.discourse-cdn.com/coda1/original/2X/e/e7f3e2874275e1ab2f897f0759241861a0b3f5b2.gif)

Doing the same thing with a row reference would do the opposite: still point to the specified object ID and row/column ID, and replace the name to reflect the actual name instead.

So this is why it’s not possible to have two `CurrentValue` variables — because **unlike row/column references, variables are referenced not by any internal IDs but by names.**

(Also you could’ve just told us so 😉 I know you want to communicate the reasons in a simple way for the majority of non-technical users to understand. But sharing the technical reasons would not only be very appreciated among us power users, but we’d be able to pitch in with better educated suggestions.)

Given this knowledge, I have another approach in mind. Keep `CurrentValue` behavior as is, but **introduce a new variable `CurrentValues`** that would be a list of all `CurrentValue` down the function stack. I.e. `CurrentValues.First()` would always be the outermost one, `CurrentValues.Last()` would be the innermost one (always the same as `CurrentValue`), `CurrentValues.Nth()` would give access to intermediary ones if needed etc. Technically it’d be as simple as `push()`ing and `pop()`ing a value in/out of the array whenever you’re entering/exiting the nested context (i.e. in the same pieces of logic where `CurrentValue` is changed). I imagine this would be the simplest addition (no extra syntax required), an elegant one, and pretty much solve the pain point. @shishir

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [May 17, 2020, 3:02pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/47 "2020-05-17T15:02:22Z")

</div>

> [@Paul\_Danyliuk](#):
>
> Keep `CurrentValue` behavior as is, but **introduce a new variable `CurrentValues`**

I guess this is a **great** perspective.  
I fully support this idea: it’s keeping compatibility with the existing implementation (i.e. `CurrentValue` is _always_ `CurrentValues.Last()`) and allows to have a full control of nested contexts.  
Good point @Paul_Danyliuk 👍

---

<div class="post-metadata">

**Author:** ![shishir](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/shishir/32/6017_2.png) [@shishir](https://connect.superhuman.com/u/shishir)\
**Post date:** [November 18, 2020, 2:10am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/48 "2020-11-18T02:10:01Z")

</div>

Quick re-up on this thread since we’ve been discussing ways to address this (no promises yet, just trying to figure out the right design). Would love updated thoughts to one of the earlier posts with a few options for how to handle this ([Outer CurrentValue access](https://connect.superhuman.com/t/outer-currentvalue-access/8048/17)). Any new syntax for differentiating loop variables that people would find natural?

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [November 18, 2020, 8:45am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/49 "2020-11-18T08:45:36Z")

</div>

Hi @shishir,  
I believe that so far @Paul_Danyliuk’s ([Outer CurrentValue access](https://connect.superhuman.com/t/outer-currentvalue-access/8048/46)) proposal would meet many requirements on the user’s perspective and on the background implementation impacts.

Having a List of `CurrentValues`, being the first (`CurrentValues.First()` or `CurrentValues.Nth(1)`) the outermost value and the last (`CurrentValues.Last()` or `CurrentValues.Nth(CurrentValues.Count())` or by default the… _current_ `CurrentValue`) the innermost would be rather intuitive, consistent with the current implementation would definitely address many targets.

Happy to contribute more, if needed.  
Cheers

---

<div class="post-metadata">

**Author:** ![Johg\_Ananda](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/johg_ananda/32/13930_2.png) [@Johg\_Ananda](https://connect.superhuman.com/u/Johg_Ananda)\
**Post date:** [November 18, 2020, 3:53pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/50 "2020-11-18T15:53:48Z")

</div>

You have a framework for handling this with Automation, `Step 1 Result`, `Step 2 Result`, etc - could you build off that?

---

<div class="post-metadata">

**Author:** ![cnr](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/cnr/32/24174_2.png) [@cnr](https://connect.superhuman.com/u/cnr)\
**Post date:** [November 19, 2020, 8:10pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/51 "2020-11-19T20:10:24Z")

</div>

Building off of @Federico_Stefanato.

What if `CurrentValue` returns what we all know and love as `CurrentValue`. But, there are special formulas `Outer` and `Inner` (or perhaps `Previous`/`Next`) which accesses the current value stack.

So, given two lists of numbers `[1, 2, 3, 4]` and letters `["a", "b", "c", "d"]` , where you want the output

```auto
1 a
2 b
3 c
4 d

```

You would use the formula:

```auto
[1, 2, 3, 4].FormulaMap(
  ["a", "b", "c", "d"].FormulaMap(
    Concatenate(CurrentValue.Outer(), CurrentValue)
  )
)

```

For multiple nested lists, `Outer` and `Inner` should be “subscriptable” or indexable. E.g. with the lists `[1, 2, 3, 4]`, `["a", "b", "c", "d"]`, and `["w", "x", "y", "z"]` with the desired output:

```auto
1 a w
2 b x
3 c y
4 d z

```

The formula would be:

```auto
[1, 2, 3, 4].FormulaMap(
  ["a", "b", "c", "d"].FormulaMap(
    ["w", "x", "y", "z"].FormulaMap(
      Concatenate(CurrentValue.Outer(2), CurrentValue.Outer(), CurrentValue)
    )
  )
)

```

This means that the default value of `Outer` when left unspecified is 1, which I think is in keeping with the behavior of `Nth` (which I think is smart anyway since 0 indexing can sometimes confuse people).

`Outer` and `Inner` should also be reverse subscriptable. For example, the same formula above could be written using `Inner` like this:

```auto
[1, 2, 3, 4].FormulaMap(
  ["a", "b", "c", "d"].FormulaMap(
    ["w", "x", "y", "z"].FormulaMap(
      Concatenate(CurrentValue.Inner(-2), CurrentValue.Inner(-1), CurrentValue)
    )
  )
)

```

This also would imply that you can use `CurrentValue.Outer(0)` and `CurrentValue.Inner(0)` as synonyms for `CurrentValue`.

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [November 20, 2020, 12:46pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/52 "2020-11-20T12:46:40Z")

</div>

> [@cnr](#):
>
> What if `CurrentValue` returns what we all know and love as `CurrentValue` . But, there are special formulas `Outer` and `Inner` (or perhaps `Previous` / `Next` ) which accesses the current value stack.

Hi @cnr,  
thanks for the exhaustive example.  
It is indeed what I reported (and again, **credit should primarily go to @Paul_Danyliuk** who first outlined the concept).

My suggestion is that instead of creating an _ad-hoc_ syntax for the `CurrentValues` stack, just rely on how Arrays are currently implemented, so that it can be analogous to other (Coda) contexts (also in terms of indexing coherence).

Plus, the **an additional property** of `CurrentValue`, **`depth`** , should represent the nesting level in a relative way.

From your extremely handy examples:

```auto
[1, 2, 3, 4].FormulaMap(
  ["a", "b", "c", "d"].FormulaMap(
    ["w", "x", "y", "z"].FormulaMap(
      Concatenate(
          CurrentValues.First(), // equivalent: CurrentValues.Nth(1); CurrentValues.Nth(CurrentValue.depth - 2);
          CurrentValues.Nth(2), // equivalent: CurrentValues.Nth(CurrentValue.depth - 1); btw, here CurrentValues.Nth(CurrentValue.depth - 1).depth would be, well, 2 :)
          CurrentValue // our beloved friend keeps his meaning - equivalent: CurrentValues.Last(); useless, but still... - CurrentValues.Nth(CurrentValue.depth); CurrentValues.Nth(CurrentValues.Count());
      )
    )
  )
)

```

I hope it makes sense.

Thank you!

---

<div class="post-metadata">

**Author:** ![Connor\_McCormick](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@Connor\_McCormick](https://connect.superhuman.com/u/Connor_McCormick)\
**Post date:** [November 20, 2020, 4:06pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/53 "2020-11-20T16:06:57Z")

</div>

@Federico_Stefanato the only issue I see with that approach is _what happens if `CurrentValue` is already returning a list?_

By having a special formula it’s always:

1. Clear that you’re operating on the `CurrentValue` stack, not on its value.
2. Much cleaner and simpler to explain. A new user comes in and says, “How do I get the current value from the loop outside the current one?” You reply, “the `Outer` formula.” They say, “ah duh, makes sense.”

I do agree that a `Depth()` formula would be nice to have.

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [November 20, 2020, 5:00pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/54 "2020-11-20T17:00:38Z")

</div>

Hi @Connor_McCormick,  
I think there is a little detail not clear, here…

Actually, `CurrentValue` is - and will be - a **value** holding the contextual element.  
Being a `List()` an single item or _a `List()` of `List()`_  
This should not change as it is today.

`CurrentValues` (with the s) is a `List()` of `CurrentValue`, therefore there are no semantical interferences.

`Depth()` should be an object on its own - such as `CurrentDepth`.

So, for instance:

```auto
List(List(1,2,3), List(4,5)).FormulaMap( 
   Format("Depth: {1}; Size: {2} {3}",
      CurrentDepth, CurrentValue.Count(), 
      CurrentValue.FormulaMap(
         Format("Depth: {1}; Value: {2} (Outer depth: {3}; Size: {4})", 
            CurrentDepth, 
            CurrentValue, 
            CurrentDepth -1
            CurrentValues.Nth(CurrentDepth -1).Count()
         )
      )
   ).BulletedList()
).BulletedList()

```

Would print

```auto
- Depth: 1; Size: 3
  - Depth: 2; Value: 1 (Outer depth: 1; Size: 3)
  - Depth: 2; Value: 2 (Outer depth: 1; Size: 3)
  - Depth: 2; Value: 3 (Outer depth: 1; Size: 3)
- Depth: 1; Size: 2
  - Depth: 2; Value: 4 (Outer depth: 1; Size: 2)
  - Depth: 2; Value: 5 (Outer depth: 1; Size: 2)

```

(Forgive me is I missed some parenthesis 🙂 the key is to understand the concept).

I hope it helps.

**Edit:**  
Updated with the `CurrentDepth` additional object

---

<div class="post-metadata">

**Author:** ![cnr](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/cnr/32/24174_2.png) [@cnr](https://connect.superhuman.com/u/cnr)\
**Post date:** [November 20, 2020, 5:11pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/55 "2020-11-20T17:11:12Z")

</div>

Ah got it, `CurrentValues` is the plural of `CurrentValue` and contains within it multiple `CurrentValues` in a list. Yeah, that would make sense. That reduces the ad hociness of the solution, at the cost of being a bit more verbose.

Which do you think is more readable:

```auto
CurrentValues.Nth(CurrentValue.Depth() - 2)

```

or

```auto
CurrentValue.Outer(2)

```

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [November 20, 2020, 5:12pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/56 "2020-11-20T17:12:17Z")

</div>

Maybe something that could clarify a bit more (?? not sure, tough) would be to call the list `ContextualValues` and the innermost element - `ContextualValues.Last()` - would be our `CurrentValue`.

🤔

---

<div class="post-metadata">

**Author:** ![Federico\_Stefanato](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/federico_stefanato/32/10092_2.png) [@Federico\_Stefanato](https://connect.superhuman.com/u/Federico_Stefanato)\
**Post date:** [November 20, 2020, 5:27pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/57 "2020-11-20T17:27:24Z")

</div>

Hi @cnr,

> [@cnr](#):
>
> Which do you think is more readable:
> 
> ```auto
> CurrentValues.Nth(CurrentValue.Depth() - 2)
> 
> ```
> 
> or
> 
> ```auto
> CurrentValue.Outer(2)
> 
> ```

Very good point.

Adding responsibility and complexity to the _current_ `CurrentValue` would have a significant impact on existing code, therefore I guess we should try to _add_ something, not _change_ it.

So this would then become

```auto
CurrentValues.Nth(CurrentDepth - 2)

```

Which would be a good compromise, I’d say

The reason I would prefer a “standard” implementation (i.e relying on what is already existing, therefore `List()`) is that there is a symmetric behaviour.  
Conceptual readability is always welcome, but it forces to have contextual syntaxes and this has a cost in terms of overall complexity and learning curve.

This is a personal opinion, of course and I totally see your point.

---

<div class="post-metadata">

**Author:** ![cnr](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/cnr/32/24174_2.png) [@cnr](https://connect.superhuman.com/u/cnr)\
**Post date:** [November 21, 2020, 6:05pm UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/59 "2020-11-21T18:05:21Z")

</div>

As I think about it more, aliasing would also be super beneficial. You could do things like this:

```auto
Table.FormulaMap(
  t := [Tasks].Filter(Done=false), 
  Sequence(Length(t)).FormulaMap(
    ...
))

```

---

<div class="post-metadata">

**Author:** ![Ian\_Nicholson](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ian_nicholson/32/7561_2.png) [@Ian\_Nicholson](https://connect.superhuman.com/u/Ian_Nicholson)\
**Post date:** [December 2, 2020, 1:36am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/60 "2020-12-02T01:36:18Z")

</div>

Variables! Or at least somewhat of an analog! Best solution I’ve seen mentioned so far…

I can’t help but think the `CurrentValues.Nth()` idea still seems a bit clunky and not user-friendly.

---

<div class="post-metadata">

**Author:** ![cnr](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/cnr/32/24174_2.png) [@cnr](https://connect.superhuman.com/u/cnr)\
**Post date:** [December 2, 2020, 1:54am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/61 "2020-12-02T01:54:57Z")

</div>

Yeah, not original to me, but would be enormously powerful. I think implementing both `OuterValue` and aliasing would be the best solution.

I agree that `Nth` is not what most new users will reach for. It’s as though we’re being intentionally pedantic in order to be “pure”. The question to ask is, “what will users try? What question will they ask in the forums?”

I think things like `CurrentValue.Outer()`, `OuterValue`, `PreviousValue` and the like are what I would try. Even `Value.Previous()` where `Value` defaults to `CurrentValue`.

Linguistically, they’ve kinda backed themselves into a weird corner, because it would seem that `CurrentValue` should always refer to a variable related to the current value, so if it ever relates to a variable that’s not the current value, like when it’s the _previous value_, that would seems weird. But language evolves, I prefer warts that work (read: finally give me nested for-loops, I’m begging you).

---

<div class="post-metadata">

**Author:** ![Johg\_Ananda](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/johg_ananda/32/13930_2.png) [@Johg\_Ananda](https://connect.superhuman.com/u/Johg_Ananda)\
**Post date:** [December 2, 2020, 7:12am UTC](https://connect.superhuman.com/t/outer-currentvalue-access/8048/62 "2020-12-02T07:12:27Z")

</div>

I feel that it part of this can be solved with really good UX. If the formula editor makes it abundantly clear that there are multiple values available, the user can use the down arrow to move through and select them. In this case, with clear labeling and presentation, the nomenclature becomes less important.

[Previous page](https://connect.superhuman.com/t/outer-currentvalue-access/8048.md?page=2)

[Next page](https://connect.superhuman.com/t/outer-currentvalue-access/8048.md?page=4)
