+ Reply to Thread
Results 1 to 15 of 15

Need help with formula to list unique values from a list based on a condition

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Need help with formula to list unique values from a list based on a condition

    Please help! As soon as I insert the IF function around the INDEX/MATCH function, the formula stops working.

    I am looking to get all values from a list based on a condition, i.e. i need the origins for one particular destination.
    A simplified sample data set is attached, including my failing formula.

    The result I'm looking for, based on all Canadian origins, is:
    French - 25'000
    German - 20'000

    Duplicates should not be omitted, i.e. if there were 2 French origins, they should appear on separate rows in the new list.

    Thanks for your support in advance!
    Attached Files Attached Files
    Last edited by mischge; 08-03-2016 at 04:25 PM.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Need help with formula to list unique values from a list based on a condition

    You need to put quotes ( " ) around Canada in your formula, as it is a text value.

    Also, the formula you are trying to use is an array formula, so you need to commit it using the key combination of Ctrl-Shift-Enter (CSE), rather than the usual < Enter >.

    I'm not sure what you are trying to do though, so I don't know if that gives you what you want when you copy it down.

    Hope this helps.

    Pete

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help with formula to list unique values from a list based on a condition

    Try this...

    Data Range
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    2
    Date
    Origin
    MT
    Destination
    Canada
    French
    25000
    3
    4/1/2017
    French
    25,000
    Canada
    German
    20000
    4
    4/1/2017
    Italian
    30,000
    US
    5
    4/1/2017
    German
    20,000
    Canada
    6
    4/1/2017
    TBD
    30,000
    US


    This array formula** entered in H2:

    =IFERROR(INDEX(B:B,SMALL(IF($D$3:$D$6=$G$2,ROW(D$3:D$6)),ROWS(H$2:H2))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy across to I2 then down until you get blanks.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Need help with formula to list unique values from a list based on a condition

    Thanks Pete, that made sense!

    Tony, thanks for your input as well. The formula works, but it will not repeat same Origins.
    Replace "German" with "French", and my desired outcome would be 2 lines with French - 25'000 and French - 20'000.

    To further complicate matters, I also need it to be within a date range (for example within April 2017).

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help with formula to list unique values from a list based on a condition

    How about updating your sample file and show us what results you expect.

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Need help with formula to list unique values from a list based on a condition

    The solution in the attached file does not make use of array formulae, so hopefully you'll be able to understand it more easily.

    I've used G1 for the date that you are interested in (enter it as the 1st of the month, though it will only display the month and year), and then put this formula in cell E3:

    =IF(AND(D3="Canada",A3>=$G$1,A3<=EOMONTH($G$1,0)),MAX(E$2:E2)+1,"-")

    This can be copied down as far as you like (as shown by the hyphens) and it sets up a criteria of being within the month specified in G1 AND having a destination of "Canada" - if this is met then it just sets up a unique sequential numbering for those records. Then in G4 you can have this formula:

    =IFERROR(INDEX(B:B,MATCH(ROWS($1:1),$E:$E,0)),"")

    which will bring the origin country for the record marked with a 1 in column E, and you can copy the formula into H4 to get the appropriate MT value. When you copy the formulae down, the ROWS($1:1) part becomes ROWS($1:2), and so will bring the second record which matches the criteria, and so on for subsequent rows. Copy the two formulae down as far as you need them (until you get blanks), and then you can change the date in G1 to see the extract change - I've added some records for May 2017.

    Hope this helps.

    Pete
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Need help with formula to list unique values from a list based on a condition

    Peter_UK, Thanks a lot! I see where your "helper column" is useful.
    However, I have to show a full quarter (April, May, June), so 3 helper columns would be required, which I am trying to avoid.
    Is there a way to combine the formula from the helper column into the MATCH/INDEX function?

    I was looking at Tony Valko's approach again as well. But I failed at even getting it to even reference the date range, let alone match the MT with the Origin.

    May I ask you to help once again?

    Thank you!
    Attached Files Attached Files

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help with formula to list unique values from a list based on a condition

    I'm confused!

    Here are the results from your file:

    Data Range
    F
    G
    H
    I
    3
    Destination
    Origin
    MT
    4
    4/1/2017
    Canada
    French
    20,000
    5
    French
    25,000
    6
    German
    25,000
    7
    Italian
    30,000
    8


    And here is the raw data:

    Data Range
    A
    B
    C
    D
    2
    Date
    Origin
    MT
    Destination
    3
    4/1/2017
    French
    25,000
    Canada
    4
    4/1/2017
    Italian
    30,000
    US
    5
    4/1/2017
    French
    20,000
    Canada
    6
    4/15/2017
    TBD
    30,000
    US
    7
    5/1/2017
    German
    25,000
    Canada
    8
    5/3/2017
    French
    30,000
    US
    9
    5/7/2017
    Italian
    20,000
    Canada
    10
    5/21/2017
    TBD
    30,000
    US


    Your results include German and Italian yet these entries do not fall within the date range.


  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Need help with formula to list unique values from a list based on a condition

    You can change the formula in E20 to this:

    =IF(AND(D20="Canada",A20>=$G$18,A20<=EOMONTH($G$18,2)),MAX(E$19:E19)+1,"-")

    (note the change in red) in order to include 2 months in addition to the starting month - just copy this down and the secondary table will give the same results as yours.

    Hope this helps.

    Pete

  10. #10
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Need help with formula to list unique values from a list based on a condition

    @Tony Valko: I didnt say my formulas worked!

    @ Pete_UK: I need each month in a separate table. It's the requested format I have to deliver.

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Need help with formula to list unique values from a list based on a condition

    Quote Originally Posted by mischge View Post
    ... I need each month in a separate table...
    Your sample file in Post #7 doesn't show that. Perhaps you could attach a more realistic file showing more examples of what you have and what you want to achieve from it.

    Pete

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help with formula to list unique values from a list based on a condition

    Quote Originally Posted by mischge View Post
    @Tony Valko: I didnt say my formulas worked!
    I asked you to show us what results you expect and I assumed those were the results you expected!

    Try this...

    Data Range
    F
    G
    H
    I
    3
    Destination
    Origin
    MT
    4
    4/1/2017
    Canada
    French
    25000
    5
    French
    20000
    6


    This array formula** entered in H4:

    =IFERROR(INDEX(B:B,SMALL(IF(($A$3:$A$10>=$F$4)*($A$3:$A$10<=EOMONTH($F$4,0))*($D$3:$D$10=$G$4),ROW(D$3:D$10)),ROWS(H$4:H4))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy across to I4 then down until you get blanks.

  13. #13
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Need help with formula to list unique values from a list based on a condition

    @Peter_UK: see attached.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    07-30-2013
    Location
    binningen
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Need help with formula to list unique values from a list based on a condition

    @ Tony Valko: Amazing! Thank you so much! Works like a charm

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help with formula to list unique values from a list based on a condition

    You're welcome. Thanks for the feedback!

+ 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. Data Validation List - Formula to Sort and Return Unique Values in List
    By beewketu in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-14-2015, 04:18 PM
  2. List Unique Values Based On Criteria
    By tangmere.milli in forum Excel General
    Replies: 5
    Last Post: 03-16-2015, 09:49 AM
  3. [SOLVED] Unique list based on condition
    By bdrilling33 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-11-2014, 10:27 AM
  4. [SOLVED] formula required to list cell values based on condition
    By kiranpat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2014, 04:54 AM
  5. [SOLVED] Need unique list based on another list and incorporating =RIGHT(...) formula
    By NS4Excel in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 03-31-2014, 10:10 PM
  6. Count unique values and create list based on these values
    By vipa2000 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  7. Counting unique items in a list based on a condition
    By George Lynch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2005, 09:06 AM

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