Explanation of a formula

Richards440

New Member
Joined
Feb 24, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am currently working on a large data set. I took the 10 largest values within this data set using the large formula. After this I wanted the area these values came from and found this formula online, =INDIRECT(ADDRESS(1,SUMPRODUCT((B1:M9=A13)*COLUMN(B1:M1)))). It seemed to work but can anybody explain to me why this worked?

B1:M9 = Data
A13= Value to look for
B1:M1 = Naming convention
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Richards440,

I'm not exactly sure what you want the formula to do so let me restate your question.

In cells A13 to A22 you have the top ten largest value from your matrix and you want to return some kind of title from cells B1 to M1 to show in which column they appear?

If so then I'll start with a couple of changes. If B1 to M1 are the title/headings to display then they probably shouldn't be in the search matrix and I believe the only relative address used should be A13 so you can copy down the formula. I've therefore modified the formula to INDIRECT(ADDRESS(1,SUMPRODUCT(($B$2:$M$9=A13)*COLUMN($B$1:$M$1))))

My explanation would be that the SUMPRODUCT produces an array of TRUE and FALSE results (1 and 0) looking for the A13 value in the matrix. As you have 12 columns (B through M) then you'll get 12 TRUE,FALSE values for row 2 then 12 TRUE,FALSE values for row 3, etc. and as we're looking in a matrix B to M (12 columns) and row 2 to 9 (8 rows) then we'll see 96 TRUE or FALSE results.
Now it multiplies those results by the column number for B to M (2 to 13) so as we're performing arithmetic the TRUE becomes 1 and the FALSE becomes 0. Let's assume the number we're looking for can be found in cell D3, then we'll get for row 2 the 12 FALSE (zero) values multiplied by the COLUMN number 2 through 12 which all result in zero. Now for row 3 we'll get two more FALSE values multiplied by the COLUMN numbers 2 and 3 but then we'll hit the TRUE match in D3. The TRUE, or 1, multiplied by the COLUMN 4 will return a 4 in that SUMPRODUCT array which is otherwise zeros. So SUMPRODUCT * COLUMN has given us the column number of the match.

ADDRESS default gives us a cell address in the format $Z$22 for a specified row and column number. The 1 is hard coded as row 1 and we've just returned a 4 from the SUMPRODUCT * COLUMN so the ADDRESS in this example will return $D$1

INDIRECT default lets you specify a cell address, or range of cells, as a text field, e.g. "$Z$22". While INDIRECT can get quite complex when used with other functions in this case it is quite simple, it will return the contents of the cell from the ADDRESS function, $D$1. If we've labelled the row 1 title headings in B1 to M1 with "Batch 39" through "Batch 50" then INDIRECT("$D$1") would return the contents of D1, "Batch 41".

Here's that explanation as a worked example.
HINTS:
  1. Using Formulas, Evaluate Formula will let you step through the calculation (though you may want to use a smaller matrix to make it easier to follow).
  2. Normally you want to avoid volatile functions (ones which recalculate with any sheet change) especially if you have a large dataset. INDIRECT is volatile and in this example INDEX would give the same result, changing our formula to INDEX($B$1:$M$1,,SUMPRODUCT(($B$2:$M$9=A13)*COLUMN($B$1:$M$1))-COLUMN($A$1))
  3. The formula will only work if the there are no duplicates in the Top 10 list, e.g. if the number sought is found in columns 9 and 8 then the formula would return 17 so point the INDIRECT at $Q$1. If you'd like the change to fix this then let me know. Hint in a Hint: We'll use another LARGE and a COUNTIF.
Richards440.xlsx
ABCDEFGHIJKLM
1Batch 39Batch 40Batch 41Batch 42Batch 43Batch 44Batch 45Batch 46Batch 47Batch 48Batch 49Batch 50
2137157110014391874111813441533227172216601789
31806121201110265474091791215151320817301275
418631496265367410691042719869129212501110
5443104312801615887156960512946371844164726
62816832314966603011665152992512092301298
76055381129167533715491503136018482181186321
868318121016151961170219368619871592691151
986811404131788178711781383159815118371352334
10
11
12Top 10Heading
132011Batch 41
141987Batch 47
151961Batch 43
161874Batch 43
171863Batch 39
181848Batch 47
191844Batch 48
201806Batch 39
211791Batch 45
221789Batch 50
Example1
Cell Formulas
RangeFormula
A13:A22A13=LARGE($B$2:$M$9,ROW()-12)
B13:B22B13=INDIRECT(ADDRESS(1,SUMPRODUCT(($B$2:$M$9=A13)*COLUMN($B$1:$M$1))))
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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