Ravindra BagaleCourses & study guides मराठी Track your progress

9. Dynamic Arrays

9.18 Named LAMBDA Functions in Name Manager, with Optional Arguments (ISOMITTED)

Example first. In lesson 9.7 you met LAMBDA briefly. Now Ruhi wants a real, reusable function for the team: LATEFLAG should say "Late" when a delivery took more than 15 minutes. But the Kolhapur store uses a 12-minute promise. So the limit must be optional: if you give it, use it; if you leave it out, use 15. We will build LATEFLAG step by step, save it in Name Manager and call it like a built-in function: =LATEFLAG(H2) or =LATEFLAG(H2,12).

Named LAMBDA with optional argument — in 30 seconds

What: A LAMBDA saved in Name Manager becomes your own function with a friendly name. ISOMITTED tells you whether the user skipped an argument, so you can use a default value.

Why: One tested formula, used everywhere by name, is safer than the same long formula copied into 50 cells. Optional arguments keep simple calls simple.

Tiny example: After saving it, =LATEFLAG(H2:H11) marks 3 orders as Late, and =LATEFLAG(H2:H11,12) marks 5.

First look at the data (before → after):

Named LAMBDA with optional argument: before and after tables, fictional Blinkit Maharashtra data

Expected result — J2 and K2 spill

Order ID Mins J: default limit 15 K: limit 12
BLK-1001 9 On time On time
BLK-1002 12 On time On time
AMN-1003 14 On time Late
BLK-1004 11 On time On time
AMN-1005 16 Late Late
BLK-1006 8 On time On time
BLK-1007 18 Late Late
AMN-1008 10 On time On time
BLK-1009 13 On time Late
BLK-1010 17 Late Late
Before table and formula as text

Before — Orders: Mins in column H

A: Order ID H: Mins
BLK-1001 9
BLK-1002 12
AMN-1003 14
BLK-1004 11
AMN-1005 16
BLK-1006 8
BLK-1007 18
AMN-1008 10
BLK-1009 13
BLK-1010 17

Formula / click path

Name: LATEFLAG     Scope: Workbook
Refers to: =LAMBDA(mins,[limit],IF(mins>IF(ISOMITTED(limit),15,limit),"Late","On time"))
J2: =LATEFLAG(H2:H11)      K2: =LATEFLAG(H2:H11,12)

Do it step by step:

  1. Test the logic in a spare cell first: =LAMBDA(mins,limit,IF(mins>limit,"Late","On time"))(16,15) returns Late.
  2. Open Formulas › Defined Names › Name Manager and click New….
  3. In Name type LATEFLAG, keep Scope: Workbook, and in Comment write what it does and its arguments.
  4. In Refers to paste =LAMBDA(mins,[limit],IF(mins>IF(ISOMITTED(limit),15,limit),"Late","On time")) and click OK, then Close.
  5. In J2 type =LATEFLAG(H2:H11). Three orders show Late.
  6. In K2 type =LATEFLAG(H2:H11,12). Now five orders show Late.

Version note

LAMBDA and ISOMITTED are listed for Excel for Microsoft 365 (Windows and Mac) and Excel 2024 (Windows and Mac). The square-bracket style for optional parameters, [limit], was announced on Microsoft's Insider blog; if your Excel does not accept the brackets, write limit without brackets and call the function with an empty last argument, for example =LATEFLAG(H2,). ISOMITTED then still sees the missing value. In Excel for the web you can create names, but Microsoft notes that sheet-level scope is not available there.

How a LAMBDA is built

=LAMBDA([parameter1, parameter2, …,] calculation)

  • The parameters are names for the inputs (mins, limit). Up to 253. No full stop (period) in a name, and do not use names that look like cell addresses (A1, H2).
  • The calculation is the last argument. It uses the parameter names like variables, the same way LET does (lesson 9.6).
  • A LAMBDA typed in a cell without values after it, like =LAMBDA(x,x*2), shows #CALC!. Either call it straight away, =LAMBDA(x,x*2)(5) gives 10, or save it with a name.

The Name Manager fields (Windows)

Field What to type Our example
Name The function name. Use capitals and no spaces. LATEFLAG
Scope Workbook (default) so every sheet can use it. Workbook
Comment Up to 255 characters. Excel shows it as a tooltip when you type the function, so explain the arguments here. Late if mins > limit. limit is optional (default 15).
Refers to The LAMBDA, starting with = =LAMBDA(mins,[limit],…)

On a Mac use Formulas › Define Name.

How the optional argument works, piece by piece

  1. [limit] in square brackets tells Excel that limit may be left out. Optional parameters must come after the required ones.
  2. ISOMITTED(limit) returns TRUE when the user did not give a limit.
  3. IF(ISOMITTED(limit),15,limit) therefore means "15 if missing, otherwise what the user typed".
  4. Microsoft's own ISOMITTED example: =LAMBDA(x,y,IF(ISOMITTED(y),"Missing second argument",x+y))(1,) returns "Missing second argument".

Two more useful functions with optional arguments

Name Refers to Call Result
WITHGST =LAMBDA(amount,[rate],amount*(1+IF(ISOMITTED(rate),18%,rate))) =WITHGST(1000) 1180
WITHGST same =WITHGST(1000,5%) 1050
PCTCHANGE =LAMBDA(old,new,IF(old=0,"",(new-old)/old)) =PCTCHANGE(520,610) 17.31% (format as %)
PCTCHANGE same =PCTCHANGE(0,610) (blank, avoids #DIV/0!)

The 18% default in WITHGST is only a sample rate for practice. Check the correct GST rate for your item with your accountant; this course does not give tax advice.

Editing and testing

  • To change a function, open Name Manager, select it and click Edit…. Every cell that uses it updates.
  • Keep a sheet called Tests with a few calls and the answers you expect (for example =LATEFLAG(16) should be Late, =LATEFLAG(15) should be On time). After every edit, glance at that sheet.
  • A named LAMBDA lives in the workbook. To use it in another file, copy a sheet that uses it into the new workbook (the names come along) or keep a template workbook.

Common problems

What you see Why Fix
#CALC! A LAMBDA in a cell with no values after it. Add the test values in brackets, or save it in Name Manager.
#NAME? Typo in the function name, or the workbook is opened in a version without LAMBDA. Check Name Manager; use Microsoft 365 or Excel 2024.
#VALUE! Wrong number of arguments (too many, or a required one missing). Count the parameters in Refers to.
The brackets [limit] are rejected Your build does not have the optional-parameter syntax yet. Remove the brackets and call with an empty last argument.

How these results were checked: LAMBDA helper functions do not run in LibreOffice, so each expected value was computed in Python and the totals were cross-checked in LibreOffice with classic formulas (SUMIF, running SUM, SUMPRODUCT). Microsoft reference: LAMBDA function, ISOMITTED function. Optional parameters: Microsoft 365 Insider blog.

Practice task (try it before you open the answer):

  1. Create a named function DELIVERYSLA(mins,[promise]) that returns "Within SLA" when mins ≤ promise, and "Missed" otherwise. The default promise is 15.
  2. Use it on H2:H11 with the default and with a promise of 10.
  3. How many orders miss a 10-minute promise?
Answer
  1. Refers to: =LAMBDA(mins,[promise],IF(mins<=IF(ISOMITTED(promise),15,promise),"Within SLA","Missed"))
  2. =DELIVERYSLA(H2:H11) gives Missed for AMN-1005, BLK-1007, BLK-1010; =DELIVERYSLA(H2:H11,10) gives Missed for BLK-1002, AMN-1003, BLK-1004, AMN-1005, BLK-1007, BLK-1009, BLK-1010.
  3. 7 orders: =SUM(--(DELIVERYSLA(H2:H11,10)="Missed")).

Ravindra Bagale's Tip

Always test a LAMBDA in a cell with sample values before you save it. A wrong function saved in Name Manager is hard to find, because the cells only show its name.