Sheet Clinic

Make your own Google Sheets function with LAMBDA and Named functions

A bare LAMBDA returns #N/A. Save the overtime pay formula as a named function, OT_PAY(rate, hours), and call it like any built-in.

Sheet Clinic editorsPublished
D2=LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0))

Before as you see it

ABCD
1NameRateHoursGross pay
2Rachel2246#N/A
3Kevin18.538703
4Maria25411037.5
5James2032640
6Linda24441104
7Carlos1940760
8Emily21521218

What changed

  1. OT_PAY saved under Data > Named functions
  2. D2:D8 now call =OT_PAY(B2, C2) and so on down

After one named function

ABCD
1NameRateHoursGross pay
2Rachel22461078
3Kevin18.538703
4Maria25411037.5
5James2032640
6Linda24441104
7Carlos1940760
8Emily21521218
Figure 1. Column D before and after. The long formula and the bare LAMBDA give way to one short call per row.

When it works, column D on the Fixed tab gets weekly gross pay, overtime included, from one short call per row. D2 holds =OT_PAY(B2, C2), and the column reads 1078 in Rachel's row and 1218 in Emily's at the bottom. OT_PAY is not built into Sheets. It is the long overtime formula saved once under Data, then Named functions, with two inputs called rate and hours, and after that you type it the way you would type SUM.

Rate in B, hours in C, and the long overtime formula in D

Row 1 has the headers Name, Rate and Hours in A1:C1 and Gross pay in D1. Rows 2 to 8 list seven people, Rachel through Emily, with an hourly rate in column B and a week of hours in column C. Rates go from 18.5 for Kevin to 25 for Maria, and the hours run from 32 for James up to 52 for Emily, so some rows cross 40 and some do not.

The Broken tab is where the sheet started. Rows 3 through 8 each hold the full formula with their own row number, for example =B3*MIN(C3, 40) + B3*1.5*MAX(C3-40, 0) in D3. It pays the rate in column B for the first 40 hours in column C, and one and a half times that rate for every hour past 40. Six copies of the same logic means six cells to edit if the overtime rule ever changes, and nothing in the sheet ties them together.

Cell D2 on that tab is a first attempt at giving the formula a name. It holds =LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0)) and displays #N/A, and selecting it brings up a red note that reads Function LAMBDA should be followed by a call containing the actual values. It wants the rate and hours right after the LAMBDA, in a second pair of parentheses.

The Broken tab with D2 selected. The formula bar shows =LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0)), D2 shows #N/A, and the note reads: Function LAMBDA should be followed by a call containing the actual values.
Figure 2. The Broken tab. D2 is the only cell in column D without a total.

Saving the overtime formula as OT_PAY(rate, hours)

Open Data, then Named functions, and click Add new function. A sidebar opens with four boxes on its first page.

In Function name, type OT_PAY. Google's named functions page does not allow spaces in the name, and _ is the only special character on its list, so the name is OT_PAY and not OT PAY. In Function description, the copy uses a short line about the 40 hour rule, and Google's page says this text shows up in the function help box. Under Argument placeholders, add rate, press the return arrow, then add hours the same way. Each one is listed below the box with a remove button next to it.

Formula definition takes the calculation itself, written with the placeholders where the cells would go: =rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0). Click Next. The second page shows a preview, OT_PAY(rate, hours), and optional boxes for a description and an example of each argument. Create saves it.

Back on the sheet, =OT_PAY(B2, C2) goes in D2. Fill it down to D8 and each row hands over its own rate and hours. The Fixed tab is that version. Rows 3 to 8 return the same totals the long formula gave on Broken, and Rachel gets 1078 in the row that used to show the error. Carlos, at exactly 40 hours, gets 760 with no overtime, and Emily at 52 hours gets 1218.

The Fixed tab with D2 selected. The formula bar shows =OT_PAY(B2, C2), and column D lists 1078, 703, 1037.5, 640, 1104, 760 and 1218 for rows 2 through 8.
Figure 3. The Fixed tab. Every cell in column D is a short OT_PAY call.

Keep cell addresses out of the definition and pass them in as arguments instead. The same Google page says a range typed into a definition is saved as an absolute reference, so A1:B3 becomes Sheet1!$A$1:$B$3. Written that way, every row would read the same cells.

InputRates in B2:B8, hours in C2:C8, seven rows
Formula=OT_PAY(B2, C2) in D2, filled to D8
Expected1078, 703, 1037.5, 640, 1104, 760, 1218
Sheets returned1078, 703, 1037.5, 640, 1104, 760, 1218 Matches expected
Checked2026-11-11, free personal account

Calling the LAMBDA in place with (B2, C2)

LAMBDA builds a function and stops there. Google's LAMBDA function page lists a LAMBDA with no values after it as a case that returns an error, because the inputs have to follow in a second pair of parentheses. LAMBDA on its own does not create a name.

If the formula only lives on one sheet and a name feels like overkill, the error in D2 has a smaller fix. Put the values right after the closing parenthesis of the LAMBDA, as in =LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0))(B2, C2). Column D of the More ways tab does this in every row and returns the same seven totals as Fixed, from 1078 for Rachel to 1218 for Emily.

The formula bar on any of those cells shows the downside. The whole calculation is still written out in each row, only with names instead of addresses.

MAP over B2:B8 and C2:C8 from a single cell

MAP takes the LAMBDA without the trailing call. E2 on More ways holds =MAP(B2:B8, C2:C8, LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0))). MAP passes each row's rate and hours to the LAMBDA in turn, and the results fill E2:E8 from that one formula. They match column D cell for cell. Google's LAMBDA page explains why there is no error here, since a helper function such as MAP supplies the values itself.

Nothing needs filling down, but the ranges are fixed. A new name added under Emily stays outside B2:B8 until someone edits the formula, while a column of OT_PAY calls only needs one more cell.

The More ways tab with E2 selected. The formula bar shows =MAP(B2:B8, C2:C8, LAMBDA(rate, hours, rate*MIN(hours, 40) + rate*1.5*MAX(hours-40, 0))), and columns D and E both list 1078 down to 1218.
Figure 4. Column D calls the LAMBDA once per row. Column E gets the same numbers from MAP in E2 alone.

Wrong number of arguments to OT_PAY

A named function checks its inputs the way a built-in one does. F2 on More ways calls it with the rate only, =OT_PAY(B2), and shows #N/A with this note: Wrong number of arguments to OT_PAY. Expected 2 arguments, but got 1 arguments. Both placeholders are required, in the order they were added, rate first and hours second.

The More ways tab with F2 selected. The formula bar shows =OT_PAY(B2), F2 shows #N/A, and the note reads: Wrong number of arguments to OT_PAY. Expected 2 arguments, but got 1 arguments.
Figure 5. Leave out hours and OT_PAY returns #N/A instead of a total.

Google's named functions page lists a few more limits on the name. It can't match a built-in function such as SUM, can't look like a cell reference such as AA11, can't start with a number, and has to be under 255 characters. If the file also has a named range with the same name, the named range wins.

OT_PAY belongs to this file. To use it in another spreadsheet, open that one and choose Data, Named functions, Import function, then pick the source sheet and the functions you want. Per the same page, importing a function whose name is already taken replaces the existing one.

OT_PAY comes along when the file is copied. A copy made from a different account returned the same seven totals on its Fixed tab, and the practice fix on Try it yourself worked there too.

The Try it yourself tab starts out as Broken, with the error in D2. Type =OT_PAY(B2, C2) in D2, copy it down through D8 over the long formulas, and the column will match Fixed.

Take-home copy. Four tabs: Broken, Fixed, Try it yourself, More ways. OT_PAY is already defined in it, and it opens as a copy in your own Drive.

Copy the sheet