# Launched: Reuse logic and create nested loops with the new WithName() formula

**URL:** <https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900>\
**Category:** News from Superhuman\
**Created:** [December 2, 2020, 10:06pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900 "2020-12-02T22:06:18Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Brian\_Fakhoury](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/brian_fakhoury/32/16532_2.png) [@Brian\_Fakhoury](https://connect.superhuman.com/u/Brian_Fakhoury)\
**Post date:** [December 3, 2020, 6:22pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/21 "2020-12-03T18:22:30Z")

</div>

i can’t explain how excited I am for this, so so so useful! No more [currentValue] ambiguities!!

Edit: would it be possible to have multiple expression/name pairs though instead of one?

---

<div class="post-metadata">

**Author:** ![Jean\_Pierre\_Traets](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jean_pierre_traets/32/16275_2.png) [@Jean\_Pierre\_Traets](https://connect.superhuman.com/u/Jean_Pierre_Traets)\
**Post date:** [December 3, 2020, 7:33pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/22 "2020-12-03T19:33:42Z")

</div>

Dear @Jason-Tamulonis. great achievement from you and the Codans that have been involved with the development and roll out 🏆 🏆 🏆

Dear “after sales/education 🥇 team” @maria, @Ben_Lee, @Al_Chen_Coda some practical samples and a formula fitness on this 👶 newborn child 👶 would be welcomed by many Coda enthusiasts 🤔

_Lately I am quite busy with new challenges in my life, but hopefully the soonest I will be able to add some sample myself, I am sure other community members will be able to show off their take on WITHNAME()_

---

<div class="post-metadata">

**Author:** ![Marko\_Petrovic](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/marko_petrovic/32/12015_2.png) [@Marko\_Petrovic](https://connect.superhuman.com/u/Marko_Petrovic)\
**Post date:** [December 3, 2020, 7:39pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/23 "2020-12-03T19:39:04Z")

</div>

I agree, one formula fitness for this new formula would be really cool 🙂

---

<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:** [December 4, 2020, 12:01pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/24 "2020-12-04T12:01:31Z")

</div>

@Jason-Tamulonis you still have some cases where it doesn’t work as expected. For example, we know that the result of `AddRow()` is a reference to the new row and we can insert it somewhere, e.g.

```auto
thisRow.ModifyRows(
  [New row], SomeTable.AddRow(...)
)

```

But guess how this works (hint: it doesn’t create just one row):

 ![image](https://global.discourse-cdn.com/coda1/original/3X/6/a/6a978ebffdb20620a21788d4d32f305f83a7c3be.png)

---

<div class="post-metadata">

**Author:** ![Spirit\_Guides\_Info](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/spirit_guides_info/32/18019_2.png) [@Spirit\_Guides\_Info](https://connect.superhuman.com/u/Spirit_Guides_Info)\
**Post date:** [December 4, 2020, 8:36pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/25 "2020-12-04T20:36:37Z")

</div>

Jack! Let’s do a hunker down and test some options.

---

<div class="post-metadata">

**Author:** ![Jack\_DePew](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jack_depew/32/14541_2.png) [@Jack\_DePew](https://connect.superhuman.com/u/Jack_DePew)\
**Post date:** [December 5, 2020, 12:37am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/26 "2020-12-05T00:37:20Z")

</div>

Yeah I’m in 100%! It’ll be fun.

---

<div class="post-metadata">

**Author:** ![Ed\_Liveikis](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ed_liveikis/32/21358_2.png) [@Ed\_Liveikis](https://connect.superhuman.com/u/Ed_Liveikis)\
**Post date:** [December 8, 2020, 4:23pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/27 "2020-12-08T16:23:28Z")

</div>

Very nice 🙂

From a performance standpoint is there going to be a significant difference between using `WithName` vs adding a column to hold the intermediate formula result?

---

<div class="post-metadata">

**Author:** ![Jason-Tamulonis](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jason-tamulonis/32/46956_2.png) [@Jason-Tamulonis](https://connect.superhuman.com/u/Jason-Tamulonis)\
**Post date:** [December 8, 2020, 8:07pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/28 "2020-12-08T20:07:45Z")

</div>

> [@Alexis\_Fennoy](#):
>
> Thank you so much for this information. I am wondering if this new tool can be used to iterate over groups of tasks. We are currently working on a project where we produce instructional content and we have a task list for the entire production process from end-to-end. Now, we are seeing that some classes are popular and we want to bring them back, which means we don’t need the entire task list, but just a subgroup of tasks to be able to repeat as needed. If the nested loops tool wouldn’t work for this, do you have other suggestions?

It seems like WithName might help here, but it is hard to tell without more details. I’d suggested starting a thread with your use case over on [Ask the community](https://connect.superhuman.com/c/askthecommunity/3)

---

<div class="post-metadata">

**Author:** ![Jason-Tamulonis](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jason-tamulonis/32/46956_2.png) [@Jason-Tamulonis](https://connect.superhuman.com/u/Jason-Tamulonis)\
**Post date:** [December 8, 2020, 8:15pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/29 "2020-12-08T20:15:19Z")

</div>

> [@Ed\_Liveikis](#):
>
> From a performance standpoint is there going to be a significant difference between using `WithName` vs adding a column to hold the intermediate formula result?

Putting an intermediate result in a column will basically guarantee that the value gets cached and recalculated less frequently. Using WithName may give you that benefit depending on how our optimizer handles your formula.

---

<div class="post-metadata">

**Author:** ![Alexis\_Fennoy](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/alexis_fennoy/32/17632_2.png) [@Alexis\_Fennoy](https://connect.superhuman.com/u/Alexis_Fennoy)\
**Post date:** [December 8, 2020, 8:57pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/30 "2020-12-08T20:57:52Z")

</div>

Awesome. Will do. Thank you!

---

<div class="post-metadata">

**Author:** ![MrChrisRodriguez](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/mrchrisrodriguez/32/11189_2.png) [@MrChrisRodriguez](https://connect.superhuman.com/u/MrChrisRodriguez)\
**Post date:** [December 8, 2020, 11:36pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/31 "2020-12-08T23:36:18Z")

</div>

This. The same semantics already exist in other formulas, and it would allow us to define multiple variables without having to descend into nesting hell.

I understand that nested FormulaMaps were likely a major motivation for this feature (and those would be nested), but simplifying development would also be huge for formula-heavy applications.

I don’t want to trade column-hell for nesting-hell. Give us WithName with support for defining more than one variable!

---

<div class="post-metadata">

**Author:** ![anon26297861](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon26297861](https://connect.superhuman.com/u/anon26297861)\
**Post date:** [September 1, 2021, 8:49am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/32 "2021-09-01T08:49:54Z")

</div>

Hi,

you pointed out a very important fact - the samples shown do generate several new rows and that is not what I am trying to achieve 😉 I am trying to create one (!) new row with several content from other rows which I am filtering and then scanning through with FormulaMap.

Did you find a solution for WithName creating one new row ?

Thanks!

---

<div class="post-metadata">

**Author:** ![Nad](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/nad/32/26972_2.png) [@Nad](https://connect.superhuman.com/u/Nad)\
**Post date:** [September 9, 2021, 1:37am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/33 "2021-09-09T01:37:00Z")

</div>

This a very useful formula that I find myself using quite often. What would make it even better is if it could define multiple names in a similar fashion to SwitchIf or ModifyRows:  
WithName(Value, Name, OptionalValue1, OptionalName1,…, Expression).  
This would come in super handy as the top function in a very complicated calculation to make the code tidy and more readable.  
Also, changing the function now to make multiple names work wouldn’t break backwards compatibility in existing docs - So I really hope Codans consider it.

PS: Excel does the same thing with the Let() function.

---

<div class="post-metadata">

**Author:** ![Nad](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/nad/32/26972_2.png) [@Nad](https://connect.superhuman.com/u/Nad)\
**Post date:** [September 9, 2021, 1:41am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/35 "2021-09-09T01:41:46Z")

</div>

Oops, just saw this was already mentioned here…So yeah, I second @Kenji_Prahyudi 's suggestion!

> [@Launched: Reuse logic and create nested loops with the new WithName() formula](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/14):
>
> Yay this is awesome! smiley I suggest WithName to be able to define more than one name, so it will be like this WithName(value1, name1, [value2], [name2], ..., expression)

---

<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:** [September 9, 2021, 9:48am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/36 "2021-09-09T09:48:17Z")

</div>

@nad you can stack:

```auto
WithName(1 + 1,two,
WithName(2 + 2,four,
  RestOfYourFormula()
))
```

---

<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:** [September 9, 2021, 5:14pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/37 "2021-09-09T17:14:07Z")

</div>

We thought about this when designing the formula. The trouble is that we don’t really have a pattern for `varargs` in the middle of a set of parameters (i.e. if there’s an unlimited set of optional parameters, they kind of have to be at the end). The alternative option was to reverse it and do something like `WithName(expression, name1, value1, [name2], [value2])` but then auto-complete won’t work (you can’t use `name1` in `expression` because you haven’t defined it yet). So we settled on this pattern. We often see people do what @Johg_Ananda mentioned – nest multiple `WithName(..., WithName(...))` calls within each other.

---

<div class="post-metadata">

**Author:** ![Nad](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/nad/32/26972_2.png) [@Nad](https://connect.superhuman.com/u/Nad)\
**Post date:** [September 16, 2021, 12:58am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/38 "2021-09-16T00:58:51Z")

</div>

Fair enough, and I guess it’s a common feature in programming language design to require putting optional arguments at the end of the parameter list.  
I’ll have to settle for nesting WithName as per @Johg_Ananda tip, which still a an improvement over having multiple intermediate columns.

Maybe one day we can have some very light borrowing from imperative languages, a simple assignment operator " [var\_name] := expression" that can be used anywhere in the formula coupled with “return [var\_name OR Expression]” statement at the end of the formula would a godsend for power users.

---

<div class="post-metadata">

**Author:** ![Rushabh\_Doshi1](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/rushabh_doshi1/32/16091_2.png) [@Rushabh\_Doshi1](https://connect.superhuman.com/u/Rushabh_Doshi1)\
**Post date:** [January 20, 2022, 6:47am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/39 "2022-01-20T06:47:39Z")

</div>

This is awesome. It saved the day when trying to figure out nested formulaMaps. Is there anyway to pin this to the beginning of this topic: [Outer CurrentValue access](https://connect.superhuman.com/t/outer-currentvalue-access/8048) so people don’t have to scroll through a ton of comments to eventually discover the solution?

---

<div class="post-metadata">

**Author:** ![Anthony\_Thong\_Do](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/anthony_thong_do/32/23715_2.png) [@Anthony\_Thong\_Do](https://connect.superhuman.com/u/Anthony_Thong_Do)\
**Post date:** [January 23, 2022, 7:24am UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/40 "2022-01-23T07:24:18Z")

</div>

I’ve figured out my own workaround, does this help solve your problem as well?

 ![image](https://global.discourse-cdn.com/coda1/original/3X/e/8/e8da743f5d370aaeed75bc52822135bb84df3be4.png)

---

<div class="post-metadata">

**Author:** ![Kenji\_Prahyudi](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/kenji_prahyudi/32/13074_2.png) [@Kenji\_Prahyudi](https://connect.superhuman.com/u/Kenji_Prahyudi)\
**Post date:** [January 23, 2022, 12:51pm UTC](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900/41 "2022-01-23T12:51:24Z")

</div>

@Anthony_Thong_Do wow man this is genius!! 👏 👏 👏

[Previous page](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900.md?page=1)

[Next page](https://connect.superhuman.com/t/launched-reuse-logic-and-create-nested-loops-with-the-new-withname-formula/19900.md?page=3)
