In this guide, we’ll see how to use the LET function in Excel and why it’s so important for making our files, especially those with complex formulas, easier for the end user to read.
LET allows you to declare variables within formulas and is an essential function for working effectively with Excel for Microsoft 365, as it changes the way we think about formulas: no longer just as output, but also by defining the various logical steps that lead us to the conclusion.
The other advantage is a matter of speed, since the variable is calculated only once. If we avoid calculating the same operation 10 times, Excel will certainly be faster at completing the processes we’re creating. This is particularly relevant if certain references are reused multiple times in the formula, as you become more proficient with Excel, you’ll notice cases where you have several repeated combinations, and optimizing with LET will come naturally to you.

LET is a key function for anyone who wants to improve their Excel skills, and I use it extensively in all my work files, as well as in numerous guides you’ll find on this site. LET cannot be used in versions up to Excel 2019, as it is available starting with Excel 2021, in general, I recommend upgrading to the 365 version, if possible, which includes all the latest updates.
What Does the LET Function Do in Excel
The LET function in Excel allows us to declare variables that we’ll then use within our formula. If you have a background in programming (including VBA), you’ll have no trouble using it right away in your files, since it’s similar to what you see in many other development environments. For those who’ve never used these variables before, let’s consider why they might be useful.
Excel tries to help us this way when we start typing:
=LET(name1,name_value1,calculation_or_name2,[name_value2,calculation_or_name3],….
It goes without saying that it’s not entirely clear what we’re supposed to do. However, the suggestions as we type clarify aspects that will become relevant when we start using it extensively:
- Name1 tells us that we need to choose a name for our first variable
- Value_Name1 indicates that we need to specify what this Name1 corresponds to
- Calculation_or_Name2 indicates two possibilities: either there is a calculation that completes our formula, or we can declare a new variable called Name2 and continue
Let’s imagine we have two values, for example, price in D4 and sales tax in E4. We want to multiply them. One possible formula would be:
=(D4)*(1+E4)
Another possible formula, using LET, would look like this:
=LET(price,D4,
vat,E4,
price_with_vat,price*(1+vat),
price_with_vat)
The result is the same, but the explanation of the individual steps is much easier to understand.
Let’s explore this topic further with an example. Let’s try calculating the percentage margin, with and without LET.
How to Use LET in Excel with a Practical Example

Let’s see how to use LET in Excel with a practical example. In this case, we’ll calculate the percentage margin, which is calculated as (price − cost) / (price). If we didn’t use LET, we’d get:
=(B3-C3)/B3
The result is correct because we have (100 − 30)/(100), which actually equals 0.7, or 70%.

However, the problem of understanding clearly arises if we open the formula from a random cell in our worksheet. In fact, it’s impossible to tell what B3 is and what C3 is, since we have no reference to understand the formula’s operation in more detail.
Let’s see what the result would look like if we made the best use of LET:
=LET(price,B6,
cost,C6,
margin,B6-C6,
margin_pct,margin/price,
margin_pct)
Now, the formula is definitely longer, so we sacrifice a bit of brevity, but gain in clarity, since:
- Price is B6
- Cost is C6
- Margin is simply the difference between Price and Cost
- Percentage Margin is Margin/Price
Even if we were to open this formula elsewhere on the sheet, even without fully grasping how it works (we don’t know what this margin corresponds to), we’d still be able to understand that we’re talking about a percentage margin and not other KPIs.
Now let’s see how LET can help us if we want to find the top X customers in a database.
How to Use LET in Excel with a Complex Example

Let’s see how to use LET in Excel with a more complex example, which involves creating a statistic based on our top customers. We have a database in a table called TBL, which contains two columns: Customer and Price.
The proposed solution was developed before the introduction of GROUPBY, which greatly simplifies this process, if you’d like to learn more about the GROUPBY function, take a look here.
We want to retrieve our top X customers in a single step, allowing the user to select a value, which could be 5, 10, or 25, from a cell.
Let’s look at the formula without using LET:
=TAKE(SORT(HSTACK(UNIQUE(TBL[CUSTOMER]),
SUMIFS(TBL[PRICE],TBL[CUSTOMER],UNIQUE(TBL[CUSTOMER]))),2,-1),C2)
In this case, the formula is hard to read:
- Let’s start with the core of the formula. We can see that there are values stacked using STACK, but note that TBL[CUSTOMER] is repeated three times: twice with UNIQUE and once on its own. We’re stacking, horizontally, the unique customer values and then the total price for each of them, creating a two-column array
- We see that the data is sorted by total price in descending order (2 is the price column; -1 means descending) and is contained within a stream that isn’t entirely clear
- Finally, TAKE tells us that we’ll take only a certain number of rows related to C2. So we’re taking two columns with the unique customer values and their prices, sorting them by the price column in descending order, and then taking only a user-specified number of rows. Visualizing the result of this formula before calculating it is far from simple
I’ll start by saying that using LET is essential, but it’s up to you to decide exactly how to apply this function to your files. You can get extremely specific, for example by specifying a text label for each column you’ll use. You can take a quicker approach, perhaps using it only for certain particularly complex steps. I often use descriptive words within the LET parameters to distinguish them from the function names, but here, too, you have complete freedom to modify the logic as you prefer.

I’ll show you how I would do it if I had to explain the process to my team members, perhaps as a starting point for creating a dedicated LAMBDA. Let’s review the process, step by step:
- First, we want to obtain the unique customer values
- Next, we want to calculate the total price for our unique customer values
- At this point, we create a two-column array containing the unique values
- We then need to sort this array by the second column in descending order
- Finally, we select only the number of rows corresponding to the topX we’re interested in

Let’s look at the formula step by step, specifically:
=LET(customers,UNIQUE(TBL[CUSTOMER]),
total,SUMIFS(TBL[PRICE],TBL[CUSTOMER],customers),
stack,HSTACK(customers,total),
stack_sort,SORT(stack,2,-1),
final_stack,TAKE(stack_sort,C2),
final_stack)
At this point, let’s evaluate the individual steps:
- "Customers" refers to the unique customers in our database
- `Total` returns the total price for each unique customer, who are now referred to as “customers” rather than by the placeholder `UNIQUE`
- `Stack` indicates that we are creating a horizontal array with two columns: `clients` and `total`. We will therefore have `CARUSO | 306,469 €` and so on, for all our clients
- `Stack_sort` sorts our stack, clearly indicating that we are modifying it to sort by total, which is the second column of our array
- Final_stack is the final step, where, using TAKE, we’ll retrieve only the specific number of rows we need
At this point, let’s write `final_stack` again because that’s the value we want to return. This step is crucial, and I’ve underestimated it in the past, but it’s always better to explicitly state the final calculation rather than just ending the formula. Let me give you an example:
=LET(customers,UNIQUE(TBL[CUSTOMER]),
total,SUMIFS(TBL[PRICE],TBL[CUSTOMER],customers),
stack,HSTACK(customers,total),
stack_sort,SORT(stack,2,-1),
TAKE(stack_sort,C2))
This formula returns exactly the same result as before, but we’re not explicitly stating that this is our final stack. Therefore, I always prefer the first option, partly to make it clear to the user that this is a defined sequence that ends precisely with this parameter.
When to Use the LET Function in Excel
You might be wondering when it makes sense to use the LET function in Excel. As I’ve mentioned elsewhere in this guide, I use it in practically all my files, since it greatly aids understanding, not only for others but also for myself.
LET can come in handy in several situations:
- If you need others to use a file you’ve created, they’ll already have a clear and detailed explanation of each step. If you want, you can always use ChatGPT to have the steps explained, but with LET, everything will definitely be easier
- If you need to revisit one of your files after some time has passed, LET will help you quickly get back into the concepts you used when creating the file. I’ve had to reopen files I created months earlier on several occasions, and LET has been immensely helpful in reviewing the processes and, if necessary, improving them
- If you want to improve your Excel skills, LET is an essential step. This is because, when you create formulas without LET, you risk repeating the same operations numerous times, resulting in complex formulas that are difficult for a third party to understand and lack structure. If, on the other hand, you think in terms of LET, these same formulas, which at first may seem complex and inefficient, will instead become much clearer and help you develop “muscle memory” that you can apply to other workbooks as well
- If you want to learn how to create custom Excel functions, that is, LAMBDA functions, you simply must use LET. This is because LET is the first necessary step to define what information the user must enter, and declaring it correctly will help you create functions that are easy for others to use as well. Without LET, LAMBDA risks becoming a black hole of slow and complex formulas, which could be completely different if broken down into separate sections using LET
In summary, there are no reasons, other than compatibility with versions prior to 2021, not to use LET. The only issue worth exploring, which we’ll cover shortly, is when variables can interfere with Excel’s native functions.
When using LET can cause problems in Excel
LET shouldn’t cause any problems when working with Excel, since it’s a valuable tool for our formulas. However, there are some edge cases to consider, particularly with function names that contain a period. I’ve discussed this topic in the past with my friend Roberto Mensa (an Excel MVP whom I recommend you follow because he creates incredible charts), and, thanks also to other experts like Bo Rydobon, we’ve discovered the following.
Some Excel functions include a period (.) in their name, such as STDEV.S, NORM.DIST, T.DIST or PERCENTILE.INC. In and of itself, this isn’t a problem. It becomes a problem if, as a variable for LET, we use what comes before the period and then call that function in the same formula.
I therefore recommend that you avoid variable names such as stdev, norm, t or percentile. The formula will still work, but only as long as you don’t use, in the same formula, a function whose name starts with that word followed by a period. In short, you can name a variable “stdev”, but if you then use STDEV.S in the same LET, Excel returns an error.
Let’s look at a practical example. Let’s say we want to take the top X price values from our database using this formula:
=LARGE(TBL[PRICE],
SEQUENCE(B1))
Enter the values in B1, there are 5 in this case, and complete the formula.
But suppose we want to see them in separate rows instead of a column, in that case, we could use this formula and be all set:
=LARGE(TBL[PRICE],
SEQUENCE(,B1))

But suppose we want to do this using a function called TOROW, which allows us to place all the values on a single row:
=LET(values,B3#,
row,TOROW(values),
row)
We take all the values from B3# and simply transpose them into a row. No problem.

Now let’s calculate the standard deviation of the same values, naming the variable `stdev`:
=LET(stdev,B3#,
result,STDEV.S(stdev),
result)
The formula returns #FIELD!. This is quite frustrating because it’s unexpected, but it happens because Excel reads STDEV.S as a field of the variable stdev (in fact, it rewrites it as stdev.S) instead of the function. With `values` as the name, the same formula returns the standard deviation without any problem.
Keep this in mind when you copy formulas written in other language versions of Excel: function names change from one language to another, so a LET that works in one version can break in another. In the Italian version, for example, TOROW is A.RIGA, so a variable called a breaks it.

Another thing to watch out for is, for example, creating variables like =LET(sum_%,...). If you use certain special characters, Excel won’t accept the formula and shows the message “There’s a problem with this formula.” Again, the problem is the name of the variable, but if you use only text values that clearly declare the variables, you shouldn’t encounter any particular issues.
Conclusions
LET is an essential function for working effectively with Excel because it clarifies the scope of the task and the individual steps in a practical and efficient way. I recommend using it in all cases involving complex formulas, especially if certain elements or calculations are repeated, or to enhance the training of internal staff on existing files.
Artificial intelligence makes extensive use of LET because it allows certain calculations to be sped up and made more compact, just be careful not to overuse it; “megaformulas” are sometimes worse than many formulas combined!
