What is LAMBDA? 4 Practical examples to REALLY understand it

Share

Facebook
Twitter
LinkedIn

Ladies & gentlemen… Excel has a new function. LAMBDA()  is the new addition to Excel’s family of functions. Using LAMBDA, we can create custom & reusable functions in Excel. 

In this article, learn all about:

  • What is LAMBDA()
  • How to create LAMBDAs in Excel?
  • How to re-use LAMBDAs
  • 4 Practical Examples of LAMBDA
  • What are LAMBDA helper functions?
  • Sharing LAMBDAs with others
  • How LAMBDA compares with other custom function options in Excel?

LAMBDA - Who can use it?

LAMBDA() and other lambda helper functions are available in below formats of Excel only.

  • Excel 365
  • Excel on the Web
  • iOS & Android Excel

If you are using an older version of Excel (Excel 2019 / 2016…) then you can test and practice LAMBDA from Excel on the web. Just go to https://excel.new

What is LAMBDA & How to create it?

LAMBDA (pronounced lam-duh) allows us to write our own functions and add them to the library. 

For example, here is a very simple LAMBDA to subtract one value from another.

				
					=LAMBDA(a, b, a-b)
				
			

To call this LAMBDA, you can use the below syntax.

				
					=LAMBDA(a, b, a-b)(90, 12)

' The result will be 78
				
			

Here is a quick demo of our subtraction LAMBDA…

How to use LAMBDA in Excel - Video

I made a video about LAMBDAs. Please watch the video for a bit more explanation and demos. (Watch on Youtube).

How to "install" & "reuse" LAMBDA?

The TRUE Power of LAMBDA is unleashed once you “install” or “setup” them. To install out subtract lambda, 

  1. Go to Formulas ribbon and click on “Define Name”.
  2. Type a name for the lambda, such as subtract
  3. In the “Refers to:” area of the name, type your lambda. For ex:
    1. =LAMBDA(a, b, a-b)
  4. Click OK. 
  5. That is all. Our SUBTRACT LAMBDA is setup.

To call the lambda, just go to any cell and type the =subtract formula and provide parameters a & b as you normally would.

How awesome is that. 🤩

Here is a quick demo of the LAMBDA setup process.

Practical Examples of LAMBDA

Let’s be honest. No one needs the SUBTRACT function. We can already do that with the – (minus) operator. So in this part of the article, let me present some practical LAMBDAs. 

 

Calculating weighted averages is a pain in Excel. There is no built-in function to do the task. Well, we can make our own WAVERAGE() function, thanks to LAMBDA().

Define WAVERAGE name as

=LAMBDA(values, weights, SUMPRODUCT(values, weights)/ SUM(weights))

Here is how you can use it to correctly calculate weighted average of salaries.

weighted average lambda

Let’s say you have a list of values and just want to get the “topn” values in descending order. We can set up a LAMBDA to do that magic.

Define TOPN name as

=LAMBDA(values, n, LARGE(values, SEQUENCE(n)))

We can call this LAMBDA like:

=TOPN(a1:a10, 3) to see top 3 values in the range A1:A10.

Excel has the excellent TODAY() function to tell me what is the current date. But there is no TOMORROW()?

Let’s fix that with LAMBDA.

Define the name tomorrow as,

=LAMBDA(TODAY()+1)

And, you can call it by writing =TOMORROW() in any cell. Works like magic…

You can write complex Date logic to figure that out. But who wants to write the same formulas every time. This is the job for LAMBDA.

Define FirstMonday as,

=LAMBDA(anydate,
LET(som, DATE(YEAR(anydate),MONTH(anydate),1), CHOOSE(WEEKDAY(som),1,0,6,5,4,3,2)+som))

And to get the first Monday of any month, you can use =FIRSTMONDAY(any date)

For example, =FIRSTMONDAY(“1-jan-2022”) will be 3-Jan-2022 (which is the first monday).

What are LAMBDA "helper" functions...?

Apart from LAMBDA, Microsoft also introduced a bunch of helper functions so we can truly build any kind of LAMBDAs in Excel.

These are,

  • MAP – to map (or apply) a LAMBDA to a range of values and return a range of outputs.
  • REDUCE – to take a bunch of values (or lambda outputs) and reduce them to a single value
  • SCAN – Returns intermediate results of applying a lambda on an array – one step at a time.
  • MAKEARRAY – gives you an array of specific size (rows by columns) by applying the lambdas
  • BYCOL – applies a lambda function to a range, one column at a time and returns a row of outputs.
  • BYROW – revers of BYCOL…

Read more about the LAMBDA Helper functions here.

How to "share" LAMBDAs with others?

By default, any LAMBDA you create is only available in the workbook. To share LAMBDAs across files or with other users, you can try:

  • Simpler option: Email or share the files with others. When they open the file, they can see & use the LAMBDAs in that file or copy paste the names to their own files.
  • Better option: You can use the newly added “Advanced Formula Editor” to share and centrally publish lambdas (with Github). This is for advanced users only. You can get the add-on here.

Download - Excel LAMBDA Examples

Click here to download sample workbook with 4 LAMBDAs. Play with the functions or make your own.

How does LAMBDA compare with UDFs?

Seasoned users of Excel know that we already have the ability to create and share our own functions. It is called user defined functions (or UDFs). 

Here are some points on how UDFs compare with LAMBDA.

  • UDFs rely on VBA (or add-ins). If you disable the add-in or don’t load the VBA code, then the UDF won’t work.
  • LAMBDAs are part of core Excel, so they will run without any permission or loading.
  • UDFs are easy to share, but LAMBDAs have no such option yet.
  • UDFs work in all desktop versions of Excel. LAMBDA is on available in Excel 365 but they also work on Excel on Web & on apps.
  • UDFs let you access Visual Basic object model (restricted) and do things on your spreadsheet that are not possible with formulas (for ex: extract comment in a cell or find the color of a cell). 

 

Learn more about LAMBDA in Excel...

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

19 Responses to “Free Invoice Template using Excel – Download”

  1. Doug H says:

    Nice post! Invoicing for the small biz or solo entrepreneur is something I see a lot of interest in. Also there are great templates from http://office.microsoft.com/en-us/templates

  2. Abhay says:

    This is awesome.

    I would need a little more. e.g. say I generate a Inv. # 1 with all the details. Once done I can click a button all the relevant details gets stored in some table. Further, when i generate a new invoice those details gets stored in same table but just below the previous invoice.

    Is their a way to do this?

  3. Hui... says:

    Daily dose of Excel held a competition in 2005 for this same topic
    It obtained 9 solutions which are shown:
    http://dailydoseofexcel.com/archives/2005/10/27/invoice-app-the-results/

  4. parimal says:

    How can i removed Dollar Sign, As want to use this in india.
    Please reply.

  5. parimal says:

    Also if possible then can i use Indian Rupee Sign and how?

  6. Gaurang Mhatre says:

    Hi Chandoo,

    Thanks for sharing this invoice template, Let me tell you this template will definitely help me since I got a process to handle where this invoice piece comes. Just a small doubt, can we store all the invoice details in PRODUCT & SERVICES sheet. So that whenever I select an invoice number from invoice sheet I can take print out and I can share it as well. Can we do that?? Since I will be dealing with this on monthly basis.
    It would be great if you can help me with this.

    Thanks in advance for your help!

    Regards,
    Gaurang Mhatre

  7. shrikant says:

    Hi Chandoo,

    I was thinking learning excel is quite tuff task but your blog proved me wrong. You made it very interesting. Thank you. Also the template you have provided for Invoice is very helpful to us.

  8. AKIN KARAMAN says:

    Thanks thanks thanks.. Very helpful. 🙂

  9. Trevor Gordon says:

    Hi i love the speadsheet but would like to ask how do i get it to add the description into the invoice as well

  10. Anuj says:

    Hi Randy, I tried to download one of your link "https://www.dropbox.com/s/2yvo0o2tgq9quhe/Medical_Massage_and_Salon_Application-Free.xlsm" However, i found the link unavailable. Can you please help me get the new link or can you please send this VBA file on my Email-ID.

  11. Kapil says:

    Hi, is there any chance that this can work with the "Products & Service" sheet outside of the Invoice sheet. I create multiple invoice files for the numerous clients. Updating the product sheet for each of them maybe a task. Hence, I want to create a MASTER FILE from which data can be picked up without having to insert new data in each of the invoice files.
    Possible? Or am I asking for the moon 😉

  12. Kadr Leyn says:

    Thank you so much for tutorial.
    This example can be reviewed for the example of the advanced invoice that made with excel userform :https://youtu.be/Qr-4of-38DI

  13. Trevor Gordon says:

    Good Day
    i love this template may i ask if it could be modified to have the following
    when you lookup a item code in the next column to the right it brings up the description then the quantity, unit cost, discount and then total otherwise i love the template

    Item Code Description Quantity Unit Cost Discount Total

  14. Denise Konopka says:

    When creating an Invoice template in Excel are you able to utilize the auto row height and wrap feature when the cell is a merged cell? I need to have a number of cells merged together to allow for enough space to type in the description of work performed (lets say cells A-D are merged in each row) however it seems that I am unable to utilize the auto format feature. To work around this I have to manually increase the row height after each entry. Is there a better solution for this? Thank you!

Leave a Reply