简体   繁体   中英

Google Sheets, returning a text value based on relative rank

I'm trying to create a relative ranking structure based on cell values within a repeating range.

I have ranked the text values accordingly. Text Ranks

I then have a sheet with columns that contain subsets of these text values like so; Text Value Table

What I am trying to accomplish, is that when a Rank of 1 is entered into a cell in row A, it will return the highest value of that row based on the column values in row B. So as an example;

If 1 was entered into cell A2, it would return "Text 1" in B2. If 2 was entered in A2 it would return "Text 3" in B2. If 3 was entered in A2 it would return "text 5". If any other rank (4-20) was entered B2 would remain blank. The same would happen in Row 3 except it would consider "Text 2" as rank 1, "Text 3" as rank 2, and "Text 4" as rank 3.

I can make this work in Excel with XLOOKUP but I've been unable to solve the problem with Google Sheets, any help here would be extremely appreciated!

Try this one:

Formula (B7):

=IFERROR(INDEX(ARRAYFORMULA(VLOOKUP(SORT(VLOOKUP(TRANSPOSE(C7:7), {Sheet2:$B$2,$B$21:Sheet2,$A$2,$A$21}, 2: FALSE)), Sheet2,$A$2,$B$21, 2, FALSE)), A7), "")

Sheet2:

表2

Output:

输出

Formula steps:

  1. TRANSPOSE the row into column to be able to use VLOOKUP and compare it to the Sheet2 Table.
  2. Use VLOOKUP to return the rank.
  3. SORT the rank.
  4. VLOOKUP again to look the values in the Sheet2 and now return the text values
  5. At this point, we now have the list of sorted text values based on our row values, now we use the given rank and get the sorted text value based on rank using INDEX
  6. If it returns #N/A , return blank instead.

Step by step visualization of the formula for the 7th row:

可视化

If you're OK copying down the formula, then this should work:

=iferror(index(split(textjoin(char(6655),true,$C2:$G2),char(6655)),$A2),"")

The values on the row are joined together using TEXTJOIN , separated by CHAR(6655) which is a character you wouldn't expect to have in your text. The true in the TEXTJOIN removes blank cells. Then SPLIT breaks the text into separate cells using CHAR(6655) .

INDEX then gets the corresponding cell value dependent on your Rank value in column A.

IFERROR displays nothing ( "" ) if the Rank value is greater than the number of cells of data.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM