Extract two column values based on top 5 of one column, without grabbing the rest of the columns

41 Views Asked by At

I have a sheet with all kinds of values, the most important ones:

Column B2 to 256: Color name
Column F2 to 256: Sold items

I need to grab the top 5 color names and amount of sold items, without grabbing the rest of the columns.

1

There are 1 best solutions below

0
marikamitsos On BEST ANSWER

You mention:

...grab the top 5 color names and amount of sold items, without grabbing the rest of the columns.

There are different ways to read your request

If your question is:

  • Grab the top 5 color names (meaning 5 colors with most sold items) and amount of sold items, use the formula in H3

    =QUERY(A1:F,"select B, sum(F) where B is not null 
               group by B order by sum(F) desc limit 5 label sum(F) 'MOST Sold' ",1)
    

If your question is:

  • Grab the top 5 color names (meaning top 5 colors as they appear in column B) and amount of sold items, use the formula in H11

    =QUERY(A1:F,"select B, sum(F) where B is not null and B matches '"&JOIN("|",(ARRAY_CONSTRAIN(UNIQUE(B2:B),5,1)))&"' 
               group by B order by sum(F) desc limit 5 label sum(F) 'MOST Sold' ",1)
    

enter image description here

(Please adjust ranges to your needs)
If I misunderstood your question, please share a test sheet so as you can be easier helped.

Functions used: