Formula to find top 25 from the data set - excel

I've the following data and 10 more columns: What's the best formula to pull top 20 or top 25 of x and y combined? Should I go Index Match. If it's a macro, I'll have to write the code. I would prefer formula over code. Any suggestion?
100 x
50 y
6 z
89 x
5 x
24 y

Essentially, you are looking for a pseudo-LARGEIF formula. This can be based on the LARGE function and the INDEX function as a standard (non-array) formuala.
      
The formulas in D3:F3 are,
=LARGE(INDEX(($A$2:$A$99)*(($B$2:$B$99="x")+($B$2:$B$99="y")), , ), ROW(1:1)) ◄ LARGEIF column B is x or y
=LARGE(INDEX(($A$2:$A$99)*($B$2:$B$99=$E$2), , ), ROW(1:1)) ◄ LARGEIF column B is x
=LARGE(INDEX(($A$2:$A$99)*($B$2:$B$99="y"), , ), ROW(1:1)) ◄ LARGEIF column B is y
If you have a lot of choices, you can use an array of constants to match. D3 could also be,
=LARGE(INDEX(($A$2:$A$99)*($B$2:$B$99={"x","y"}), , ), ROW(1:1)) ◄ LARGEIF column B is x or y
Fill down as necessary. These are standard formula and do not require CSE.

Related

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

SUMIFS with multiple criteria and OR logic in multiple columns

I found here an example for doing a sumifs with multiple criteria and OR logic, but I tried with multiple to do it for multiple columns and it is not working.
Here is an example. Base on this dataset:
A1 B1 C1 D1
B X u 11
B X u 22
A X t 22
B X t 22
I'm using the following formula:
=SUM(SUMIFS(D:D,B:B,"X",A:A,{"A","B"},C:C,{"t","u"}))
I get 55 as a result in the formula, but it should be 77 instead
If I change last row of the dataset it calculates correctly like:
A1 B1 C1 D1
B X u 11
B X u 22
A X t 22
A X t 22 --> Column A1 value changed from B to A
Is it possible to have multiple columns with multiple OR values?
Try,
=SUM(SUMIFS(D:D, B:B, "X", A:A, {"A","B"}, C:C, TRANSPOSE({"t","u"})))
By changing the 'direction' in which the second array of criteria is read, you get all possible combinations instead of paired combinations.
I was working on the same lines as #Jeeped but came up with
=SUM(SUMIFS(D:D,B:B,"X",A:A,{"A","B"},C:C,{"t";"u"}))
in order to change the direction of the second array.
Note: I don't know how you would easily extend this to include another set of criteria because you need another 'dimension'. As far as I can see it would have to look like this
=SUM(SUMIFS(D:D,B:B,{"X","X","X","X","Y","Y","Y","Y"},A:A,{"A","A","B","B","A","A","B","B"},C:C,{"t","u","t","u","t","u","t","u"}))

Formula to pull all data for Top 25

I've following data set and I've used Index- Large function
=LARGE(INDEX(($A$2:$A$99)*($B$2:$B$99={"x","y"}), , ), ROW(1:1))
... to find out Top 25 of x and y combined. How would I pull the Column that has listed fruits? I can't use Large since it's for Numbers only. I've 20 more columns that have text only. Any thoughts?
apple 100 x
banana 50 y
grapes 6 z
watermelon 89 x
cantaloupe 5 x
orange 24 y
You need to adjust the formula you provided for the correct columns first.
=LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))
When that is done, it can be used as matching criteria in a larger formula that also matches column C for x, y.
=IFERROR(INDEX(A$2:A$99, MIN(INDEX(ROW($1:$98)+(($C$2:$C$99<>{"x","y"})+($B$2:$B$99<>LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))))*1E+99, , ))), "")
In the sample image below, that formula would go into E4. Fill both right and down as necessary.
      
If the values in the nmbr column may be duplicated (while still matching {x, y}) then one formula cannot be used for the entire lookup table. Use the following in F4.
=LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))
E4 would be,
=IFERROR(INDEX(A$2:A$99, SMALL(INDEX(ROW($1:$98)+(($C$2:$C$99<>{"x","y"})+($B$2:$B$99<>LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))))*1E+99, , ), COUNTIF($F$4:$F4, $F4))), "")
Copy and paste E4 to G4 then select E4:G4 and fill down.
      
Note that when transcribing the formula for your own use, ROW(1:98) is the position within A2:A99, not the actual row on the worksheet.

3 Variable Weighted Average in Excel

I have 3 variables that I need to take a weighted average of.
I want to excel to calculate all possible combination of weights by .01 increments.
I have three columns in excel. Weight A, Weight B and Weight C. Weight A = 1-sum(Weight B + Weight C).
Fix Weight C to .01, Cell in column B will be = cell above + 0.01 (where the very first cell is just a value cell of 0.01)
This works, but then I have to manually search for where Weight A becomes negative and then manually change the cell in column B back to 0.01 (next cell continues the formula of cell above + 0.01), and then manually change the cell in column C to 0.02 and drag it down.
As you can see, I would have to do this for C=.03, .04, .05 ....etc. And then fix column B as .01, .02, .03 etc.
Is there a faster way of doing this? i.e. Excel finding all possible combinations of the sum of 3 cells summing to one?
Thanks in advance.
I believe I have a grasp on what you are trying to accomplish. Would your results look similar to the following?
        
The formulas in A2:C2 are,
=1-SUM(B2:C2) ◄ A2
=IF(SUM(A1)=0, 0.01, B1+0.01) ◄ B2
=IF(SUM(A1)=0, MAX(C$1:C1)+0.01, C1) ◄ C2
Fill down as necessary.

Formula to change another cell

I'm a novice in excel. I'm using Excel 2010. My spreadsheet looks something like this:
0 A B C D
1 X 10€ X: (sum of all incomes, made by A)
2 Y 20€ Y: (sum of all incomes, made by B)
3 Z 5€ Z: (sum of all incomes, made by C)
4 X 4€
5 Z 6€
I have a list of incomes and outcomes, collected/paid for by 3 different persons. I'd like to format the first column: if the content of the cell is 'X', the income in that row is added to X's sum of all incomes, if it's Y, add to Y's sum, same for Z.
Something like this (for A1):
"if content = X, add B1 to D1; if content = Y, add B1 to D2; if content = Z, add B1 to D3"
How do I write the formula?
Use the =SUMIF() formula.
Before you start, remove the colons from C1, C2 and C3.
In D1 write this formula:
=SUMIF($A$1:$A$5,C1,$B$1:$B$5)
... and copy or drag the formula down to D2 and D3.
Remember the $-signs in the formula to lock the ranges when copying or dragging.

Resources