Forum Discussion

AmyYang's avatar
AmyYang
Brass Contributor
Feb 20, 2022
Solved

How to use XLOOKUP in scenario where I want the latest date with AVAILABLE data?

Hello, 

 

May I ask, if you could open the attached excel, currently I am trying to use XLOOKUP formula to look up for example, country Chile's latest vaccination percentage from the LATEST date with AVAILABLE data. 

 

The problem that I'm experiencing is that I need to pull this data from a number of different countries and each country have different "Latest Date" so excel would look up the latest date however it is blank for Chile on 2/18/2022 because instead I would like Excel to capture the 89% fully vaccinated from 2/16/2022 instead for Chile for example. Is it possible for excel to skip the blank dates? 

 

Thanks,

Amy 

10 Replies

  • AmyYang 

    The last record for which there exists data is given by

    = XLOOKUP(
        country,
        IF(fullyVaccinated,location),
        fullyVaccinated,
        "No records",
        0,
       -1)

    For this to correspond to the latest date, the data needs to be sorted ascending by date (which it is).

    If 'country' is the array of countries for which you wish to see results the formula will spill to return results for the entire list.

    • AmyYang's avatar
      AmyYang
      Brass Contributor

      PeterBartholomew1 Hi Peter -  thank you so much for providing the XLOOKUP and IF formula! I did not know we can use the formula like that! 

       

      May I follow-up regarding the IF function within the XLOOKUP: 

      1) First, lookup value is country (e.g. Chile)

      2) We use IF function and include % Fully Vaccinated Data, why? Because we didn't put in value if true or value if false, so what is the purpose of this? 

      3)Then afterwards I understand we want the return array back to Xlookup formula 

       

      Thank you,

      Amy

      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        AmyYang 

        1) First, lookup value is country (e.g. Chile): Correct

        2) We use IF function and include % Fully Vaccinated Data, why? Because we didn't put in value if true or value if false, so what is the purpose of this? 

        Rather than looking for the country in the original list, I look for it in an array that is modified to show FALSE if there is no data.  That prevent the lookup from retuning lines with no data.

        3)Then afterwards I understand we want the return array back to Xlookup formula 

        Yes, that is the new array to be searched.

    • CarlosF's avatar
      CarlosF
      Brass Contributor

      harshulz AmyYang 

       

      I really doen't undestard this formulae.

      If you fill the table1 for Argentina and date 01/03/2022 with "100%", the result of the formulae will not be the latest value different to 0, it will be the biggest one, which, in this case, will be 100%..

       

      Sorry if I am wrong.

       

      Regards,

       

      Carlos

    • AmyYang's avatar
      AmyYang
      Brass Contributor

      harshulz  Hi Harshulz, wow, that is really great simplistic formula (which I didn't know how to use previously) ! Thank you! 

    • AmyYang's avatar
      AmyYang
      Brass Contributor
      Dear Mtarler,

      Thank you so much for your time and providing this excel function!

      If it's possible, may I clarify with a few follow-up questions:
      1) What's the reason that you used INDEX function instead of XLOOKUP function? I actually haven't used INDEX function before

      2) May you let me know your thoughts regarding your process for creating this formula?

      The formula: =INDEX(Table1[people_fully_vaccinated_per_hundred],MAX((Table1[location]=A6)*ISNUMBER(Table1[people_fully_vaccinated_per_hundred])*ROW(Table1[location]))-ROW(Table1[#Headers]))

      INDEX formula is INDEX(reference, row_num, [column_num], [area_num]).

      - it makes sense the reference is the column with "People Fully Vaccinated Per Hundred"
      - then for row_number, it looks like you used the maximum number in the "People Fully Vaccinated Per Hundred" column + Location = Chile country. but I don't understand the other elements.
      - Why use "*" which is multiplication?
      - I don't understand why if we're finding the maximum cell that is a number, why we need Row(Location)-Row(Headers) as well

      Thank you kindly if you can provide more details in advance so I can further understand your logic and utilize the same process for other spreadsheets.

      Kind regards,
      Amy

Resources