Google Sheets - formula to return N first values from range A where MAX(range B) - excel

F1:N1 with random numbers (can have duplicates).
F2:N2 with sorted numbers.
Need a formula to fill in A1:C1 with values from F2:N2 where F1:N1 has a maximum value.
In the example it should be 1,8,3 from F2:N2 - according to 9,9,8 from F1:N1.
_ A B C D E F G H I J K L M N
1 ? ? ? 9 3 8 1 5 5 3 9 8
2 1 2 3 4 5 6 7 8 9

You can do this with a "helper row" to create a list of unique ranks:
F3: =RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1
and fill right to N3
Since your values in F2:N2 are sequential {1...8}, you can use this formula:
A1: =MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0)
and fill right to C1
If the values in F2:N2 are random, then you can use this:
A1: =INDEX($F$2:$N$2,1,MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0))
and fill right to C1

Nobody has jumped in to offer a Google Sheets solution so here is one:
=query(transpose(sortn(transpose(F1:N2),3,,1,false,2,true)),"select Col1,Col2,Col3 limit 1 offset 1")
In A1. This is a self-expanding formula so does not need to be filled across and does not need helper rows.
EDIT
'Limit 1' may be omitted in the above formula as mentioned in the comment.
Also this is a little shorter:
=transpose(query(sortn(transpose(F1:N2),3,,1,false,2,true),"Select Col2"))

Formula in A1 = INDEX($F$2:$N$2,MATCH(COLUMN(A1),$F$3:$N$3,0)) and is dragged till C1
Formula in F3 = RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1 and is dragged till N3

Related

how to average first n numbers in ms excel

I have two columns in an Excel spreadsheet that look like:-
Key Values
f 1
f 2
u 3
g 4
g 5
h 6
h 7
j 8
j 9
k 10
k 11
k 12
I want to create apply formula which creates an average of first n numbers in ms excel.
I Try this:-
=AVERAGE(B:B,10)
but could not get the answer.
Please help me for give me appropriate answer.
Avoid volatile set-ups with OFFSET or INDIRECT where possible:
=AVERAGE(B2:INDEX(B:B,n+1))
Or, as pointed out by #JvdV:
=AVERAGE(TAKE(B:B,n+1))
Replace n as desired.
in cell E1: enter the number of rows to take into account for average
in cell F1: enter ="B1:B"&E1
in cell E4: enter =AVERAGE(INDIRECT(F1))
Rgds
Frederik

Dragging formulas across - Increment columns by more than 1

I can't seem to find anything similar that's already been asked (they all relate to incrementing row numbers rather than columns)
I'm looking to drag a formula across horizontally and have the columns increment by 2
E.g. B1-A1, D1-C1, F1-E1...
Thanks!
You'll need to have a value in cell A1 and B1 for the following to work.
For my testing I put the number 1 in A1 and B1.
Try this in Cell C1:
=IF(MOD(COUNT($A$1:B1),2)=0,COLUMN(B1),IF(B1<>A1,B1,A1))
Here's what you should see when you drag that formula across:
A B C D E F G H I J K L M N
1 1 2 2 4 4 6 6 8 8 10 10 12 12
And this is what the formula does:
The MOD(COUNT() part of the formula counts the cells to the left of it, and if they are a multiple of 2, the value changes.
I've left the value to change to (the 'new' value) as the COLUMN() number for the cell before, just for example's sake. but you can change this part.
The last IF statement at the end checks if the cell before is equal to the cell before that, (eg. Is CELL C1 equal to CELL B1) and if they are not equal, it will give the cell before as a value (the 'copy' value).

Find first n summed values in Excel with criteria

I have the following table:
Sheet 'raw':
Account | Value
A 2
A 3
B 5
C 2
A 1
B 4
D 8
F 18
D 4
What I would like to capture the top n accounts by sum of values using only Excel formulas:
Sheet2:
Top | Account | Sum
1 F 18
2 D 12
3 B 9
4 A 6
4 C 2
I tried this approach (considering A to C columns in Excel):
- for the value:
{=LARGE(ROUND(raw!B$2:B$65000,2)+ROW(raw!B$2:B$65000)/10000),A2)}
for the account name:
{=INDEX(raw!$A$2:$A$65000,MATCH(A2,(ROUND(raw!B$2:B$65000,2)+ROW(raw!B$2:B$65000)/10000),0))}
I use array formulas for that, but it will provide me the top individual values not the sum per account
Could someone help me on this topic?
Thank you in advance!
With your dataset following seems to work:
In cell C2, CTRL+SHIFT+ENTER and not just ENTER following formula:
=LARGE((ROW(Sheet1!$A$2:$A$10)=MATCH(Sheet1!$A$2:$A$10,Sheet1!$A$1:$A$10,0))*SUMIF(Sheet1!$A$2:$A$10,Sheet1!$A$2:$A$10,Sheet1!$B$2:$B$10),ROWS($C$2:$C2))
In cell B2, CTRL+SHIFT+ENTER and not just ENTER following formula:
=INDEX(Sheet1!$A$2:$A$10,MATCH(Sheet2!C2,(ROW(Sheet1!$A$2:$A$10)=MATCH(Sheet1!$A$2:$A$10,Sheet1!$A$1:$A$10,0))*SUMIF(Sheet1!$A$2:$A$10,Sheet1!$A$2:$A$10,Sheet1!$B$2:$B$10),0))
Edit: There's typo in the formula Sheet2!D2 should be Sheet2!C2.Above formula is corrected.
CAUTION: Formula may give incorrect results if totals tie.

How to match columns and adding blank rows in excel

I have an excel file with 5 rows in column A and B, and 3 in column C and D (in reality though, I have a couple of hundreds of rows). Column B consists of text belonging to A, and D of text belonging to C. Column C has some of the values found in column A.
It looks like this:
A B C D
1 1 stringA1 1 stringC1
2 2 stringA2 2 stringC2
3 3 stringA3 4 stringC3
4 4 stringA4
5 5 stringA5
Now, I would like to match the numbers in column C with those in A, so that matches are put in the same row. For those rows in A for which there is no match in C, I want to have blank cells after column B.
It would look like this in this case:
A B C D
1 1 stringA1 1 stringC1
2 2 stringA2 2 stringC2
3 3 stringA3
4 4 stringA4 4 stringC3
5 5 stringA5
I have some idea that I should use VLOOKUP and maybe Conditional Formatting, but unfortunately I am not very experienced in excel. Could someone please suggest a way to do this?
Enter the following formula in Cell E1:
=IF(IFERROR(MATCH(A1,$C$1:$C$5,),"")<>"",INDEX($C$1:$D$5,IFERROR(MATCH(A1,$C$1:$C$5,),""),1),"")
and this one in Cell F1:
=IF(IFERROR(MATCH(A1,$C$1:$C$5,),"")<>"",INDEX($C$1:$D$5,IFERROR(MATCH(A1,$C$1:$C$5,),""),2),"")
Using Helper Column:
You can also do this using a helper column.
In Cell E1 write:
=IFERROR(MATCH(A1,$C$1:$C$5,),"")
Then in Cell F1 write:
=IF(E1<>"",INDEX($C$1:$D$5,E1,1),"")
And finally in Cell G1 write:
=IF(F1<>"",INDEX($C$1:$D$5,E1,2),"")
This was answered by #user3514930 to a question here.
You can directly use this formula in D2 and copy downwards:
=IF(A2 = C2, A2, "")
Now if you have formulas in A2, C2, type in those formulas in place of A2, C2 in the above.

How to select a value given a set of criteria

I have the following table and would like to select the $
for products when index = max:
id product $ max?
1 A 1 No
2 B 2 No
3 A 2 No
4 C 4 No
5 D 5 No
6 A 3 Yes
7 B 6 Yes
8 C 8 Yes
How do I get the results in the column identified max?
Regards.
UPD:
The results should be based on the max id and not max $. I am sorry for the confusion
If you need formula for max column based on max id, try next one:
=IF(MAX(IF(B:B=B2,A:A))=A2,"Yes","No")
where B:B column with your products, A:A - column with id.
Just select D2, enter formula in formula bar, and press CTRL+SHIFT+ENTER to evaluate it and then drag it down.
Note, if you know exact ranges of your data, you can change B:B and A:A to e.g. $B$2:$B$100 and $A$2:$A$100

Resources