SOLVED

Help Vlookup formula with criteria

%3CLINGO-SUB%20id%3D%22lingo-sub-1555193%22%20slang%3D%22en-US%22%3EHelp%20Vlookup%20formula%20with%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1555193%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22lia-message-subject-wrapper%20lia-component-subject%20lia-component-message-view-widget-subject-with-options%22%3E%3CDIV%20class%3D%22MessageSubject%22%3E%3CDIV%20class%3D%22MessageSubjectIcons%20%22%3E%3CH1%20id%3D%22toc-hId-499769382%22%20id%3D%22toc-hId-499769386%22%20id%3D%22toc-hId-499769386%22%3E%3CFONT%20size%3D%225%22%3EHelp%20Vlookup%20formula%20with%20criteria%3C%2FFONT%3E%3C%2FH1%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-body%20lia-component-message-view-widget-body%20lia-component-body-signature-highlight-escalation%20lia-component-message-view-widget-body-signature-highlight-escalation%22%3E%3CDIV%20class%3D%22lia-message-body-content%22%3E%3CP%3EIf%20I%20have%20a%20table%2C%20what%20formula%20would%20I%20use%20to%20return%20a%20value%20to%20a%20cell-based%20upon%20two%20lookup%20criteria%20(match%20country%20%26amp%3B%20in%20price%20range)%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20width%3D%22123%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22123%22%3ETable%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECountry%3C%2FTD%3E%3CTD%3EUnit%20Price%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ENZ1%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ENZ2%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECN%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECN2%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EHK%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BWhat%20formula%20should%20apply%20to%20able%20get%20the%20answer%20as%20expected%3F%3C%2FP%3E%3CTABLE%20width%3D%22494%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22135%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%22135%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%22224%22%3EExpect%20result%20from%20the%20table%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EOrigin%20country%3C%2FTD%3E%3CTD%3EAmount%3C%2FTD%3E%3CTD%3EUnit%20Price%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ENZ%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ENZ%3C%2FTD%3E%3CTD%3E199.99%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECN%3C%2FTD%3E%3CTD%3E99.98%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECN%3C%2FTD%3E%3CTD%3E200.01%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EHK%3C%2FTD%3E%3CTD%3E100%3C%2FTD%3E%3CTD%3E200%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1555193%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1555217%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20Vlookup%20formula%20with%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1555217%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F744508%22%20target%3D%22_blank%22%3E%40eehyun123%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20is%20the%20logic%20behind%20the%20rounding%20of%20price%20range%20based%20on%20amount%3F%20For%20example%2C%20for%20NZ%20199.99%20goes%20to%20200%2C%20what%20shall%20be%20for%20187.31%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Help Vlookup formula with criteria

If I have a table, what formula would I use to return a value to a cell-based upon two lookup criteria (match country & in price range)?

 

 

Table
CountryUnit Price
NZ1100
NZ2200
CN100
CN2200
HK200

 

 What formula should apply to able get the answer as expected?

  Expect result from the table
Origin countryAmountUnit Price
NZ100100
NZ199.99200
CN99.98100
CN200.01200
HK100200
14 Replies
Highlighted

@eehyun123 

What is the logic behind the rounding of price range based on amount? For example, for NZ 199.99 goes to 200, what shall be for 187.31?

Highlighted

@Sergei Baklan 

 

Fixed my sample:

 

this my contract pricing table:

CountryPrice per Min (INR)
France3.68
New Zealand3.53
New Zealand - Mobile21.87

This the report received, as the report didn't tell whether it for mobile or normal type.

The only way to identify is to match the country & match to the nearest rate to get my contract rate.

It may also happen the rate total not close.

Purpose to check whether it charges as per agreed contract rate

Origin countryDurationCharge UnitContract Rate (formula) 
NEW ZEALAND         13221.8658 to get contract rate  21.87?
NEW ZEALAND         303.53 to get contract rate   3.53?
FRANCE              52212.25 to get contract rate   3.68?
Highlighted

@eehyun123 

That could be as 

image.png

formula

=INDEX($C$4:$C$6,
    MATCH(1,INDEX(
        ISNUMBER(SEARCH($E4,$B$4:$B$6))*
       (ABS($C$4:$C$6-$G4)=MIN(ABS($C$4:$C$6-$G4))),0),0)
)

works as it on Excel with dynamic arrays, otherwise Ctrl+Shift+Enter

Highlighted

@Sergei Baklan 

 

Thank for helping.

However, it not work when I add additional country.

Any suggestion?

 

Highlighted
Best Response confirmed by eehyun123 (Occasional Contributor)
Solution

@eehyun123 

 

If I may, I think the problem is that the MIN function is evaluating all of the rate differences and not just the rate differences for the selected country.

 

I think it just needs a little tweak. Try this in H4 (copied down):

 

=INDEX($C$4:$C$9, MATCH(1,ISNUMBER(SEARCH($E4,$B$4:$B$9))*(ABS($C$4:$C$9-$G4)=MIN(IF(ISNUMBER(SEARCH($E4,$B$4:$B$9)),ABS($C$4:$C$9-$G4),""))),0))

 

Highlighted

@eehyun123 

Another way is...

=INDEX($C$4:$C$9,MATCH(MIN(IF(ISNUMBER(SEARCH(E4,$B$4:$B$9)),ABS($C$4:$C$9-G4))),INDEX((ISNUMBER(SEARCH(E4,$B$4:$B$9)))*(ABS($C$4:$C$9-G4)),),0))
Highlighted

I believe you will have a problem if the charge/unit happens to match the price per min. Since the difference is zero, it will match to the first zero.@Subodh_Tiwari_sktneer 

Highlighted
Thanks, it works!
Appreciated
Highlighted

@JMB17 

Not sure why you got a different output.

 

Lookup prices.jpg

Highlighted

@Subodh_Tiwari_sktneer 

 

I get a different answer by changing the charge/unit to 21.87. Is the charge/unit in your screencap 21.87 or just formatted to show 2 decimals?

 

If the charge/unit is the same as the price per min for the applicable country, then the min value for that country is zero. Then MATCH will match to the first zero in the second argument, which may/may not be  correct as the values for the other countries will be zero as well.

Highlighted

@JMB17 

Ah... you are right. Thanks for pointing that out.

Highlighted

@eehyun123 

As variant

image.png

with

=IF(LEN($E4)=0,"",
     XLOOKUP(
        $E4&"*",
        SORTBY($B$4:$B$9,ABS($C$4:$C$9-$G4)),
        SORTBY($C$4:$C$9,ABS($C$4:$C$9-$G4)),
        "no such",2)
)

if you are on Excel with dynamic arrays

Highlighted

Thanks @Sergei Baklan 

 

this work with using latest formula _ xlookup . Help me learn alot !

Highlighted

@eehyun123 

For my own benefit, I first implemented @Sergei Baklan 's formula using defined names

= IF(LEN(@Origin_country)=0,"",
     XLOOKUP(
       @Origin_country&"*",
       SORTBY(Country, ABS(Price-@Charge)),
       SORTBY(Price, ABS(Price-@Charge)),
       "no such",2)
  )

(I have come to believe I am the only person on the planet that finds names more readable)

Instead of using XLOOKUP to perform a wildcard search of a sorted array, I decided to use XLOOKUP to search for the filtered value closest to zero.

= IF( LEN(@Origin_country),
   XLOOKUP( 0, priceVariance, tblPrice, "no such", 1 ),
   "" )

where the name 'priceVariance' refer to the formula

= IF( (LEFT(Country, LEN(@Origin_country)) = @Origin_country), ABS(Price - @Charge), -1 )

Using the newly released LET function, this could be combined

= LET(
  countryFound?, LEFT(Country, LEN(@Origin_country)) = @Origin_country,
  priceVariance,  IF( countryFound?,  ABS(Price - @Charge), -1 ),
  closestPrice, 
    IF(LEN(@Origin_country),
       XLOOKUP( 0, priceVariance, tblPrice, "no such", 1 ),
       "" ),
  closestPrice )