UNIQUE of Rectangular Range Using MAKEARRAY in Excel - 2416

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Jul 31, 2021.
Another new LAMBDA helper function in Excel is MAKEARRAY. This video shows a simple example, and then tackles the problem from episode 2317 of how to unwind a rectangular range into a single column so you can pass it to UNIQUE and SORT.
The formula used in the video is:
Excel Formula:
=LET(array,B2:G15,
rowcount,ROWS(array),
colcount,COLUMNS(array),
itemcount,rowcount*colcount,
MAKEARRAY(itemcount,1,
LAMBDA(r,c,
INDEX(array,
LET(a,MOD(r,rowcount),IF(a=0,rowcount,a)),
ROUNDUP(r/rowcount,0))
)))
maxresdefault.jpg


Transcript of the video:
Learn Excel from MrExcel Podcast episode 2416.
Unique of a rectangular range using the brand new MAKEARRAY array function.
Hey, welcome back to the MrExcel netcast. I'm Bill jelen.
We've been talking about these new Lambda helper functions.
We already talked about MAP, REDUCE, SCAN, BYROW, and BYCOL.
Today I want to talk about MAKEARRAY and when I saw this one, I thought, “oh, let's revisit this nine minutes and 48 seconds of hell getting the unique on a rectangular range”.
It had a lot of methods including this one by my friend Liam. Just a terrible way to go.
Alright MAKEARRAY is very simple. How many rows do you want?
How many columns do you want? And then what's the logic? What's the formula?
For each intersection of row and column.
So here we're doing 12 rows by 5 columns and then the LAMBDA function needs R and C – row and column.
And what the calculation is.
Now, the classic one is R times C to create a multiplication table. But it can be anything.
Two times R divided by C. Whatever you need.
The complex method here and this is the one in the video.
We had a rectangular range of data that I wanted to get a unique of all the items there.
Not on a “by row” basis.
So the question was how to unwind this into a single column so we can pass it to UNIQUE.
And the formula that lets me do that is this one.
So we use the LET function, assign the Array to be A2:G15.
Count how many rows there are using the ROWS function.
Count, how many columns there are using COLUMNS function. And then how many total items there are.
In this case, it's 84 items using RowCount times ColumnCount.
Now here's where it MAKEARRAY pops in.
I'm going to create an array that is 84 columns tall in one column wide.
And then the calculation is going to be a Lambda and pass it R and C.
Now C is going to be one every single time, so we're not even going to use C in this. It's just which row are we trying to figure out.
And then this becomes a nice little dance here of trying to figure out which row we want to get the data from and that's using the MOD function.
You always have to worry about the mod of 14 / 14 is going to be 0 instead of 1, so there's a little if statement here.
If A is equal to 0, then use 14. Otherwise the calculation of A.
To get the column we're going to do our WhichRow here divided by the RowCount.
Rounding up that makes sure that we get to the right column.
And what we get is in the 1st 14 items Orange through - I don't know how to pronounce that is that Xigua?
Orange through Xigua appears and then we start Banana from column two and it unwinds.
Now once we get that whole thing then it's just simple to wrap the whole formula in UNIQUE.
There is a unique list and then to sort that, just add a sort function. Like that and the sorted unique list.
I don't know if this is any better than any of the methods in the nine minute and 48 second video, but the one advantage this video is a lot shorter and you can get on with your day.
If you like these videos please down below, click Like, Subscribe and Ring the bell.
Feel free to post any questions or comments down in the comments below.
Thank you for stopping by and we'll see you next time for another netcast from MrExcel.
 
Last edited by a moderator:
I get a syntaxical error suggesting I need to use an apostrophe at or around the 'r' in the LAMBDA function. What do you think I'm doing wrong?
 
I get a syntaxical error suggesting I need to use an apostrophe at or around the 'r' in the LAMBDA function. What do you think I'm doing wrong?
Here is the formula I am using:
=UNIQUE(LET(array,B3:E693,
rowcount,ROWS(array),
colcount,COLUMNS(array),
itemcount,rowcount*colcount,
MAKEARRAY(itemcount,1,
LAMBDA(r,c,
INDEX(array,
LET(a,MOD(r,rowcount),IF(a=0,rowcount,a)),
ROUNDUP(r/rowcount,0))
))))
 
I can confirm that your formula works without problems on my computer.

Excel Formula:
=UNIQUE(LET(array,B3:E693,
    rowcount,ROWS(array),
    colcount,COLUMNS(array),
    itemcount,rowcount*colcount,
    MAKEARRAY(itemcount,1,
        LAMBDA(r,c,
            INDEX(array, LET(a,MOD(r,rowcount),IF(a=0,rowcount,a)), ROUNDUP(r/rowcount,0))
        )
    )
))

Note: Next time try to use Excel Formula BBCode on the toolbar (the first code button named as XLS) as it will make your formula more readable and also easy to copy.
 
Ok. I wonder why my result shows this error? Ideas? The formula breaks at the r in the LAMBDA line.

mrExcel rect array formula.JPG
 
Are you sure you are in the Beta channel? The error makes me think you don't have the LAMBDA and/or MAKEARRAY functions in your Excel installation.

You need to join the Office Insider program and select the beta channel for updates to be able to test the new functions since they are not public yet.
 
My apologies. I've been surfing the web for days trying to find a solution for this issue and came across this formula. I did not realize the LAMBDA and MAKEARRAY functions were Beta. I've now joined Office Insider and I'm certain once I get my Office365 update the formula will work as expected. I'll let you know one way or the other. Really appreciate you're patience with me.
 
No problem at all.

It sometimes takes longer for some subscribers to get the updates on the Beta channel, however, you should get these two functions (LAMBDA and MAKEARRAY) should be installed as soon as you update the Office after you join the Insider program.

Right, I tested it and your formula generates results although I didn't analyze if the result is the expected one or not.
 

Forum statistics

Threads
1,221,532
Messages
6,160,381
Members
451,643
Latest member
nachohoyu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top