Blog Post

Excel Blog
3 MIN READ

Announcing LET

Chris_Gross's avatar
Chris_Gross
Icon for Microsoft rankMicrosoft
Mar 17, 2020

Have you ever had to repeat the same expression multiple times within a formula, created a mega formula or wished that you had a way to reuse portions of your formula for easier consumption? With the addition of the LET function, now you can!

 

Introducing LET

LET allows you to associate a calculation or value in your formula with a name. It's names except on a formula level.

 

The main benefits are:

 

      1. Readability

No more having to remember what a specific range/cell reference referred to, what your calculation was doing or duplicating the same expression within a formula. With the ability to name expressions, you can give meaningful context to readers of your formula.

 

      2. Performance      

If you reuse the same expression multiple times in a formula, Excel calculates that expression multiple times. LET allows you to name the expression and refer to it using that name. Any named expression is calculated only once, even if it is referred to many times in the formula. This can significantly improve performance for computationally complex expressions.

 

The function definition for LET works as follows:


LET(name1, value1, [name2…], [value2…], calculation)

 

  • name1: The name for the 1st value
  • value1: The value to associate with the 1st name
  • name2 (optional): Additional names
  • value2 (optional): Additional values
  • calculation: The calculation to perform. This is always the final argument and it can refer to any of the defined names in the LET.

Deconstructing the parameters, there are two things to make note of

      1. The names and their values must be in pairs.

   For example: 

 

 

=LET(total, SUM(A1:A10), total * 3).

 

 

   In this case, i) total and ii) SUM(A1:A10) are a pair.

 

Taking this one step forward, if we wanted to add another name, we just need to define a new pair...

 

 

=LET(total, SUM(A1:A10), count, COUNT(A1:A10), total / count)

 

 

  1. The last parameter of the function is the calculation which can use the values you named. A properly structured LET will have an odd number of arguments.

  In the prior cases this is “total *3” or “total / count” 

 

Example

Suppose you have some raw sales data, and you'd like to filter that data to show one person, and add a dash to any blank cells.

Unfiltered Data Filtered Data

 

This formula can be authored traditionally using the following formula. However, this formula suffers from a common occurrence where you have to make use of the same expression twice, in this case it’s the FILTER expression.

 

By using a LET we can abstract on this value and even add an addition to fix up the criteria, which in this case is “Fred” but you might want to change to “Amy” in the future or point it at a cell reference.

 

The other thing to make note of is precedence when referencing names; Name definitions can only make use of prior and not subsequent names. For example, you can see that filterCriteria is able to be used by the filteredRange name definition because it comes afterwards.

 

An added benefit of using a LET in this formula is that Excel will calculate this formula 2x as fast with the LET because Excel does not have to repeat the same calculation.

 

Original Formula

=IF(ISBLANK(FILTER(A2:D8,A2:A8="Fred")),"-", FILTER(A2:D8,A2:A8="Fred"))

 

Formula using LET

=LET(filterCriteria, “Fred”, filteredRange, FILTER(A2:D8,A2:A8=filterCriteria),

         IF(ISBLANK(filteredRange),"-",filteredRange))

 

Learn More

To learn more about LET, please check out our help article.

LET Help

 

Availability Notes

LET is now available to Office 365 Subscribers in the Insiders Channel (Beta and Current Channel Preview) and will be available to users of other channels later this year. I’ll update this blog as LET becomes available to more channels. 

 

In the meantime, please provide feedback either in the comments below or through our normal channels and please note the function signature is subject to change based on feedback before moving to further rings.


To stay connected to Excel and its community, read the Excel blog posts and send us ideas and suggestions via UserVoice. You can also follow Excel on Facebook and Twitter

 

 

Chris Gross
Program Manager, Excel

Updated Jul 23, 2020
Version 10.0

59 Comments

  • Interesting; this is what I normally achieve by using a sequence of named formulas.  This has the advantage that, what is in reality a nested formula, appears as a sequence of statements on the worksheet rather than hidden away in name manager.  To be readable it really needs the alt+enter carriage return as SergeiBaklan suggests.  I wonder whether an alternating pattern of separators might help, e.g.

    = LET( 
          salesData := Sales[[Region]:[Profit]],
          modifiedSalesData := IF( ISBLANK(salesData), "-", salesData ),
          FILTER( modifiedSalesData, Sales[Rep]=SelectedRep )
      )

    Perhaps that is too drastic since both colon and equals have existing meanings.  A less drastic variation might be to alternate comma and semi-colon as if building an array constant (semi-colon and backslash in mainland Europe).

     

    I had a quick practice with the function and came to the conclusion that, for me, the most effective way to build a multi-element formula was to start with a single formula and once that checks out, to name it and echo it

    = LET( salesData, Sales[[Region]:[Profit]],
           salesData
       )

    so allowing the overall formula to be built and tested one line at a time.

  • Ute Simon With new functions we go live with an initial translation and then update translations based on community feedback. We've already received some feedback from German language users that they prefer the English LET instead of SEI as this is a programming term. What are your thoughts?

  • JennerQ's avatar
    JennerQ
    Copper Contributor

    I have been waiting for this for FOREVER!!! Thank you so, so, so, so very much!!!

  • excelpbi's avatar
    excelpbi
    Brass Contributor

    Chris_Gross 

     

    Brilliant - Similar to Variables in DAX.

    The Formula team has show enormous vision in the last few months starting with the release of Dynamic array formulas.

    I which some of the vision would rub off on the Power Query and Power Pivot team - which are basically hibernating

     

    With a little bit more vision this would be ever more brilliant

     

    =LET(filterCriteria, “Fred”, filteredRange, FILTER(A2:D8,A2:A8=filterCriteria),

             IFBLANK(filteredRange),"-"))

     

    Oh by the way IFBLANK is already an idea on uservoice

     

    Regards

    Sam

  • jazzista's avatar
    jazzista
    Copper Contributor

    I just used inside the filter function with Boolean logic  and it worked like a charm. This is a great addition to the excel formulas 

     

    =LET(ZeroValue,ISBLANK($H$18),FILTER(C22:F33,(ZeroValue+($D$22:$D$33=H18))*(ZeroValue+($E$22:$E$33=$J$18))))

  • Für alle, die die neue Funktion ausprobieren wollen: In der deutschen Excel-Version heißt diese Funktion SEI.

    (If you are using a German Excel and want to try the new function: LET has been translated to SEI in the German Excel version.)

  • Detlef_Lewin's avatar
    Detlef_Lewin
    Silver Contributor

    Hi

     

    I'm not sure if it is such a progress.

    If it is a complex formula I would use a helper column.

    If it is a test for "equals zero" I would use IFERROR(1/(1/number),value_if_error).

     

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    That is great addition to modern Excel. By the way, with such technique formula formatter is even more demanded

    =LET(
       filterCriteria, “Fred”,
       filteredRange, FILTER(A2:D8,A2:A8=filterCriteria),
       IF(ISBLANK(filteredRange),"-",filteredRange)
    )