Find first n summed values in Excel with criteria - excel

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.

Related

Find element in a matrix in excel [duplicate]

I have the following Excel spreadsheet:
A B C D E F
1 MFC2 MFC1 QFC Search Criteria: CW14
2 CW11 Column Name: MFC1
3 CW13
4 CW14
5 CW17
6 CW18
7 CW19
8
9
In Cells A1:C8 I have different calender weeks. All of them are unique!
In Cell E2 I want that the column name is displayed based on the value that is put in Cell E1.
In this case the search criteria is CW14 so the result should be column name MFC1.
I tried to modify the formula from this question but could not make it work:
E1 = INDEX($A$1:$C$1,MATCH(E$1,$A$2:$C$30,0))
This formula gives me #NV as result.
What do I need to change to get the desried result?
Use AGGREGATE instead of MATCH:
=INDEX(1:1,AGGREGATE(15,7,COLUMN($A$2:$C$30)/($A$2:$C$30=$E$1),1))
=INDEX($A$1:$C$1,MAX(ISNUMBER(FIND(E1,$A$2:$C$7))*COLUMN($A$2:$C$7)))

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

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

Sumproduct matching values in excel

I have two excel tables:
A B C D E
1 John 10 Mark 2
2 Tommy 20 Tommy 3
3 Jane 15 John 4
4 Kate 2
5 Jane 1
Is there a function to sumproduct values in colum B with those values in column E which match by name, i.e. 10*4 + 20*3 + 15*1 ?
You can use sumif for this and just sum up the results when you are done:
=B1 * sumif(D:D, A1, E:E)
Copy that down your sheet, and then add up the totals.
If you don't want a ton of formulas hanging out on your sheet, you could convert this to a CSE/Array formula:
=SUM($B$1:$B$3*SUMIF(D:D, $A$1:$A$3,E:E ))
Just enter that in and hit Ctrl+Shift+Enter to enter it. It will get curly braces around it, which means it's an Array formula.
Since you asked about sumproduct, we could use SUMPRODUCT
=SUMPRODUCT(($A$1:$A$5=A1)*$B$1:$B$5)*SUMPRODUCT(($D$1:$D$5=A1)*$E$1:$E$5)
Now that is assuming there are no repeats (all names are unique). In the event that names are not unique you will have those numbers added together then multiplied.
After you apply that to a column and copied down appropriately, lets say F1 to F3, in F5 you could get your final answer using:
=SUM(F1:F3)

A function that will lookup a reference

Before I get started thanks for taking your time and helping.
This is what my worksheet looks like:
Row # B C D E F
2 1 Product 1 B2 B3 B4
3 2
4 6
5 1 Product 2 B5 B6
6 5
7 4 Product 3 B7
I was trying to follow this formula: (The best answer one or green check mark) return values from multiple matching rows
I got all the way to the =IFERROR(INDIRECT(lookups!H5),"") but can not get this to work.
What I am tying to do is order the numbers in Column B to go to the right of the product. Which I was able to get the column it is in (B) and the row number it is in (B2). I would like to change the value (B2) to the number that is there.
I would like it to look like this:
Row # C D E F
2 Product 1 1 2 6
3
4
5 Product 2 1 5
6
7 Product 3 4
If someone could help explain this to me or find a better way that would be great.
Not sure what is to happen to columnB but if you replace B with "="B throughout columns D:F then select each of these in turn and apply Text to Columns with Tab as the delimiter the 'cell references' convert to formulae referring to the values in B. If you want to delete columnB copy D:F and Paste Special, Values over the top.

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