minimum of an array

charijit

Board Regular
Joined
Nov 27, 2003
Messages
89
Dear All,
In column-A I have various items : a,b,c,d,e,r,v,a,b,d,t,h,e,r,v.
In column-B I have prices of items in Column-A : 1,3,4,5,5,6,3,4,6,7,8,3,4,5,6.
In column-C I have vendor names, who have supplied the items in Column-A : ww,ee,dd,ff,ee,ee,dd,ww,rr,zz,ss,ee,ee,rr,dd.

In a separate sheet I have listed the items nos. appearing in Column-A mentioned above. In the second column I wish the minimun price of the item to appear (since item is repeating and vendors may vary and thus their rates). In the third column I wish the vendor name corresponding to the minimun price to appear.
I seek all of your help.
 
Ken,
Now it is working. I have so much to learn.

Dear Dear Sixth Sense,
Can you tell me what is "array entered" because I am not clear about it after reading the Excel help file on this. Also kindly help me know if the above excersize can be done with DMIN and DGET function.
Lastly, I am not able to understand the logic for vendor name. Can you please explain the logic for the INDEX argument used therein.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think the sumproduct of this formula is a little bit tricky.

Code:
=INDEX(Sheet1!$C$1:$C$15,SUMPRODUCT(--(Sheet1!$A$1:$A$15=Sheet2!A1),--(Sheet1!$B$1:$B$15=Sheet2!B1),ROW(Sheet1!$A$1:$A$15)))
This argument refers to the range where you want to select from(the vendors name)
Code:
Sheet1!$C$1:$C$15

This part is tricky!

Code:
SUMPRODUCT(--(Sheet1!$A$1:$A$15=Sheet2!A1),--(Sheet1!$B$1:$B$15=Sheet2!B1),ROW(Sheet1!$A$1:$A$15))
The first argument create an array of size 1X15 with
values of 1 for those equal the criteria Sheet2!A1 and 0 for those that are not
This reutrns something like
{1;0;0;1;0..}
Code:
--(Sheet1!$A$1:$A$15=Sheet2!A1)
The second argument is simmilar to the first. But this time
it is looking at column B.
Code:
--(Sheet1!$B$1:$B$15=Sheet2!A1)

The 3rd argument returns an array containing the row numbers of the argument. literally, this returns {1;2;3;4;5;6;7;8;9;10;11;12;13;14;15}
Code:
ROW(Sheet1!$A$1:$A$15)

So the sumproduct will return the row number that complies
the first two arguments.

but one problem with this is when there are more than one matches, ie two vendors selling the same item and both the cheapest price in the array. this will return 0.
maybe aladin can shed ligh on this.
 
Upvote 0
SIXTH SENSE said:
I think the sumproduct of this formula is a little bit tricky...

but one problem with this is when there are more than one matches, ie two vendors selling the same item and both the cheapest price in the array. this will return 0.
maybe aladin can shed ligh on this.

That's right. Just change the triple

< a, 4, ww >

to

< a, 1, xx >

which shows that the system of formulas acw posted cannot reflect the reality. However, I'll post one that will. That's a system which I have been proposing last few months here and elsewhere.
 
Upvote 0
Hi

Aladin you are right. Change the formula
=INDEX(Sheet1!$C$1:$C$15,SUMPRODUCT(--(Sheet1!$A$1:$A$15=Sheet2!A1),--(Sheet1!$B$1:$B$15=Sheet2!B1),ROW(Sheet1!$A$1:$A$15)))

with array entered
=INDEX(Sheet1!$C$1:$C$15,MIN(VALUE(SUBSTITUTE((Sheet1!$A$1:$A$15=Sheet2!A1)*(Sheet1!$B$1:$B$15=Sheet2!B1)*ROW(Sheet1!$A$1:$A$15),0,999))))

Again the 999 will have to be changed to something suitable.

Tony
 
Upvote 0
Hi Charijit:

How about ...
Book3
ABCDEFG
1ITEMPRICEVENDOR
2a1wwMinimumPriceTable
3b3eeITEMPRICEVENDOR
4c4dda1ww
5d5ffb3ee
6e5eec4dd
7r6eed5ff
8v3dde4ee
9a4wwr5rr
10b6rrv3dd
11d7zzt8ss
12t8ssh3ee
13h3ee
14e4ee
15r5rr
16v6dd
Sheet1


The items in cells E3:E12 are Unique Values that can be obtained by using AdvancedFilter on A1:A16

The formula in cell F4 is ... =MIN(IF(($A$2:$A$16=$E4)*($B$2:$B$16)>0,($A$2:$A$16=$E4)*($B$2:$B$16)))

It is an array formula. It is then copied to cells F5:F12

The formula in cell G4 is ... =INDEX($C$2:$C$16,MATCH(E4&CHAR(1)&F4,$A$2:$A$16&$B$2:$B$16,0))

this is also an array formula. It is then copied to cells G5:G12.
 
Upvote 0
charijit said:
[/i]
....Also kindly help me know if the above excersize can be done with DMIN and DGET function.
....
[/i]
Hi Charijit:

Let us have a look at the following ...
y040226h1a.xls
ABCDEFGHIJ
1ITEMPRICEVENDORITEMsource
2a1wwacriteria
3b3eeDATATABLESolutionDataTable
4c4ddITEMPRICEVENDOR
5d5ffa1ww
6e5eeb3ee
7r6eec4dd
8v3ddd5ff
9a4wwe4dd
10b6rrr5ff
11d7zzv3ee
12t8sst8ss
13h3eeh3ee
14e4ee
15r5rr
16v6dd
Sheet1 (2)


In this one variable DATA TABLE solution, I have used the DMIN function for MINIMUM Price, and the INDEX function for locating the VENDOR.
 
Upvote 0
charijit said:
...
In column-A I have various items : a,b,c,d,e,r,v,a,b,d,t,h,e,r,v.
In column-B I have prices of items in Column-A : 1,3,4,5,5,6,3,4,6,7,8,3,4,5,6.
In column-C I have vendor names, who have supplied the items in Column-A : ww,ee,dd,ff,ee,ee,dd,ww,rr,zz,ss,ee,ee,rr,dd.

In a separate sheet I have listed the items nos. appearing in Column-A mentioned above. In the second column I wish the minimun price of the item to appear (since item is repeating and vendors may vary and thus their rates). In the third column I wish the vendor name corresponding to the minimun price to appear...

Your original data looks like this with changes regarding item "a", made on purpose...

Exhibit 1
aaVendorsLowestPrice charijit v1.xls
ABCD
1ItemPriceVendor
2a1ww
3b3ee
4c4dd
5d5ff
6e5ee
7r6ee
8v3dd
9a1xx
10b6rr
11d7zz
12t8ss
13h4ee
14e4ee
15r5rr
16a1dd
17
VendorsOriginal


Note that you have for item "e" 2 different prices from the same vendor "ee". While this is close to the reality, the system of formulas in what follows requires that this type of data (item and vendor duplicates) is eliminated. The system also needs a different data representation like in:

http://www.mrexcel.com/board2/viewtopic.php?t=72823

See Exhibit 2 in the next post.
 
Upvote 0
Aladin Akyurek said:
...

See Exhibit 2...

Exhibit 2 (Partly shown)
aaVendorsLowestPrice charijit v1.xls
ABCDEFGHIJKLMNOPQRSTUV
1VENDORS
2TITLESddeeffrrsswwxxzzRANKCHEAPEST
3a1111    23 21ddwwxx
4b36 1 2    01ee  
5c41       01dd  
6d57  1    201ff  
7e4 1      01ee  
Vendors


The above representation can be easily constructed from the first exhibit (Exhibit 1) by means of a formula (but I won't discuss that now).

Formulas...

J3, copied to Q3:

=IF(N(B3),RANK(B3,$B3:$I3,1)+COUNTIF($B3:B3,B3)-1,"")

R3: (determines the number of ties of the cheapest price)

=MAX(IF(INDEX(B3:I3,MATCH($S3,J3:Q3,0))=B3:I3,J3:Q3))-$S3

which must be confirmed with control+shift+enter instead of just enter.

S3 houses 1, meaning Top 1 cheapest.

T3, copied across to AA3:

=IF(COLUMN()-COLUMN($T3)+1<=$S3+$R3,INDEX($B$2:$I$2,MATCH(COLUMN()-COLUMN($T3)+1,$J3:$Q3,0)),"")

Each formula must also be copied down.

As can be seen from above, the cheapest price for an item can be associated with one or more vendors. When more, just giving one is patently wrong.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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