Aggregate Function on Vlookup Array Not Working

mforness

New Member
Joined
Dec 15, 2004
Messages
16
I am having problems getting a complex formula to work correctly and would appreciate any help or suggestions! I am using Excel 2003 and Windows XP.

I am trying to create a single cell formula that returns the min value of an array returned from a vlookup function. This is part of a more complex solution that I am trying to implement, but I think I have narrowed my problem down to this issue, so I have created a very simple example to demonstrate.

Cells A1 to B5 contain a lookup table:
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Letter</th><th>Number</th></tr> <tr><td>D</td><td>4</td></tr> <tr><td>C</td><td>3</td></tr> <tr><td>B</td><td>2</td></tr> <tr><td>A</td><td>1</td></tr></table>

Cells A7 to C8 contain the input values:
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Lookup1</th><th>Lookup2</th><th>Lookup3</th></tr> <tr><td>D</td><td>B</td><td>A</td></tr></table>

Enter the following formula (as an array formula) into 3 cells (they need to be in one row to work, not one column):
=VLOOKUP($A$8:$C$8,$A$1:$B$5,2,FALSE)

The correct array of 4,2,1 is returned into those 3 cells (essentially the result of 3 separate vlookups), so that part seems to work. However (and here is my issue), if I enter the following formula into 1 cell (as an array formula again) to find the min value of that array:
=MIN(VLOOKUP($A$8:$C$8,$A$1:$B$5,2,FALSE))

The value of 4 is returned instead of the value of 1 that I expected. It seems like the min formula always only looks at the first value in the array instead of finding the actual min of all values. However, if the same min array formula is entered as an array formula into more than one cell, the correct min value of 1 is returned to all the cells. Since the min function is an aggregate that should only return one value, I would have expected it to work correctly when entered into only 1 cell?? I tested with other aggregates (max and count) with the same results. If the array formula is entered into 1 cell, the aggregate portion only uses the first value of the array, if it is entered into 2 (or more) it correctly uses ALL values in the array.

I can't seem to find a way to get it to work. I have tried transposing different parts of the formula, tried switching to index/match or offset/match formulas instead of vlookup... all with no success. Any ideas on why the formula isn't working? Or suggestions on a different approach to reach the same goal? Note that I am trying to keep this to a single cell solution without creating a lot of extra tables since the real data is a lot larger and the range sizes will change. And I am hoping to avoid writing a custom VBA function.

Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try...

<TABLE style="WIDTH: 384pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=512 x:str><COLGROUP><COL style="WIDTH: 48pt" span=8 width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 height=17 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" id=td_post_2092511 class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 width=64> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 height=17>D</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: white; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 width=64 align=right x:num>4</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25>D</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25>B</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25>A</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 align=right x:num x:fmla="=MIN(IF(ISNUMBER(MATCH(D2:F2,$A$2:$A$5,0)),$B$2:$B$5))" x:arrayrange="H2">1</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: white; WIDTH: 48pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 height=17 width=64>C</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: white; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 width=64 align=right x:num>3</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: white; WIDTH: 48pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 height=17 width=64>B</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: white; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 width=64 align=right x:num>2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: white; WIDTH: 48pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 height=17 width=64>A</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: white; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl24 width=64 align=right x:num>1</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" id=td_post_2092511 class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25 height=17> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl25> </TD></TR></TBODY></TABLE>

A2:B5 houses the data and D2:F2 the lookup values of interest.

H2:

Control+shift+enter, not just enter...

=MIN(IF(ISNUMBER(MATCH(D2:F2,$A$2:$A$5,0)),$B$2:$B$5))

Note. VLOOKUP() is designed to return a scalar, not an array object.
 
Upvote 0
Thank you both for the quick responses!

Andrew, your array formula -- =MIN(IF(A2:A5=A8:C8,B2:B5)) -- did exactly what I asked.

Aladin, your formula -- =MIN(IF(ISNUMBER(MATCH(D2:F2,$A$2:$A$5,0)),$B$2:$B$5)) -- seemed to return the min value of all entries from the lookup table regardless of whether it corresponded to one of the input values. When the input values were changed so that none of them matched ‘1’ in the lookup table, ‘1’ was still returned. However your comment on VLOOKUP() returning a scalar, not an array was insightful… now I understand why my formula doesn’t work.

Unfortunately, Andrew's formula doesn’t look like it is going to work when I build it into my end solution. That is completely my fault. I tried to simplify the problem in my initial post too much. In hindsight I should have just posted exactly what I was trying to do. My end goal is to find the min value of the sum of two arrays looked up in a table. I didn't have much luck extending Andrew's formula like that. For anyone with enough stamina to keep reading, here is the actual "business problem" I am solving for.

I have a list of plants (P1, P2, etc), warehouses (W1, W2, etc), and customers (C1, C2, etc). A product moves from plant to warehouse to customer. What I need to do is find the lowest total transportation cost for each plant and customer combination. Each combination has multiple options since it can go through different warehouses. Each combination has two transportation legs with an associated cost – plant to warehouse plus warehouse to customer. There is a lookup table that contains the cost for all source & destination pairs. My plan was to return an array for the cost from a plant to all warehouses, return an array for the cost from all the warehouses to a customer, sum those arrays (resulting in a new array where each element is the total plant to customer cost for one option), and choose the min option.

Here is the setup of my current test worksheet.

Transportation cost lookup table (A1 to D31):
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104F8C; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Source</th><th>Destination</th><th>Lane</th><th>Cost</th></tr> <tr><td>P1</td><td>W1</td><td>P1_W1</td><td>5</td></tr> <tr><td>P1</td><td>W2</td><td>P1_W2</td><td>15</td></tr> <tr><td>P1</td><td>W3</td><td>P1_W3</td><td>10</td></tr> <tr><td>P1</td><td>W4</td><td>P1_W4</td><td>12</td></tr> <tr><td>P2</td><td>W1</td><td>P2_W1</td><td>7</td></tr> <tr><td>P2</td><td>W2</td><td>P2_W2</td><td>11</td></tr> <tr><td>P2</td><td>W3</td><td>P2_W3</td><td>6</td></tr> <tr><td>P2</td><td>W4</td><td>P2_W4</td><td>8</td></tr> <tr><td>P3</td><td>W1</td><td>P3_W1</td><td>12</td></tr> <tr><td>P3</td><td>W2</td><td>P3_W2</td><td>6</td></tr> <tr><td>P3</td><td>W3</td><td>P3_W3</td><td>7</td></tr> <tr><td>P3</td><td>W4</td><td>P3_W4</td><td>9</td></tr> <tr><td>W1</td><td>C1</td><td>W1_C1</td><td>12</td></tr> <tr><td>W1</td><td>C3</td><td>W1_C3</td><td>8</td></tr> <tr><td>W1</td><td>C4</td><td>W1_C4</td><td>10</td></tr> <tr><td>W1</td><td>C5</td><td>W1_C5</td><td>12</td></tr> <tr><td>W2</td><td>C1</td><td>W2_C1</td><td>8</td></tr> <tr><td>W2</td><td>C2</td><td>W2_C2</td><td>14</td></tr> <tr><td>W2</td><td>C3</td><td>W2_C3</td><td>18</td></tr> <tr><td>W2</td><td>C4</td><td>W2_C4</td><td>22</td></tr> <tr><td>W2</td><td>C5</td><td>W2_C5</td><td>16</td></tr> <tr><td>W3</td><td>C2</td><td>W3_C2</td><td>9</td></tr> <tr><td>W3</td><td>C3</td><td>W3_C3</td><td>13</td></tr> <tr><td>W3</td><td>C4</td><td>W3_C4</td><td>16</td></tr> <tr><td>W3</td><td>C5</td><td>W3_C5</td><td>17</td></tr> <tr><td>W4</td><td>C1</td><td>W4_C1</td><td>12</td></tr> <tr><td>W4</td><td>C2</td><td>W4_C2</td><td>16</td></tr> <tr><td>W4</td><td>C3</td><td>W4_C3</td><td>22</td></tr> <tr><td>W4</td><td>C4</td><td>W4_C4</td><td>22</td></tr> <tr><td>W4</td><td>C5</td><td>W4_C5</td><td>18</td></tr></table>

Warehouse list (A34 to D35):
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>Warehouses</th><th> </th><th> </th><th> </th></tr> <tr><td>W1</td><td>W2</td><td>W3</td><td>W4</td></tr></table>

Plant and customer matrix (A39 to D44):
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th></th><th>P1</th><th>P2</th><th>P3</th></tr> <tr><td>C1</td><td> </td><td> </td><td> </td></tr> <tr><td>C2</td><td> </td><td> </td><td> </td></tr> <tr><td>C3</td><td> </td><td> </td><td> </td></tr> <tr><td>C4</td><td> </td><td> </td><td> </td></tr> <tr><td>C5</td><td> </td><td> </td><td></td></tr></table>

Note that there are a few warehouse to customer combinations missing from the transportation cost table (since in reality not all lanes can be used). I was thinking that if the lane wasn’t in the table an arbitrarily high cost like 999 could be returned to the array so that the combination wouldn’t ever be returned as a minimum cost option.

My initial thought was to get a formula like this to work (entered in cell B40):
=MIN(VLOOKUP(B$39&"_"&$A$35:$D$35,$C$1:$D$31,2,FALSE)+VLOOKUP($A$35:$D$35&"_"&$A40,$C$1:$D$31,2,FALSE))
I was trying to add together the VLOOKUP results of both transportation legs (all options for each leg) and return the min value. But as Aladin pointed out, since VLOOKUP returns a scalar and not an array object, this will not work.

I also couldn't get variations of Andrew's formula to work. It seems like the problem is that the array formula returns as many results as it arguments... instead of just the successful matches from the lookup table. So adding the arrays together doesn't seem to work because the positioning between the elements in the two arrays doesn't match up (the plant to warehouse cost in array 1 won't be in the same position as its corresponding warehouse to customer cost in array 2 so they can be added).

I am hoping that I can find an end solution that keeps intermediate tables to a minimum. Since the actual data set is much larger and can change... I am trying to keep the solution as dynamic as possible.

For anyone who actually read all the way through my post… thanks! I definitely appreciate your time. Sorry for the length. Any suggestions or thoughts are welcome!
 
Upvote 0
...

Aladin, your formula -- =MIN(IF(ISNUMBER(MATCH(D2:F2,$A$2:$A$5,0)),$B$2:$B$5)) -- seemed to return the min value of all entries from the lookup table regardless of whether it corresponded to one of the input values. When the input values were changed so that none of them matched ‘1’ in the lookup table, ‘1’ was still returned. However your comment on VLOOKUP() returning a scalar, not an array was insightful… now I understand why my formula doesn’t work.

...

Before taking up the long reading, the formula I posted should have been:

Confirmed with control+shift+enter...

=MIN(IF(ISNUMBER(MATCH($A$2:$A$5,D2:F2,0)),$B$2:$B$5))
 
Upvote 0
Thanks for the formula update Aladin! Your new formula makes more sense now. It works with the first example that I posted. However it still has the same issues as Andrew's formula when I try to use it in a more complex way.

It returns the correct result when finding the min of one array returned from a lookup table (which is what I originally asked for - so your response is correct). But when I try to nest multiple instances of that formula - to try and return the min of the sum of two arrays returned from a lookup table... the answer is not correct.

The issue seems to be that each array returns a result for every row in the lookup table, not just the matches. So when adding two arrays together, the actuals results of each array won't line up so they can be added... they are in different orders depending on where the match was found in the lookup table.

Let me know if anyone has any ideas or suggestions to solve the problem (explained in more detail in my last post).

Thanks for everyone's time, I really appreciate it!
 
Upvote 0
Aladin - yes, the plant and customer matrix in cells A39 to D44 is where I was planning on putting the formula - which that would calculate the lowest cost transportation option.
 
Upvote 0
Sorry about that, I misunderstood. This is what the plant and customer matrix (A39 to D44) should be:
<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>
<table class="tableizer-table">
<tr class="tableizer-firstrow"><th></th><th>P1</th><th>P2</th><th>P3</th></tr> <tr><td>C1</td><td>17</td><td>19</td><td>14</td></tr> <tr><td>C2</td><td>19</td><td>15</td><td>16</td></tr> <tr><td>C3</td><td>13</td><td>15</td><td>20</td></tr> <tr><td>C4</td><td>15</td><td>17</td><td>22</td></tr> <tr><td>C5</td><td>17</td><td>19</td><td>22</td></tr></table>

Looking at one of the cells in the matrix in detail, B40 (P1 and C1 in the matrix) is 17. Manually done out the long way, that is because 17 is the minimum value of all possible transportation options from P1 to C1 (plant to warehouse cost plus warehouse to customer cost):

P1_W1 plus W1_C1 = 17
P1_W2 plus W2_C1 = 23
P1_W3 plus W3_C1 is not a valid option (W3_C1 doesn't exist in the cost table)
P1_W4 plus W4_C1 = 24

Thanks again for your help!!
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,266
Members
449,093
Latest member
Vincent Khandagale

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