LET (FirstName, FirstValue, Name..., Value..., Result?) LET (FirstName; FirstValue; Name...; Value...; Result?)

FirstName

The first value name.

FirstValue

The first value.

Name

An additional value name.

Value

An additional value. Values named previously are available here.

Result

The value that should be returned. Values named previously are available here.

Returns

The value of the Result parameter.

Assigns names to values and allows these values to be used in subsequent calculations. LET (First := 2, Second := First + 4, First + Second) LET (First := 2; Second := First + 4; First + Second) returns 8, because the value 2 is assigned the name First , the value First + 4 (6) is assigned the name Second , before First + Second (8) is returned.

LET is a great way to make formulas more readable and to cut down on formula repetition, helping them run faster. These topics are explored in detail below.

Parameters to LET are evaluated from left to right, meaning that values that are given names are accessible to the right of where they are defined, but not to the left of them. In the formula above, the value named First is available where the value for Second is defined, but not vice versa.

A name is defined by writing the name, followed by := and the value. An arbitrary number of these pairs may follow, before the single parameter which defines the result of the LET invocation. := may also be written ,;.

(Being able to use := instead of ,; is not commonly supported by spreadsheets. We think it makes formulas easier to read.)

LET makes formulas more readable

Consider this formula, which calculates the cost of a residential property:

LET (MetricArea := AreaInSqFt * 0.09290304, MetricPrice := 5000, MetricArea * MetricPrice)
LET (MetricArea := AreaInSqFt * 0,09290304; MetricPrice := 5000; MetricArea * MetricPrice)

This formula is intended to be used where the area of a residential property is given in square feet, and available as AreaInSqFt . Only the price in square meters is accessible, though, meaning that the area must be converted first.

It performs the conversion by multiplying the area in square feet by a constant, and gives this value the name MetricArea . (The CONVERT function could also have been used.)

It then defines the price as $5,000 per square meter, giving this value the name MetricPrice . Finally, it calculates the price by multiplying MetricArea by MetricPrice and returns this value.

Performing this calculation without LET is straight-forward:

AreaInSqFt * 0.09290304 * 5000
AreaInSqFt * 0,09290304 * 5000

However, the LET version is arguably easier to understand, as it gives names to all the constituent parts.

Whether the extra clarity makes up for the extra verbosity is a matter of personal preference. Long, complex formulas tend to benefit more from using LET than shorter formulas.

LET cuts down on formula repetition

Some formulas require certain parts to be repeated. With LET, these repeated parts can be written once, which makes formulas easier to read. It also helps them run faster, as the parts that were previously repeated only need to be calculated once.

Consider a formula which uses FILTER to return an array of values which are greater than or equal to 9:

FILTER ({ 2, 4, 6, 8, 10, 12, 14, 16 }, { 2, 4, 6, 8, 10, 12, 14, 16 } >= 9)
FILTER ({ 2; 4; 6; 8; 10; 12; 14; 16 }; { 2; 4; 6; 8; 10; 12; 14; 16 } >= 9)

Unfortunately, which values to include needs to be repeated when providing FILTER with its second parameter. With LET, the solution is simple:

LET (Values := { 2, 4, 6, 8, 10, 12, 14, 16 }, FILTER (Values, Values >= Threshold))
LET (Values := { 2; 4; 6; 8; 10; 12; 14; 16 }; FILTER (Values; Values >= Threshold))

Not only is the formula using LET easier to read and runs faster, it is also shorter.

LET enables definitions to appear only once, instead of being duplicated all over a formula. That makes formulas more maintainable, as the risk of errors creeping in when formulas are updated is reduced.

Examples

LET (First := 2, Second := First + 4, First + Second)
LET (First := 2; Second := First + 4; First + Second)

Returns 8, because the value 2 is assigned the name First , the value First + 4 (6) is assigned the name Second , before ultimately First + Second (8) is returned.

LET (Values := { 2, 4, 6, 8, 10, 12, 14, 16 }, FILTER (Values, Values >= 9))
LET (Values := { 2; 4; 6; 8; 10; 12; 14; 16 }; FILTER (Values; Values >= 9))

Returns the values which are greater than or equal to nine. Without LET, we would have had to repeat the array of values.

LET (MetricArea := AreaInSqFt * 0.09290304, MetricPrice := 5000, MetricArea * MetricPrice)
LET (MetricArea := AreaInSqFt * 0,09290304; MetricPrice := 5000; MetricArea * MetricPrice)

Calculates the price of a residential property whose area is given in square feet as the AreaInSqFt value. The area must be converted to square meters to determine the price. The first part of the formula assigns the name MetricArea to the area, converted to square meters. The second part defines the price, per square meter, and names it MetricPrice . The final part returns the price for the property by multiplying MetricArea by MetricPrice .

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell