How to return a result's position in a 2D array?

jp1981

New Member
Joined
Nov 24, 2010
Messages
6
Hi

I have a list of 107 stocks and have generated a correlation matrix between them (i.e. I have a 107x107 matrix of results).

Next step I have used LARGE() to generate an ordered list of the highest results.

How can I map those results back to the names of the stocks?

i.e. generically, I have two 107x107 matrices, how can I take a result from one matrix and return the analogously-positioned result from the other matrix?

or another way of looking at it is how to return a result's grid ref {X,Y} from a matrix?

The only thing i've thought of is for each row or column take a slice of the 1st, 2nd, 3rd highest results but that relies on me not looking to return that many results as it isn't scalable (i'm probably looking at the top 400 results from this ~11000 result matrix).

Please help...
 
My solution is pretty simple: given dataRange in A2:C4

The array ROW(dataRange) is

2 2 2
3 3 3
4 4 4

+1

Nice formula with Sumproduct.

Not sure if I am missing something here, but the formula =ROW(A2:C4) in excel will give an array of

2
3
4

In order to generate:


2 2 2
3 3 3
4 4 4

I had to slightly modify the formula to =ROW(A2:C4)*{1,1,1}

FYI, for anyone still reading this old thread.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
The --(dataRange=12) part is a two-D array that, by multiplication, will spread the (1-D) ROW(DataRange) out to two dimensions.
 
Upvote 0
Thanks Mike, I completely missed the asterisk symbol and ended up separating the ROW() part into another array.
 
Upvote 0
hey guys, I know this thread is ancient, but I wanted to pass along that all the solutions are very clever and useful. The formula versions, at least, work with strings as well. Great way to find indices in 2x text table. So thanks.
 
Upvote 0
I am trying to make this wonderful solution using SUMPRODUCT work with Structured References with Tables so I can add a column to the table with results from the SUMPRODUCT. Following are my efforts. On the left are the answers I get. On the right are the formulas used. $Q$2 is one of the table entries. In the table to be modified, it becomes [@Subj]. All table elements are unique. I don't know why I get different answers with structured referencing and traditional ranges, as shown below. I am new to Tables so may be missing a subtlety.

How many there are of $Q$2
1=SUMPRODUCT(--(tblSubjectsByCollege[#Data]=$Q$2))
1=SUMPRODUCT(--($G$2:$O$51=$Q$2))
Find first column of the data range
7=COLUMN($G$2:$O$51)
7=COLUMN(tblSubjectsByCollege)
7=COLUMN(tblSubjectsByCollege[#Data])
Find the column of the found cell
7=SUMPRODUCT(--(tblSubjectsByCollege[#Data]=$Q$2))*COLUMN($G$2:$O$51)
7=SUMPRODUCT(--(tblSubjectsByCollege[#Data]=$Q$2))*COLUMN(tblSubjectsByCollege)
9=SUMPRODUCT(--($G$2:$O$51=$Q$2)*COLUMN($G$2:$O$51))
1=SUMPRODUCT(--(tblSubjectsByCollege[#Data]=$Q$2))*COLUMN(tblSubjectsByCollege)-COLUMN(tblSubjectsByCollege)+1
3=SUMPRODUCT(--($G$2:$O$51=$Q$2)*COLUMN($G$2:$O$51))-COLUMN($G$2:$O$51)+1

<tbody>
</tbody>
 
Upvote 0
I found the answer, thanks to Charley Kyd:

How to Use SUMPRODUCT to Create Two-Dimensional Lookups in Excel Formulas

Here are his formulas applied to my table which contains unique entries:

ResultsFind Subject, where Subject is a named cell containing the search term.
Row #16=SUMPRODUCT(ROW(tblSubjectsByCollege[#Data])*(tblSubjectsByCollege[#Data]=Subject))-ROW(tblSubjectsByCollege[#Data])+1
Column #9=SUMPRODUCT(COLUMN(tblSubjectsByCollege[#Data])*(tblSubjectsByCollege[#Data]=Subject))-COLUMN(tblSubjectsByCollege[#Data])+1

<tbody>
</tbody>

<tbody>
</tbody>

The row and column numbers are with respect to tblSubjectsByCollege[#Data], not the worksheet.

Note that instead of using SUMPRODUCT(--Data=FindVal), he uses SUMPRODUCT((Data=FindVal)*1) to turn TRUE/FALSE into 1/0. For me, the result is much easier to understand.
 
Upvote 0
How would the formula differ if the entries are not unique? Essentially, I'm dealing with a dataset with a look-up table that I've brought in (bad practice, I know). So the row values are *not* unique, but each value will be in one and only one column. I'm trying to find that column index. But I don't know which row it might be in.
 
Upvote 0
wiz329
I'm not sure what your situation is.

You have a 2-D range of cells, there is only one column that has "soughtValue" in it, but there might be many rows in that column that contain "soughtValue".

Is that your situation?
 
Upvote 0
wiz329
I'm not sure what your situation is.

You have a 2-D range of cells, there is only one column that has "soughtValue" in it, but there might be many rows in that column that contain "soughtValue".

Is that your situation?

Correct.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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