Lookups within Array Formulas

akcramblet

New Member
Joined
Jul 12, 2010
Messages
10
I'm pretty good with excel, but this is tricky...

I have a table of bid results for multiple projects my company has bid.

Outside of the table, I need to look at a given company's performance, like the total backlog (or rank 1 bids):

{=SUM(([Company]=F2)*([Rank]=1)*([Bid]))} = $691,469

Not too bad.

I'd also like to see the total "tabled" bid dollars for a given company. Tabled dollars is the difference between the first and second ranked bidders on a single project. So for a given company, I need to add up the total rank 1 bids, and subtract that number from the corresponding rank 2 bids. This is what I've tried, but it doesn't seem to work (The problem is in the second half, which is really all I need):

{=SUM(([Company]=F2)*([Rank]=1)*([Bid]))-SUM((([Project]=IF([Company] =F2,IF([Rank]=1,[Project])))*([Rank]=2)*([Bid Amount])))}

I've never encountered this type of puzzle before, but can't afford the time to figure it out.

Any help is appreciated. Thanks.
Excel Workbook
ABCDEFGH
1ProjectCompanyBidRankCompanyBacklogTabled $
2AAABill$1,583,7771Silas$691,469????
3AAABob$1,644,8072
4AAAJohn$1,645,7613???? =
5AAASilas$1,704,0004$57,872
6BBBSilas$210,0001
7BBBBob$215,0002
8BBBJohn$223,5003
9CCCSilas$481,4691
10CCCBill$534,3412
11EEEJohn$1,365,4491
12EEEBill$1,367,7572
13EEESilas$1,393,1003
Sheet1
Excel 2007
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
 
Last edited:
Akcramblet, I'm glad it helped, thanks for the feedback.

Let me know if I can return the favor.

Yes you can. Now and again, when you have the time (and the patience), browse the board's questions and, if you see a problem that you know how to solve, help out.

Cheers.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Mike

I though of another option. I did not choose it because it's volatile, and I try to avoid them, but it's simpler and should be considered.

=SUM(IF(B2:B13=F2,IF(D2:D13=1,N(OFFSET(C2,MATCH(A2:A13&"|2",A2:A13&"|"&D2:D13,0)-1,0))-C2:C13)))

.. and still another one, a udf.
 
Upvote 0
pgc01,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
More than magnificnet!<o:p></o:p>
<o:p></o:p>
This is great:<o:p></o:p>
<o:p></o:p>
=SUM(IF(B2:B13=F2,IF(D2:D13=1,N(OFFSET(C2,MATCH(A2:A13&"|2",A2:A13&"|"&D2:D13,0)-1,0))-C2:C13)))<o:p></o:p>
<o:p></o:p>
This is the first time I have seen N used to get values from OFFSET. I had seen SUBTOTAL to do this before. Very nice! I would have done something like:

=SUM(IF(B2:B13=F2,IF(D2:D13=1,SUBTOTAL(9,OFFSET(C2,MATCH(A2:A13&"|2",A2:A13&"|"&D2:D13,0)-1,0))-C2:C13)))
<o:p></o:p>
<o:p></o:p>
What do you think of this:<o:p></o:p>
<o:p></o:p>
=SUMPRODUCT(--(B2:B13=F2),--(D2:D13=1),N(OFFSET(C1,MATCH(A2:A13&2,A2:A13&D2:D13,0),))-C2:C13)<o:p></o:p>
<o:p></o:p>
A couple of questions:<o:p></o:p>
<o:p></o:p>
1) Is there a reason that you used SUM and IF instead of SUMPRODUCT? What advantage might there be?
2) Is it necessary to concatenate an extra character such as "|". I used to do that and then slowly over the years I have gotten lazy and stopped doing it and then because I have not run into problems I just started making it my norm. Is there a situation where the extra character would be 100% necessary?<o:p></o:p>
<o:p></o:p>
It is fantastic how over the years I have really learned good tips from you, pgc01!!!<o:p></o:p>
<o:p></o:p>
 
Upvote 0
Hi All,

I've been watching this thread with interest. I hadn't realised we could use SUMIFS as demonstrated by pgc01, which is great to know.

In terms of your questions, Mike, I'm sure pgc01 will articulate things better than I ever could, but I think...

1) Is there a reason that you used SUM and IF instead of SUMPRODUCT? What advantage might there be?
...simply comes down to personal preference, though there might be something I don't know.

And in terms of...

2) Is it necessary to concatenate an extra character such as "|". I used to do that and then slowly over the years I have gotten lazy and stopped doing it and then because I have not run into problems I just started making it my norm. Is there a situation where the extra character would be 100% necessary?
I always delimit when concatenating for the reason illustrated below:

<table style="font-family:Arial,Arial; font-size:10pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; " border="1" cellpadding="0" cellspacing="0"> <colgroup><col style="font-weight:bold; width:30px; "><col style="width:50px;"><col style="width:50px;"><col style="width:47px;"><col style="width:20px;"><col style="width:50px;"><col style="width:50px;"><col style="width:179px;"><col style="width:163px;"></colgroup><tbody><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td>
</td><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td><td>G</td><td>H</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">1</td><td>Code A</td><td>Code B</td><td>Data C</td><td>
</td><td>Code A</td><td>Code B</td><td>Value Returned (no delimiter)</td><td>Value Returned (delimited)</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">2</td><td style="text-align:right; ">123</td><td style="text-align:right; ">456</td><td style="text-align:right; ">5</td><td>
</td><td style="text-align:right; ">1234</td><td style="text-align:right; ">56</td><td style="text-align:right; ">5</td><td style="text-align:right; ">10</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">3</td><td style="text-align:right; ">1234</td><td style="text-align:right; ">56</td><td style="text-align:right; ">10</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr></tbody></table>
<table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tbody><tr><td>Spreadsheet Formulas</td></tr><tr><td><table style="font-family:Arial; font-size:9pt;" border="1" cellpadding="2" cellspacing="0"><tbody><tr style="background-color:#cacaca; font-size:10pt;"><td>Cell</td><td>Formula</td></tr><tr><td>G2</td><td>{=INDEX(C2:C3,MATCH(E2&F2,A2:A3&B2:B3,0))}</td></tr><tr><td>H2</td><td>{=INDEX(C2:C3,MATCH(E2&"|"&F2,A2:A3&"|"&B2:B3,0))}</td></tr></tbody></table></td></tr><tr><td>Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!
</td></tr></tbody></table>
Situations such as this are probably few and far between, but better to be safe than sorry!

Matty
 
Upvote 0
Got it, Matty! That makes perfect sense that to join the numbers may cause problems. That means I am back to using an extra character when I join things, because I do do it very often and it is better to be safe than sorry.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
Hi Mike. Thanks, I also think that it's amazing how much we learn from each other in this board.

For the question 1:

There is no special reason. I just translated directly what I would do if I were to perform the calculations manually, it would be something like "loop through the records and for each one if the name of the company is equal to the value in F2 then if the Rank is equal to 2 then ...". The "Sum(If(" formula is very close to the natural language.

Your SumProduct() formula seems perfect and has the advantage of not needing to be confirmed with CSE. Sumproduct() is also slightly faster than the equivalent array formula, so there's another advantage.

For the question 2:

Matty posted a nice example that shows why it's important in some cases to use a separator when you concatenate.

Cheers!
 
Upvote 0
Cheers to all at the amazing Message Board! Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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