Calculate top-3 scores, with specific exclusions in Excel - excel

I need to find the average of the top 3 values within a range, so have been using the following:
=IFERROR(SUM(LARGE(A2:F2,{1,2,3}))/3,Z2)
on a similar dataset to:
A B C D E F G
2 10 3 9 4 3 3
However, I now need to exclude either certain columns throughout that range (i.e. B, D, E etc), or to exclude some specific values from that range (whichever way is more efficient).
Any help would be appreciated

Here is something you may be able to work with:
In A3:
{=AVERAGE(LARGE(A1:H1,ROW(1:3)))}
In A4: (excluding B, D and E)
{=AVERAGE(LARGE((A1;C1;F1:H1),ROW(1:3)))}
Notice it's an array formula and needs to be confirmed through CtrlShiftEnter

Related

Formula to get crossed values

I am trying to get values from other column, based on some logic, crossed logic, but I didn't get any result with the only thing I know: IF or VLOOKUP.
The table is in this way:
So basically there are groups divided by blank row, and in column D I want to add the value from column B, but according with other letter that the one from the row ( C is from Credit, D is from Debtor). So in first D5 I have C on the same row in A5, so I need to take value from D, which is 2, according to B6.
So sorry if this question is too easy or stupid, but I don't know much about excel formulas, other that the basic one.
I'd say the fastest way with formula takes two columns. The first one (let's say column C) will use this formula to define the blocks:
=IF(A5="",C4+1,IFERROR(C4+0,0))
It's meant for cell C5.
The second column will give back the actual result:
=SUMIFS(B:B,A:A,IF(A5="C","D",IF(A5="D","C","")),C:C,C5)
It's meant for cell D5.
Place them accordingly and drag them down to cover your list.
Then again: if you are looking just for the number and not for its sum (and therefore assuming all numbers are equal for each letter in each block), just use this one in cell D5 instead of the previous one:
=SUMIFS(B:B,A:A,IF(A5="C","D",IF(A5="D","C","")),C:C,C5)/COUNTIFS(A:A,IF(A5="C","D",IF(A5="D","C","")),C:C,C5)
Now if you were to use only IF and VLOOKUP functions, a possible solution could be this one:
A
B
C
D
E
F
G
Block index
0
What to search
What is
Value
Result
C
1
=IF(A5="",C4+1,C4)
=IF(A5="",C4+1,C4)&SE(A5="C","D",SE(A5="D","C",""))
=C5&A5
=B5
=IF(VLOOKUP(D5,E:F,2,FALSO)=0,"",VLOOKUP(D5,E:F,2,FALSO))
D
2
=IF(A6="",C5+1,C5)
=IF(A6="",C5+1,C5)&SE(A6="C","D",SE(A6="D","C",""))
=C6&A6
=B6
=IF(VLOOKUP(D6,E:F,2,FALSO)=0,"",VLOOKUP(D6,E:F,2,FALSO))
D
2
=IF(A7="",C6+1,C6)
=IF(A7="",C6+1,C6)&SE(A7="C","D",SE(A7="D","C",""))
=C7&A7
=B7
=IF(VLOOKUP(D7,E:F,2,FALSO)=0,"",VLOOKUP(D7,E:F,2,FALSO))
=IF(A8="",C7+1,C7)
=IF(A8="",C7+1,C7)&SE(A8="C","D",SE(A8="D","C",""))
=C8&A8
=B8
=IF(VLOOKUP(D8,E:F,2,FALSO)=0,"",VLOOKUP(D8,E:F,2,FALSO))
D
3
=IF(A9="",C8+1,C8)
=IF(A9="",C8+1,C8)&SE(A9="C","D",SE(A9="D","C",""))
=C9&A9
=B9
=IF(VLOOKUP(D9,E:F,2,FALSO)=0,"",VLOOKUP(D9,E:F,2,FALSO))
C
4
=IF(A10="",C9+1,C9)
=IF(A10="",C9+1,C9)&SE(A10="C","D",SE(A10="D","C",""))
=C10&A10
=B10
=IF(VLOOKUP(D10,E:F,2,FALSO)=0,"",VLOOKUP(D10,E:F,2,FALSO))
=IF(A11="",C10+1,C10)
=IF(A11="",C10+1,C10)&SE(A11="C","D",SE(A11="D","C",""))
=C11&A11
=B11
=IF(VLOOKUP(D11,E:F,2,FALSO)=0,"",VLOOKUP(D11,E:F,2,FALSO))
D
2
=IF(A12="",C11+1,C11)
=IF(A12="",C11+1,C11)&SE(A12="C","D",SE(A12="D","C",""))
=C12&A12
=B12
=IF(VLOOKUP(D12,E:F,2,FALSO)=0,"",VLOOKUP(D12,E:F,2,FALSO))
C
5
=IF(A13="",C12+1,C12)
=IF(A13="",C12+1,C12)&SE(A13="C","D",SE(A13="D","C",""))
=C13&A13
=B13
=IF(VLOOKUP(D13,E:F,2,FALSO)=0,"",VLOOKUP(D13,E:F,2,FALSO))
C
5
=IF(A14="",C13+1,C13)
=IF(A14="",C13+1,C13)&SE(A14="C","D",SE(A14="D","C",""))
=C14&A14
=B14
=IF(VLOOKUP(D14,E:F,2,FALSO)=0,"",VLOOKUP(D14,E:F,2,FALSO))

Sum values using lookup table, where lookup values are a list of values with comma delimiter

I am trying to sum values based that equal a lookup value. However, that value is actually a list of values delimited by a comma. Below is an example of what I mean.
Suppose I have raw data in the form of sheet1 below:
Sheet1:
A
B
1
ID
VALUE
2
A
30
3
A
50
4
A
20
5
B
10
6
B
20
7
C
70
8
C
40
9
D
30
10
E
50
11
F
20
12
F
30
13
G
10
And I have a look table that groups all IDs by their respective teams, as per sheet2 below.
Sheet2:
A
B
1
TEAM
IDS
2
Red
A, B
3
Blue
C, D
4
Green
E, F, G
And I want to create a report where the user can select the team name, and the sum of the values in sheet1 will aggregate based on the selection, as per the following example. So the user would select "Green" in cell B1 and it would return the sum of values that correspond to E, F, and G in sheet1.
Report:
A
B
1
Select Team:
Green
2
Sum:
110
I have searched all over for a solution to this and was able to find something similar. I tried to repurpose the formula for my data but couldn't get it to work because I think that solution dealt with numbers rather than text.
Excel: Perform a SUMIF where the criteria is a comma-delimited list
Any suggestions would be greatly appreciated!
Edit: Just want to add that I realize I could first parse out the IDs in sheet2, however I'm looking for a formula that can bypass that as my real dataset is quite large and parsing out the IDs under each team would explode the number of rows.
A variation of #JvdV solution on the linked question:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,FILTERXML("<t><s>"&SUBSTITUTE(VLOOKUP(Sheet2!F1,Sheet2!A:B,2,FALSE),",","</s><s>")&"</s></t>","//s")))
Note, this only works with Excel 2013 or later and only on PC. FILTERXML is not available on Mac or prior to 2013.
If Mac or prior to 2013:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,TRIM(MID(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",REPT(" ",999)),(ROW($ZY1:INDEX($ZY:$ZY,LEN(VLOOKUP(F1,Sheet2!A:B,2,FALSE))-LEN(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",""))+1))-1)*999+1,999))))

Excel mapping and create a new column

Excel file columns:
A B C
2 two 3
5 five 8
3 three 10
8 eight 11
12 one 15
I want to create a new column Din same file like below:
A B C D
2 two 3 three
5 five 8 eight
3 three 10
8 eight 11
12 one 15
I want to map C and A and if there's a match D takes values of B.
Example: Value 3 in C is present in A, so D will take corresponding B value three.
Thanks!
So building on BigBen's additional suggestion of using an IFERROR, I believe you want something akin to this in Column D:
=IFERROR(VLOOKUP(C1, A:B, 2, FALSE), "")
... and then drag down the formula throughout Column D
Now, there are some assumptions being made here:
Your data does not have any header row, ala the data starts in Row 1, not Row 2
You want empty/blank values where there is no exact match (this is BigBen's IFERROR suggestion). Your current question layout seems to suggest this. Otherwise, you'll get #N/A in all those blank cells in Column D.
EDIT: To confirm, I used your data (though I started in Row 2), and here's how it looked after -
If one has DA-functionality you could use:
1) - Excluding empty cells using FILTER:
Formula in D1:
=FILTER(B1:B5,COUNTIF(C1:C5,A1:A5)>0)
2) - Including empty cells using XLOOKUP:
Formula in D1:
=XLOOKUP(C1:C5,A1:A5,B1:B5,"")
If one does not have access to DA-functionality you could use:
1) - Excluding empty cells using INDEX, MATCH and SMALL:
=IFERROR(INDEX(B$1:B$5,SMALL(IFNA(MATCH(C$1:C$5,A$1:A$5,0),""),ROW(A1))),"")
Note 1 - This needs to be array entered through CtrlShiftEnter
Note 2 - Alternatively, one could use a non-array entered approach including AGGREGATE as per #basic: =IFERROR(INDEX(B$1:B$5,AGGREGATE(15,6,MATCH(C$1:C$5,A$1:A$5,0),ROW(A1))),"")
2) - Including empty cells using VLOOKUP:
Please refer to the other answer given by #Gravity here.
Basically the difference between both approaches could be vizualised like:

How to use SUMIFS and SUMPRODUCT function **with a multiplier column** for summing values if criteria range exists in a range?

This question refers to this Stack Overflow question.
This is the original question:
A B C
a 3 d
b 1 a
c 8 e
d 5
I want to use SUMIFS function, sum range is B1:B4, if the corresponding value in column A exists in column C, sum the values in column B, in this case the sum will be 3 + 5 = 8.
The answer turned out to be:
=SUMPRODUCT(SUMIF(A1:A4,C1:C3,B1:B4))
I would like to create the same result, but with a multiplier on one of the ranges.
Here's my question:
A B C D
a 3 d 3
b 1 a 1
c 8 e 1
d 5 d 3
The only thing I would like to do differently is add a range D1:D3 that acts as a multiplier. In this case, the sum I want would be (3x3)+(5x3)= 24.
One challenge is that the ranges are different sizes in the "Test Data" google sheet linked below. The "Test Data" sheet is an example of how I would like to total daily calories based on the number of servings of items that I eat as dictated by the "multiplier column."
I would like the numbers in C2:C27 to be a multiplier and factored into the total in D36.
For example, if I ate 2 servings of Beef, then 2 servings worth of Beef's ​calories would be displayed in the daily totals below the data. Currently, using the formula =SUMPRODUCT(SUMIF(Meal_Items!$A$2:$A$100,$D$2:$D$28,Meal_Items!$B$2:$B$100)), only 1 serving of beef is weighted.
Test Data
See linked Test Data set above
The original question could also be solved with this formula
=SUMPRODUCT((COUNTIF(C1:C3,A1:A4)>0)+0,B1:B4)
using that version it's a simple matter to add one or more multiplier columns
=SUMPRODUCT((COUNTIF(C1:C3,A1:A4)>0)+0,B1:B4,D1:D4)
Given discussion in comments this formula should do what you want in either Excel or google sheets
=SUMPRODUCT(IFERROR(LOOKUP($D$2:$D$28,Meal_Items!$A$2:$A$100‌​,Meal_Items!$B$2:$B$‌​100),0),$C$2:$C$28)
If you have actually put A, B, C, etc into the header row (row 1) then this will not work until you either rename your header column labels appropriately or use data range references in place of the full column references I've provided.
=B2*INDEX(B:B, MATCH(A2, A:A, 0))+B2*INDEX(B:B, MATCH(C2, A:A, 0))
In E1 enter:
=IF(COUNTIF(C$1:C$4,A1)>0,1,0)
and copy down. Then in another cell:
=SUMPRODUCT((E1:E4)*(D1:D4)*(B1:B4))
Data is in column BWeights are in column DCriteria are in column E

Getting the last non-empty cell across non-contiguous columns

How can I elegantly get the value of the last non-empty cell (i.e. having the highest column value) across a set of columns?
For example, if my set of non-contiguous columns is A, C, F, and my row has the following values:
A B C D E F G
9 8 7 6 5 4
then the result would be 7 since C is the highest of A, C, F which isn't empty.
I can do this with a bunch of nested emptiness tests for a single cell at a time, but am looking for an elegant solution that can scale well as the number of such columns rises.
Add a helper row and mark the columns to be watched with the value 1 in that row. With the helper row in row 1 and the data in columns A to M, this is the formula used in the screenshot
=LOOKUP(2,1/(($A$1:$M$1=1)*(A2:M2<>"")),A2:M2)
You can hide row 1. To adjust the columns to be "watched", just enter/remove a 1 into the helper row.
if you get the MOREFUNC addon you can do:
=MMAX(ARRAY.JOIN(A1,C1,F1),1)
MOREFUNC ADDON
Morefunc Addon is a free library of 66 new worksheet functions.
HERE is some information (by original author)
here is the last working download link I found
here is a good installation walk-through video

Resources