# LET Function – Defining Variables in Excel Functions

The LET function allows you to define variables within a formula. There are three main reasons why it’s worth using:

- Positively affects the speed of formula calculations by eliminating unnecessary calculations.
- Makes more complex formulas easier to write.
- Enhances formula clarity.

## Formula Overview

The syntax of the LET function looks like this:

=LET(name1, value1, [name2/value2], …, result)

Where:

`name1`

is the first variable name, must start with a letter.`value1`

is the calculation assigned to the first variable.`name2/value2`

(optional) is the second variable name and its value, arguments entered in pairs.`result`

is the calculation or previously defined variable.

## Using the Function

The LET function allows you to define variables within a formula. Once defined, a variable can be assigned to a static value or a value based on a calculation. The formula can refer to the variable as many times as needed, even though the variable itself is defined only once. Variable values are defined in pairs separated by a comma (or semicolon depending on your Excel settings) as `name1`

and `value1`

. The LET function allows you to define a maximum of 126 variables, with a minimum of 1 pair required. The result of the LET function is always the last argument of the function.

Variable names in the LET function must always start with a letter. It’s important to note that variable names are not case-sensitive. You can use names that contain numbers, such as “count1” or “count2,” but names like “ct1” or “ct2” will cause an error because Excel will interpret them as cell references. Also, remember that you cannot use spaces in defining variable names. Instead, use an underscore (_).

## Use Cases

Let’s explore examples of using the LET function:

- =LET(x, 10, x+1) // The result will be 11

=LET(x, 10, y, 5, x+y) // The result will be 15

As mentioned earlier, the main advantage of using the LET function is simplifying the formula and eliminating unnecessary calculations. An example is using the SEQUENCE function to generate all dates between 01.08.2022 and 15.08.2022 excluding Saturdays and Sundays:

=LET(dates, SEQUENCE(C5-C4+1, 1, C4, 1), FILTER(dates, WEEKDAY(dates, 2)<6))

Notice that the `dates`

variable is used twice in the formula. Once inside the FILTER function and then inside the WEEKDAY function. In the first case, the raw dates from the SEQUENCE function are passed to the FILTER function as the range to filter. In the second instance, the dates from the SEQUENCE function are passed to the WEEKDAY function, which checks the day of the week’s number. The result of the WEEKDAY function is used to filter the original range.

If we hadn’t used the LET function, the SEQUENCE function would have had to appear twice inside the same function. The LET function allowed the SEQUENCE to appear and calculate only once within the formula.

## Summary

In this article, I discussed the LET function, listed its main advantages, explained the formula’s syntax in Excel, and provided practical examples. Excel offers many new functions in the Office 365 package, and I’ll strive to bring them closer to you in future posts.