+ Reply to Thread
Results 1 to 16 of 16

Creating a top 5 list with conditionals

  1. #1
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Question Creating a top 5 list with conditionals

    Hi all,

    "New" guy to the forum here, as in "I've been lurking but not registering and posting".
    I have a situation that I can't find any good examples for, nor do I find a working solution, so I hope someone with a good idea can help me.

    I have a large dataset, a matrix of about 20000 lines and 25 columns. This is data I use to track a lot of different aspects and some of the statistics for it are presented on another sheet. There's one thing missing on this presentation; several top 5 lists that meets certain criteria. I have managed to do this with pivot tables and directly referencing the result in the presentation, but it's not an ideal way to do it.

    The attached picture shows an analogy of what I try to achieve.

    To describe the picture in text:
    I want to return the "Sales ID" for the line that contains the maximum of "Sold for" if "Species" is "Cat". That way I can use VLOOKUP to fill in the other fields as I wish.
    Next line should be similar, but it's the second highest value that meets the same criteria, and so on until I have a top 5 list (or top 10 for that matter).
    Using pivot table with the filters I want makes this an easy task, so I would assume it's trivial to do it in a formula too, but for once I have to give up and try to look for fresh ideas on how to do it.

    If anyone can suggest anything, please do so - it will be much appreciated

    Thank you.
    Attached Images Attached Images
    -- ohmega --
    ..still mangling Excel sheets

  2. #2
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    Hi
    Can you upload the excel file? The print screen is not worth much....

  3. #3
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Re: Creating a top 5 list with conditionals

    Hi,
    Yes, I was thinking about that too, so here it is
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    Thanks.
    Try this in C35 and down:
    =AGGREGATE(14,6,(($B$2:$B$31=$A$33)*($D$2:$D$31)),ROWS($A$1:A1))

  5. #5
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Re: Creating a top 5 list with conditionals

    Thank you for a prompt reply.

    I never discovered the Aggregate function, nice to know

    This formula works to some extent; it gives me the top 5 resulting values, but ideally I want to return the corresponding "Sales ID" (columns A) so I can lookup the name or anything else on that row based on the "Sales ID".

    Maybe I misunderstood your example or I may have been unclear in what I try to achieve (?).
    The "Species" will be given for each top 5 list (constant "Cat" in A33), while the top 5 will need a sales ID, a name and a value listed.

  6. #6
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    Hi,
    For A 35 use this:
    =XLOOKUP(B35&C35,$C$2:$C$31&$D$2:$D$31,$A$2:$A$31)

    For B35:
    =INDEX($C$1:$C$31,AGGREGATE(15,6,ROW($D$2:$D$31)/(($A$33&C35=$B$2:$B$31&$D$2:$D$31)),COUNTIF(C$34:C35,C35)))

    See attached.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    You first need to search the top 5 - then all the rest of the details are being derived from that....

  8. #8
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Re: Creating a top 5 list with conditionals

    Thank you - that gave some meaningful results.
    I applied it to my existing workbook with the live data, and it seemingly worked okay. After some double checks, I see that it will trigger a bit randomly when there are some duplicate data matching "Sold for" and "Species", but have different "Sold by".

    I think this requires a better example from me, since the actual sheet have quite a few conditionals and the end result should really be the "Sales ID" so I can use VLOOKUP on it. Unfortunately the actual workbook is shock full of sensitive data, so I will create and attach a much better example later.

    Anyway, thank you for your awesome help so far!

  9. #9
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    OK, that's why your file should be representative, so that you will be able to apply the solution on your original file....
    I wont count on Vlookup in that case because you have duplicate values and Vlookup will find only the 1st match always.....I think this is more complicated than Vlookup...

  10. #10
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Re: Creating a top 5 list with conditionals

    Hi,

    I have now created a new example file that should be more representative for the dataset I'm working with. I have included an example result list (3 of them actually) and an additional sheet that shows how it could be solved with a pivot table.
    Maybe it's best to have a hidden sheet that contains those pivot tables after all? That's what I've done before, but I think it's an improper way of doing it.

    Hopefully Microsoft creates a streamlined function for this type of thing in the future, since I don't think I'm the only one needing such results all the time
    Attached Files Attached Files

  11. #11
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Creating a top 5 list with conditionals

    well, if you just need to generate the SO_ID, relative to top 1 to n, then:

    A39: =ROUND(MOD(AGGREGATE(14,6,(orderlist[Price]+(orderlist[so-id]/10^7))/(orderlist[Transmission]="Manual")/(orderlist[Warranty]="Yes"),ROWS(A$39:A39)),1)*10^7,0)
    copied down

    you could use some O365 functions to do re-generate the table (on top n basis using SORT, FILTER, SEQUENCE etc), but this is what Pivots are built for...
    not immediately obvious why you do not want to use your Pivots (with a Top N filter applied to the Values)

  12. #12
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    OK, so your vlookup demonstrates exactly the problem I was talking about showing in lines 42&43
    See that both models in both lines makes Ford&Corier, while it should be :

    1. Ford Courier
    2. Opel Zafira

    Vlookup will not fit here if you have duplicate values (1950) since it will return just the FIRST match

  13. #13
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    For E39:
    =AGGREGATE(14,6,(($F$2:$F$31="Manual")*($J$2:$J$31="yes")*($I$2:$I$31)),ROWS($A$1:A1))

    D39 and drag to the right/down:
    =INDEX(D$1:D$31,AGGREGATE(15,6,ROW($C$1:$C$31)/(($F$1:$F$31="MANUAL")*($I$1:$I$31=$E39)*($J$1:$J$31="YES")),COUNTIF($E$38:$E39,$E39)))

    As I explained above - you cant use vlookup to search the other values because of the duplicate results in prices...


    For the other tables - you need to change the criteria and the range they pertain to....so in example 2 instead of "YES" for warranty & "MANUAL" for transmission - apply "BASIC" for stereo & "JOHN" for responsible....
    Attached Files Attached Files

  14. #14
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Creating a top 5 list with conditionals

    just for sake of clarity, in post#11, we return the SO_ID rather than the Price, and given the SO_ID is a primary key you can return the remaining columns using standard VLOOKUP

    in the Aggregate in post#11 the SO_ID is appended to the Price as a decimal (so Price determines Top 1 to N), and the outer MOD etc then isolates the SO_ID value.

    (orderlist[Price]+(orderlist[so-id]/10^7))

  15. #15
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Creating a top 5 list with conditionals

    Quote Originally Posted by ohmega View Post
    the end result should really be the "Sales ID" so I can use VLOOKUP on it.
    OK I understand your line of thought, if the Sales ID is unique - you can use the Vlookup to search all other columns - your manual example confused me a little since rows 42&43 returned the same values but it was because you applied the wrong SALES ID (170010 instead of 170030) not because of the duplicate sale amount....so XLent's solution answers your request...

  16. #16
    Registered User
    Join Date
    02-18-2021
    Location
    Oslo, Norway
    MS-Off Ver
    365
    Posts
    6

    Cool Re: Creating a top 5 list with conditionals

    Thank you so much, belinda200 and XLent!
    The final solution seems to be working perfectly when implemented into my workbook. I did have make one minor adjustment since the SO-ID was a bit longer than shown in my example.

    =ROUND(MOD(AGGREGATE(14,6,(orderlist[Price]+(orderlist[so-id]/10^7))/(orderlist[Transmission]="Manual")/(orderlist[Warranty]="Yes"),ROWS(A$39:A39)),1)*10^7,0)
    was modified to
    =ROUND(MOD(AGGREGATE(14,6,(orderlist[Price]+(orderlist[so-id]/10^8))/(orderlist[Transmission]="Manual")/(orderlist[Warranty]="Yes"),ROWS(A$39:A39)),1)*10^8,0)

    So far it have passed my sanity checks, so hopefully this will be sufficient.
    Now I have to analyze that formula and really learn what's going on. AGGREGATE with all its functions and inputs is currently a small puzzle to me, even though I had no issue implementing it.

    Again, thank you for your super expertise

+ 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. Drop down list with conditionals
    By radicaled in forum Excel General
    Replies: 2
    Last Post: 09-29-2017, 04:57 PM
  2. Summing a list of weighted conditionals
    By hagamablabla in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-16-2015, 04:35 PM
  3. [Help] creating a list from a number, then creating sheets from the list.
    By BallardBandit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2015, 01:16 AM
  4. Need help with Conditionals
    By JennyDD in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-16-2014, 12:33 PM
  5. Only list some conditionals
    By JonasGrumby in forum Excel General
    Replies: 1
    Last Post: 05-23-2007, 05:54 AM
  6. [SOLVED] Conditionals
    By Salvador Enríquez M in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-18-2006, 05:20 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