Excel LET Function: Transform Your Cell Into a Mini Code Editor
Declare Variables, Create Custom Functions, and Write Cleaner Formulas — All Without VBA!
Start Learning →📑 What You’ll Learn in This Guide
What is the Excel LET Function?
The Excel LET function is a powerful formula that allows you to declare variables inside your Excel formulas — just like you would in any programming language. Introduced in Excel 2021 and Microsoft 365, the LET function transforms how you write complex formulas.
Think of it this way: before LET, writing formulas in Excel was like solving a math problem where you had to repeat the same calculation over and over. Now, you can define a calculation once, give it a name, and reuse it as many times as you need.
Availability: Excel 2021, Excel 2024, Microsoft 365 (Windows & Mac), Excel for the web
Excel LET Function Syntax
The syntax of the LET function is straightforward:
=LET(
name1, value1,
[name2, value2],
...
calculation
)
Parameters Explained:
| Parameter | Required? | Description |
|---|---|---|
name1 |
Yes | Variable name (must start with a letter) |
value1 |
Yes | Value or calculation assigned to name1 |
name2, value2... |
Optional | Additional name-value pairs (up to 126) |
calculation |
Yes | Final calculation using the defined names |
SalesTotal or TaxRate.
Basic LET Function Example
Let’s start with a simple example. Suppose you want to calculate the total price including tax:
Without LET (Repetitive):
=IF(B2*1.18>1000, B2*1.18*0.95, B2*1.18)
Notice how B2*1.18 is calculated THREE times!
With LET (Clean & Efficient):
=LET(
PriceWithTax, B2*1.18,
IF(PriceWithTax>1000, PriceWithTax*0.95, PriceWithTax)
)
Now PriceWithTax is calculated ONCE and reused. This makes your formula:
- ✅ Easier to read
- ✅ Faster to calculate
- ✅ Easier to maintain
“The LET function isn’t just about storing values — it’s about thinking differently. You’re no longer writing formulas; you’re designing logical systems.”
🚀 Advanced: Using LAMBDA Inside LET to Create Custom Functions
Here’s where the Excel LET function becomes truly powerful. Most tutorials only show you how to store values. But the real magic? You can store entire functions as variables using LAMBDA!
This means you can create a custom function inside your formula — define it once, and call it with different parameters. No VBA required!
The Formula That Changes Everything:
=LET( MyVal, F2, MySwitch, LAMBDA(val, SWITCH(val, "a", B3#, "b", SUM(B3#), "c", 300, 0 ) ), MySwitch(MyVal) )
MySwitch — we’re storing a complete custom function that can be called with any parameter!
🔍 Step-by-Step Formula Breakdown
Let’s understand exactly how this LET + LAMBDA combination works:
Step 1: Define Input Variable
MyVal = F2
We declare our first variable MyVal and assign it the value from cell F2. This cell contains a selector value — either “a”, “b”, or “c”.
Purpose: This acts as the “control switch” for our output.
Step 2: Create Custom Function
MySwitch = LAMBDA(val, ...)
Here’s the breakthrough! We’re storing a LAMBDA function as a variable. The LAMBDA accepts one parameter called val and contains our custom logic.
This IS your custom function!
Step 3: Define the Logic
Inside LAMBDA, we use SWITCH to return different results:
- 📌 “a” → Returns the spill range B3#
- 📌 “b” → Returns SUM(B3#)
- 📌 “c” → Returns 300
- 📌 else → Returns 0 (default)
Step 4: Execute the Function
MySwitch(MyVal)
Finally, we call our custom function MySwitch and pass MyVal as the argument. The function executes and returns the appropriate result.
One formula, multiple possible outputs!
🎯 How It Works in Practice
Here’s what happens when users change the value in cell F2:
| F2 Value | Formula Returns | Real-World Use Case |
|---|---|---|
| “a” | Complete data array (B3#) | View all raw data |
| “b” | Sum of the array | Quick total calculation |
| “c” | Fixed value: 300 | Constant/threshold |
| Anything else | 0 (default) | Error handling |
5 Key Benefits of Using the Excel LET Function
1. Improved Readability
Named variables make complex formulas self-documenting. Anyone can understand what TaxAmount means versus B2*0.18.
2. Better Performance
When you use LET, Excel calculates each variable only once, even if you reference it multiple times. This significantly speeds up large workbooks.
3. Easier Maintenance
Need to change a calculation? Update it in one place. No more hunting through a formula to change the same expression in 5 different spots.
4. Reduced Errors
Defining expressions once eliminates copy-paste errors and inconsistencies that creep in when repeating the same logic.
5. Custom Functions Without VBA
By combining LET with LAMBDA, you can create custom functions that work like native Excel functions — no programming knowledge required!
🛠️ Practical Use Cases for LET + LAMBDA
1. Dynamic Report Switching
Let users choose between different aggregations (sum, average, count, max) with a single cell input — exactly like our example above.
2. Unit Conversions
Create a custom conversion function that switches between kilometers/miles, Celsius/Fahrenheit, or any units based on user selection.
3. Financial Scenario Analysis
Switch between “best case,” “worst case,” and “base case” scenarios dynamically without changing the underlying formula.
4. Data Validation Messages
Return different validation messages based on input conditions — all from a single smart formula.
5. Conditional Formatting Logic
Build complex formatting rules as reusable functions that can be applied across multiple scenarios.
LET vs Traditional Formulas: A Comparison
❌ Traditional Nested IF (Hard to Read):
=IF(F2="a",B3#,IF(F2="b",SUM(B3#),IF(F2="c",300,0)))
✅ With LET + LAMBDA (Clean & Modular):
=LET(MyVal,F2,MySwitch,LAMBDA(val,SWITCH(val,"a",B3#,"b",SUM(B3#),"c",300,0)),MySwitch(MyVal))
The LET version may look longer, but it’s:
- ✅ More readable (each component is named)
- ✅ More scalable (easy to add more options)
- ✅ More reusable (the LAMBDA can be called multiple times)
❓ Frequently Asked Questions About Excel LET Function
Q: Which Excel versions support the LET function?
A: The LET function is available in Excel 2021, Excel 2024, Microsoft 365 (Windows and Mac), and Excel for the web. It’s also available in Google Sheets.
Q: Can I use LET to create permanent named functions?
A: Variables created with LET only exist within that specific formula. For permanent named functions, combine LET with LAMBDA and save it in the Name Manager.
Q: How many variables can I create in a single LET function?
A: Excel allows up to 126 name-value pairs in a single LET function.
Q: Does LET improve formula performance?
A: Yes! When you reference a variable multiple times, Excel calculates it only once. This can significantly speed up complex formulas.
Q: Can I nest LET functions?
A: Absolutely! You can nest LET functions, and the inner LET can access variables from the outer LET.
Q: What’s the difference between LET and Named Ranges?
A: Named Ranges are defined in the Name Manager and work across the entire workbook. LET variables exist only within the formula where they’re defined — making them safer and more portable.
“The best Excel users aren’t those who know the most functions — they’re those who know how to combine them creatively. LET + LAMBDA is your gateway to that creativity.”
🎯 Key Takeaways
- LET is your in-cell editor — Declare variables, structure logic, write cleaner formulas
- Variables can store functions — Using LAMBDA inside LET creates reusable custom functions
- Performance matters — LET calculates each variable once, even if used multiple times
- Readability is key — Named variables make complex formulas self-documenting
- No VBA required — Create powerful custom functions with just formulas
Ready to Master Modern Excel Functions?
Join our community of Excel enthusiasts who are pushing the boundaries of what’s possible in spreadsheets!
📧 Stay Connected
Have questions? Want to see more advanced examples?
Drop your thoughts in the comments below!
Your Turn: Try the LET + LAMBDA pattern in your next complex formula. Start simple, experiment often, and you’ll never go back to repetitive nested formulas!
Happy DAXifying! 🚀
