Location Selection to buy

freddocp

New Member
Joined
Sep 28, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Good day,

Please, I appreciate the help in advance I'll try to explain with an example what I really need; a formula to fill in the locality I should buy in column B.

First all the statuses need to be “Available” line 1

1- As I'm located in Brazil, this would be the location priority. Example in line 3; I need 2 ; “needed :2” and in Brazil I have 297 units available.

2- When not available in Brazil, select the nearest countries, for example in line 5, Chile or Colombia. Note that China has been left out.
To decide between Chile and Colombia, check which country has more different ID numbers available; for example, between rows 5 and 8, Chile has 4, and Colombia 2. Therefore, it is more interesting to buy from Chile.

3- If the “Available” quantity is below the “Needed” quantity, select the one with the quantity or more; example line 9, Australia.

Location to buy test.xlsx
ABCDEFGHIJKLM
1AvailableAvailableAvailableAvailableAvailableAvailableAvailableNot availableAvailableAvailable
2Id NumberLocationNeededArgentinaChileColombiaUruguai PortugalFranceJapanChinaAustraliaBrazil
35623Brazil20150000000297
42458Brazil10000000007
5213335Chile2072000025400
6598456Chile30300020000
7369546Chile205100000000
8365982Chile102000000170
9123458Australia3010012040
1032156Brazil310003000008
116712569Brazil10090000001
12364781Uruguai20002000011
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A12Cell ValueduplicatestextNO
D3:M12Cell Value>=$C3textNO
D3:M12Cell Valuebetween $C3 and 0,1textNO
 

Attachments

  • Location to buy from print.png
    Location to buy from print.png
    37.8 KB · Views: 1

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try:

Book1
ABCDEFGHIJKLM
1AvailableAvailableAvailableAvailableAvailableAvailableAvailableNot availableAvailableAvailable
2Id NumberLocationNeededArgentinaChileColombiaUruguaiPortugalFranceJapanChinaAustraliaBrazil
35623Brazil20150000000297
42458Brazil10000000007
5213335Chile2072000025400
6598456Chile30300020000
7369546Chile205100000000
8365982Chile102000000170
9123458Australia3010012040
1032156Brazil310003000008
116712569Brazil10090000001
12364781Uruguai20002000011
Sheet9
Cell Formulas
RangeFormula
B3:B12B3=LET(avail,$D$1:$M$1,ctry,$D$2:$M$2,need,$C$3:$C$12,brz,M3,tbl,$D$3:$M$12,ix,ROWS($B$3:$B3),t,MMULT(SEQUENCE(,ROWS(tbl),,0),--(tbl>=need))*(avail="available")*(INDEX(tbl,ix,0)>=INDEX(need,ix)),sb,SORTBY(ctry,t,-1),IFS(INDEX(need,ix)<=brz,"Brazil",INDEX(need,ix)>MAX(INDEX(tbl,ix,0)),"N/A",1,INDEX(sb,1)))
 
Last edited:
Upvote 0
Happy to help! :cool:
Hi Eric ,

I've done some tests, and I'd like to see if you can help me, if possible. I need to try to prioritize the closest countries, I put in line 14 for example a priority level, I tried to add in your formula but I could not.

I really asked for the premise to use where there are more different items for a lot, but however, in this example when the priority of the country is higher (value closer to 1) the ideal would be to buy from this country.

As an example: Chile has 3 available, Portugal has 4. The formula determines Portugal, but Chile has Priority 2, so in this case buy from Chile which is closer to Brazil. If the priority is the same, apply the formula as before.

I hope I've explained, thanks again

1731085149306.png


Location to buy test.xlsx
ABCDEFGHIJKLM
1AvailableAvailableAvailableAvailableAvailableAvailableAvailableNot availableAvailableAvailable
2Id NumberLocationNeededArgentinaChileColombiaUruguai PortugalPeruJapanChinaAustraliaBrazil
35623Brazil20150000000297
42458Brazil10000000007
5213335Portugal2002040025400
6598456Portugal30300520000
7369546Portugal205001000000
8365982Portugal102009000170
9123458Australia3010012040
1032156Brazil310003000008
116712569Brazil10090000001
12364781Uruguai 20002000011
13
14Country priority 2222323441
15
16
Sheet1
Cell Formulas
RangeFormula
B3:B12B3=LET(avail,$D$1:$M$1,ctry,$D$2:$M$2,need,$C$3:$C$12,brz,M3,tbl,$D$3:$M$12,ix,ROWS($B$3:$B3),t,MMULT(SEQUENCE(,ROWS(tbl),,0),--(tbl>=need))*(avail="available")*(INDEX(tbl,ix,0)>=INDEX(need,ix)),sb,SORTBY(ctry,t,-1),IFS(INDEX(need,ix)<=brz,"Brazil",INDEX(need,ix)>MAX(INDEX(tbl,ix,0)),"N/A",1,INDEX(sb,1)))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A12Cell ValueduplicatestextNO
D3:M12Cell Value>=$C3textNO
D3:M12,D14:M14Cell Valuebetween $C3 and 0,1textNO
 
Upvote 0
Give this a try. I'm not sure the interaction between priority and country frequency is always going to work though.

Book1
ABCDEFGHIJKLM
1AvailableAvailableAvailableAvailableAvailableAvailableAvailableNot availableAvailableAvailable
2Id NumberLocationNeededArgentinaChileColombiaUruguaiPortugalPeruJapanChinaAustraliaBrazil
35623Brazil20150000000297
42458Brazil10000000007
5213335Colombia2002040025400
6598456Chile30300520000
7369546Chile205001000000
8365982Chile102009000170
9123458Australia3010012040
1032156Brazil310003000008
116712569Brazil10090000001
12364781Uruguai20002000011
13
14Country priority2222323441
Sheet11
Cell Formulas
RangeFormula
B3:B12B3=LET(avail,$D$1:$M$1,ctry,$D$2:$M$2,prty,$D$14:$M$14,need,$C$3:$C$12,tbl,$D$3:$M$12,ix,ROWS($B$3:$B3),t,MMULT(SEQUENCE(,ROWS(tbl),,0),--(tbl>=need))*(avail="available")*(INDEX(tbl,ix,0)>=INDEX(need,ix)),sb,SORTBY(CHOOSE(SEQUENCE(2),ctry,t),prty,1,t,-1),IFS(INDEX(need,ix)>MAX(INDEX(tbl,ix,0)),"N/A",1,INDEX(FILTER(sb,INDEX(sb,2,0)>0),1,1)))
 
Upvote 0
A little shorter, and some line feeds for clarity:

Excel Formula:
=LET(avail,$D$1:$M$1,
ctry,$D$2:$M$2,
prty,$D$14:$M$14,
need,$C$3:$C$12,
tbl,$D$3:$M$12,
ix,ROWS($B$3:$B3),
frq,MMULT(SEQUENCE(,ROWS(tbl),,0),--(tbl>=need))*(avail="available")*(INDEX(tbl,ix,0)>=INDEX(need,ix)),
sb,SORTBY(CHOOSE(SEQUENCE(2),ctry,frq),prty,1,frq,-1),
INDEX(FILTER(sb,INDEX(sb,2,0)>0,"N/A"),1,1))
 
Upvote 0
Solution
A little shorter, and some line feeds for clarity:

Excel Formula:
=LET(avail,$D$1:$M$1,
ctry,$D$2:$M$2,
prty,$D$14:$M$14,
need,$C$3:$C$12,
tbl,$D$3:$M$12,
ix,ROWS($B$3:$B3),
frq,MMULT(SEQUENCE(,ROWS(tbl),,0),--(tbl>=need))*(avail="available")*(INDEX(tbl,ix,0)>=INDEX(need,ix)),
sb,SORTBY(CHOOSE(SEQUENCE(2),ctry,frq),prty,1,frq,-1),
INDEX(FILTER(sb,INDEX(sb,2,0)>0,"N/A"),1,1))

My friend, I owe you a good lunch when you visit Brazil, thank you very much!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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