# Simplify Redundant Expressions

**URL:** <https://connect.superhuman.com/t/simplify-redundant-expressions/33026>\
**Category:** Ask the Community\
**Created:** [August 14, 2022, 6:20am UTC](https://connect.superhuman.com/t/simplify-redundant-expressions/33026 "2022-08-14T06:20:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alyssa\_Gono](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/alyssa_gono/32/28296_2.png) [@Alyssa\_Gono](https://connect.superhuman.com/u/Alyssa_Gono)\
**Post date:** [August 14, 2022, 6:20am UTC](https://connect.superhuman.com/t/simplify-redundant-expressions/33026/1 "2022-08-14T06:20:09Z")

</div>

As a Coda newbie, I found writing formulas complicated. Example, I have the formula below. It has redundant embedded expressions.

If(thisRow.[List of Effective Dates].Count() \<= 1,‘NULL’,WithName(WithName(Sequence(2,thisRow.[List of Effective Dates].count()).FormulaMap(CurrentValue.WithName(i,(thisRow.[List of Effective Dates].Nth(i-1).ToNumber() - thisRow.[List of Effective Dates].Nth(i).ToNumber())\*-1)).Min(),minDate,Sequence(2,thisRow.[List of Effective Dates].Count()).FormulaMap(CurrentValue.WithName(i,(thisRow.[List of Effective Dates].Nth(i-1).ToNumber() - thisRow.[List of Effective Dates].Nth(i).ToNumber()) \* -1)).Find(minDate)),minDateIndex,If((thisRow.[List of Effective Dates].Nth(minDateIndex + 1).Year()-thisRow.[List of Effective Dates].Nth(mindateIndex).Year()!=0),thisRow.[List of Effective Dates].Nth(minDateIndex + 1).Year() - thisRow.[List of Effective Dates].Nth(minDateIndex).Year(),WithName((thisRow.[List of Effective Dates].Nth(minDateIndex + 1).ToNumber() - thisRow.[List of Effective Dates].Nth(minDateIndex).ToNumber())/365,lessThanAYear,[Less Than One Year Gap].Nth(WithName([Less Than One Year Gap].FormulaMap(AbsoluteValue(CurrentValue-lessThanAYear)).Min(),Minimum ,[Less Than One Year Gap].FormulaMap(AbsoluteValue(CurrentValue-lessThanAYear)).Find(Minimum) ))))))

Is there any way, I can simplify it? Its very hard to maintain and debug.

---

<div class="post-metadata">

**Author:** ![Max\_OBrien](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/max_obrien/32/49285_2.png) [@Max\_OBrien](https://connect.superhuman.com/u/Max_OBrien)\
**Post date:** [August 14, 2022, 11:58am UTC](https://connect.superhuman.com/t/simplify-redundant-expressions/33026/2 "2022-08-14T11:58:21Z")

</div>

@Alyssa_Gono

you should break down your logic across several columns. so the redundant code is used once for an intermediate result (column) which can be referenced by the main formula.

you can also use the WithName() function

expression.WithName(X, … )

this will execute the ‘expression’ and assign the result to X so you can refer to X several times in the ‘…’ code that follows.

the scope of X is strictly limited to the code between the parentheses.

these two techniques should resolve your issues

max

---

<div class="post-metadata">

**Author:** ![system](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/system/32/24484_2.png) [@system](https://connect.superhuman.com/u/system)\
**Post date:** [August 17, 2022, 11:58am UTC](https://connect.superhuman.com/t/simplify-redundant-expressions/33026/3 "2022-08-17T11:58:40Z")

</div>

Closed on August 17, 2022, 11:58am UTC

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