+ Reply to Thread
Results 1 to 26 of 26

Matching two columns and returning the third?

  1. #1
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Matching two columns and returning the third?

    Hello,

    I have a working formula that matches a single column but I can't figure out how to also match a second one.

    I've attached an example spreadsheet and included some screenshots below to hopefully help explain the problem.

    Within a sheet called Lists, I have 3 defined ranges:
    Screenshot 2023-03-08 at 20.00.37.png

    Within the Transactions sheet, column F contains the following formula:

    =IFERROR(INDEX(CATEGORY,MATCH(TRUE,ISNUMBER(FIND(DESCRIPTION,C2)),0)),"")

    This takes the description in C2 and looks for a match in column A (DESCRIPTION) from Lists, returning the relevant Category from column C.
    Screenshot 2023-03-08 at 20.01.16.png

    At the moment I can't do a valid match when there are multiple transactions with the same name but different Amounts. I would like to do a double match against the Description and Amount that then returns the relevant Category. Would someone be able to help figure this out please?

    Thanks in advance.
    Example.xlsx

  2. #2
    Forum Expert
    Join Date
    06-05-2017
    Location
    Brazil
    MS-Off Ver
    Microsoft 365 Version 2404
    Posts
    1,259

    Re: Matching two columns and returning the third?

    Hello.

    Maybe you try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This is an array formula. You might have to confirm with Ctrl+Shift+Enter, instead of just Enter.

    Good luck!
    Last edited by Estevaoba; 03-08-2023 at 06:49 PM.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: Matching two columns and returning the third?

    Power Query solution. Join the two tables on the common fields.

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.

    Load each table to the Power Query Editor and then join the two tables.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Matching two columns and returning the third?

    I didn't check Alan's file so
    another way with Power Query

    Date Type Description Value Category
    01/03/2023
    UKI T/A DIRECTLINE
    -20
    me
    01/03/2023
    UKI T/A DIRECTLINE
    -10
    wife
    02/03/2023
    UKI T/A DIRECTLINE
    -40
    02/03/2023
    Savings Account
    -50
    To Savings
    02/03/2023
    UKI T/A DIRECTLINE
    -30
    dog
    03/03/2023
    SAVINGS ACCOUNT
    60
    From Savings
    04/03/2023
    BRITISH GAS
    -20
    Energy
    05/03/2023
    WATER
    -150
    Energy


    Please Login or Register  to view this content.
    Last edited by sandy666; 03-08-2023 at 07:28 PM. Reason: update

  5. #5
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    Thank you very much for your help Alan and Sandy, I didn't know about Power Query so I will certainly look into that to see how you kindly implemented it in both examples!

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    You are welcome

    if you have any questions just post it

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: Matching two columns and returning the third?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  8. #8
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    Good point, I’ll sort that out now.

    Mind is so far blown by what Power Query can do! I may have a few further questions once I’ve read into it more (eg I need to find out if it can remove duplicate rows from multiple source files, ie rows containing the same date/description/amount). I’ve only just started looking into it so no need to answer that just yet, I’ll test and experiment first.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: Matching two columns and returning the third?

    Here is a link to a really good primer for Power Query

    https://www.amazon.com/Master-Your-D...40186797&psc=1

  10. #10
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    hmm that's a real shame, no option for folder as a data source in the MacOS version of Excel yet. Ah well, time to fire up the Windows VM...

    (thank you for the book suggestion)

  11. #11
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    a few version of MacOS support Power Query, you'll need to find them

  12. #12
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    Sorry to be a pain, I unfortunately simplified things in my original example by indicating that Description cells within Lists were an exact match with the Descriptions field from my transactions. In reality the cell is a partial match, and I realised this wouldn't work after crafting the PQ myself and seeing it only match on whole cells.

    Do you know if this is possible please? I experimented with fuzzy matching with no luck, and I tried the suggestion from this article, but that just multiplied my rows for some reason.

    I've attached an example spreadsheet to show what I mean because I'd also like it to match transactions when the category has no associated amount if possible please.

    No worries if this is asking too much, I'm probably trying to over complicate things anyway...
    Example3.xlsx

  13. #13
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Matching two columns and returning the third?

    maybe this one

  14. #14
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    ohh, as simple as using Distinct! Thank you!

    One thing I've spotted though - is it possible to add the "Food" category when no value has been specified in Categories please?
    tmp_excel.png

    Another issue is that I tried to change the "BRITISH GAS" Amount within Lists from -20 to -25, but after pressing Refresh All within the Data Ribbon, the Merge1 sheet retained the "me" category when I was expecting it to clear. Am I missing something?
    Last edited by jarrah31; 03-31-2023 at 06:09 AM.

  15. #15
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    files in post#14 are not attached properly

    btw. you need to change values in both tables but see post#17

    Date Type Description Value Category
    28/02/2023
    Before UKI T/A DIRECTLINE
    -20
    me
    01/03/2023
    Text before UKI T/A DIRECTLINE and after
    -10
    wife
    01/03/2023
    Before UKI T/A DIRECTLINE
    -20
    me
    02/03/2023
    Savings Account
    -50
    To Savings
    02/03/2023
    UKI T/A DIRECTLINE
    -40
    extra
    02/03/2023
    UKI T/A DIRECTLINE After
    -30
    dog
    03/03/2023
    SAVINGS ACCOUNT
    60
    From Savings
    04/03/2023
    before BRITISH GAS after
    55
    Energy
    05/03/2023
    WATER
    -150
    Energy
    09/03/2023
    09MAR23 CD , TESCO STORES 2167,
    12.45
    10/03/2023
    CD , TESCO STORES 1234
    14.2
    16/03/2023
    16MAR23 , AMZNMKTPLACE, AMAZON.CO.UK
    22.22
    18/03/2023
    18MAR23 CD , SAINSBURYS S/MKTS , LONDON
    13.2
    Last edited by sandy666; 03-31-2023 at 07:07 AM.

  16. #16
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    oops, now fixed, thanks.

  17. #17
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Matching two columns and returning the third?

    you need to declare which description is for
    how is excel supposed to know which description is for food and which is something else

    post#15 was edited

    anyway check this one

    Date Type Description Value Category
    01/03/2023
    Before UKI T/A DIRECTLINE
    -20
    wife
    01/03/2023
    Text before UKI T/A DIRECTLINE and after
    -10
    wife
    02/03/2023
    Savings Account
    -50
    To Savings
    02/03/2023
    UKI T/A DIRECTLINE
    -40
    wife
    02/03/2023
    UKI T/A DIRECTLINE After
    -30
    wife
    03/03/2023
    SAVINGS ACCOUNT
    60
    To Savings
    04/03/2023
    before BRITISH GAS after
    -89999
    Energy
    05/03/2023
    WATER
    -150
    Energy
    09/03/2023
    09MAR23 CD , TESCO STORES 2167,
    12.45
    Food
    10/03/2023
    CD , TESCO STORES 1234
    14.2
    Food
    16/03/2023
    16MAR23 , AMZNMKTPLACE, AMAZON.CO.UK
    22.22
    Amazon
    18/03/2023
    18MAR23 CD , SAINSBURYS S/MKTS , LONDON
    13.2
    Food
    Last edited by sandy666; 03-31-2023 at 07:05 AM. Reason: added file

  18. #18
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    Ahh, it's clever how you are using an If statement to do the partial matches, and how you manipulate the Transactions first before doing a join. I really appreciate you taking the time to help with this.

    There is unfortunately a problem with the resulting table. The Category column has the same "wife" category for each of the different "UKI T/A DIRECTLINE" values, whereas each one should be different depending on the matched value. Sorry about this, I can see how much manipulation you're having to implement to cater for my obscure requirements. Hopefully this isn't too much of a pain to fix.

    Here's a screenshot to show what I mean:
    tmp_excel2.png
    Last edited by jarrah31; 03-31-2023 at 08:45 AM.

  19. #19
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    your screenshot is attached improperly again

  20. #20
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    I don't know what's happening there. I clicked the "Insert Image" icon, selected the image from my computer, and clicked "upload file". The resulting line had ATTACH within square brackets, a number, and then \ATTACH after the numbers.
    When I went back to edit, I deleted the line and repeated the same process, with the same results, but this time the embedded image worked.
    Maybe it's because my first reply was done within "Quick Reply", and the edit was within the full fat reply dialog?

  21. #21
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    wrong way, use
    ...............goadv.png
    for excel files and pictures

    you need rewrite clear-cut your DescriptionKey because with existing one you have what you see

    but you can already do everything yourself, you have three options so use one
    Last edited by sandy666; 03-31-2023 at 09:20 AM.

  22. #22
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    ok thank you, I'll have a play.

  23. #23
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    [QUOTE=sandy666;5809661]wrong way, use
    ...............Attachment 824056
    for excel files and pictures

    Is it possible to remove the Insert Image icon from Quick Reply if it doesn't work in there?

  24. #24
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Matching two columns and returning the third?

    Why not use a conventional formula:

    =IFERROR(INDEX(CATEGORY,MATCH(1,(ISNUMBER(FIND(DESCRIPTION,C2)))*(AMOUNT=D2),0)),"")

    copied down, or this (delete expected results first) which spills down:

    =MAP(C2:C9,D2:D9,LAMBDA(x,y,IFERROR(INDEX(CATEGORY,MATCH(1,(ISNUMBER(FIND(DESCRIPTION,x)))*(AMOUNT=y),0)),"")))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  25. #25
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Matching two columns and returning the third?

    Is it possible to remove the Insert Image icon from Quick Reply if it doesn't work in there?
    edit post and remove whatever you want

  26. #26
    Registered User
    Join Date
    02-10-2013
    Location
    UK
    MS-Off Ver
    Office 365, Version 2208
    Posts
    24

    Re: Matching two columns and returning the third?

    Quote Originally Posted by Glenn Kennedy View Post
    Why not use a conventional formula:

    =IFERROR(INDEX(CATEGORY,MATCH(1,(ISNUMBER(FIND(DESCRIPTION,C2)))*(AMOUNT=D2),0)),"")

    copied down, or this (delete expected results first) which spills down:

    =MAP(C2:C9,D2:D9,LAMBDA(x,y,IFERROR(INDEX(CATEGORY,MATCH(1,(ISNUMBER(FIND(DESCRIPTION,x)))*(AMOUNT=y),0)),"")))
    Wow, that's an awesome formula, thank you very much Glenn!! It works perfectly, and I didn't know you could make it spill down the column like that! Very nice indeed.

    I'll use a combination of Power Query to scan a folder for data files, and this formula to produce the categories.

    Thank you very much everyone for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Returning the headers of all columns with a matching value
    By smohyee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-08-2021, 06:33 PM
  2. Comparing Columns and returning matching value
    By VegasL in forum Excel General
    Replies: 4
    Last Post: 12-28-2018, 03:24 AM
  3. Replies: 2
    Last Post: 11-14-2013, 01:44 PM
  4. Replies: 2
    Last Post: 12-30-2011, 07:30 PM
  5. Matching two columns and returning third value
    By snashte in forum Excel General
    Replies: 4
    Last Post: 08-01-2010, 01:30 AM
  6. Matching 2 columns and returning a value to a cell
    By AS1978 in forum Excel General
    Replies: 1
    Last Post: 02-21-2008, 08:47 AM
  7. [SOLVED] Returning a Value by Matching Two Columns of Data
    By Christine Edwards in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-10-2006, 02:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1