How to Use the MAKEARRAY Function in Google Sheets

Published on

This post is about the MAKEARRAY Lambda function in Google Sheets. It requires a LAMBDA or a Named Function as input.

When I went through the list of the Lambda helper functions BYROW, BYCOL, SCAN, REDUCE, MAP, and MAKEARRAY, I thought the MAKEARRAY was the least helpful LHF. But it does also have the wow factor.

For example, we will get “range must be a single row or a single column” when we try to apply a MATCH formula to an entire table.

=match("Name",A1:D4,0)

Here I could use the MAKEARRAY function in combination with a named function to make the MATCH formula to use every row in a table.

We will see that example at the end part of this Google Sheets tutorial.

I’ve also included an example of expanding a conditional DMAX to every row using this new function.

=dmax($A$1:$C,3,{"Rank";B2})

Dragging this formula (cell spill handle) down will change the cell reference B2 to B3, B3 to B4, and so on. We can make it auto-spill.

All the LHFs are equally important. They have their roles in making our spreadsheet tasks simpler.

MAKEARRAY Purpose: Returns a calculated array of specified dimensions (specified row and column size) by applying a LAMBDA.

MAKEARRAY Function Syntax and Arguments

Syntax:

MAKEARRAY(rows, columns, LAMBDA)

Where;

rows – The number of rows in the output array.

columns – The number of columns in the output array.

LAMBDA – A LAMBDA that takes two names for rows and columns to create the array.

Syntax: =LAMBDA(name1, name2,formula_expression)(function_call, …)

Note:- The highlighted part is not required when using it in the MAKEARRAY function.

name1 – The row index of the array.

name2 – The column index of the array.

Understand the MAKEARRAY Function in Google Sheets

We use the MAKEARRAY function to return calculated arrays, so it’s simple to use.

But you must first understand what it returns in columns and rows without calculation.

Assume the row index is three and the column index is two.

The array without calculation from the perspective of row index:

11
22
33

And from the perspective of column index:

12
12
12

So the output of the following MAKEARRAY formula in Google Sheets will be as per the table below.

=makearray(3,2,lambda(row,column,row*column))
1*1=11*2=2
2*1=22*2=4
3*1=33*2=6

And if you use =MAKEARRAY(3,2, LAMBDA(row, column, RANDBETWEEN(1, 10))), it will return a 3 x 2 matrix filled with random numbers from 1 to 10.

Examples to Understand the MAKEARRAY Function in Google Sheets

How to Use MAKEARRAY With Named Functions in Google Sheets

In the following examples, we will create two Named Functions to expand the result of MATCH and DMAX.

I hope that will make you understand the potential of the MAKEARRAY function in Google Sheets.

1. Match a Value in Every Row

Advanced MAKEARRAY Function Use - Example # 1.

How to match the search key in I2 in B2:G2, B3:G3, and B4:G4?

Usually, we will use the following formula in K2 and drag it down since the MATCH function won’t accept more than one row or column as its range.

=match($I$2,B2:G2,0)

But here in the above example, I created a Named Function called TEST and used that within the MAKEARRAY Function.

The MAKEARRAY formula in K2 that expands the MATCH result to K2:K4 is as follows.

=makearray(3,1,TEST)

And what about the TEST function in use?

Named Function - TEST

The TEST function takes two arguments – r (row) and c (column).

When you use the TEST function stand-alone, you must use three formulas in K2:K4.

They are =TEST(1,1), =TEST(2,1), and, =TEST(3,1).

The MAKEARRAY feeds the arguments within the TEST function at one go as it returns a 3×1 array.

2. Conditional DMAX in Every Row

Here is one more MAKEARRAY function example in Google Sheets to make you understand how useful it is to spill (expand) formula results.

This time we have a database function in use.

Advanced MAKEARRAY Function Use - Example # 2

Problem:

The first three columns in the above table contain employee information such as name, position, and salary.

In the last column, I want to assign the maximum salary drawn in each “position” to each employee.

For example, the maximum salary drawn for position “A” is 38000.

So I want to assign this salary amount to “Anna,” and “David” as they belong to that position.

Solution:

We usually use the following DMAX in cell D2 and copy-paste it down.

=dmax($A$1:$C$6,3,{"Position";B2})

Let’s see how to make it an array formula using the MAKEARRAY function in Google Sheets.

Let’s first create a Named Function called DTEST, which is as follows.

Named Function - DTEST

Then we can use the following formula in cell D2 which will spill down.

=MAKEARRAY(5,1,DTEST)

That’s all. Thanks for the stay. Enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

3 COMMENTS

  1. Oh, awesome! I didn’t realize those other two were so easy! That is a lot simpler structure than the Makearray version. I’ll have to update some of my recent projects to test out those two. Thanks for sharing!

  2. Thanks for the quick and detailed explainer. I’ve taken what you’ve shown and tested that the pattern also works to turn any of the SUM, SUMIFS and other aggregation functions into array formulas.

    The structure is definitely cumbersome and likely too complex for most, but at least it makes it possible. So that is a major improvement.

    For a real game-changer though, turn this into a Named Range, and you can now run GOOGLEFINANCE calls with a single array formula!

    =MAKEARRAY(ROWS(range),1, LAMBDA(r,c, GOOGLEFINANCE( INDEX(range,r,c), "price") ))

    • Hi, McKay Savage,

      Thanks for your feedback.

      We can easily make most of the non-array formulas into array formulas by using the BYROW or MAP functions.

      Instead of the above MAKEARRAY formula, we can use the following BYROW formula.

      =byrow(B2:B10,lambda(ticker, ifna(GOOGLEFINANCE(ticker,"price"))))

      Using MAP:

      =map(B2:B10,lambda(ticker, ifna(GOOGLEFINANCE(ticker,"price"))))

      Where; B2:B10 is that range that contains the ticker symbols or the ‘range’ as per your formula.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.