Index and Match across a wide range of values - excel

I have a bunch of data in a few columns, but basically:
Bunch #1 (column A,B):
CHR POS
1 126234
3 5555555
3 9999999
9 3700000
Bunch #2 (column E,F,G):
CHR POS INDEX
1 1129410 1
2 4500000 2
3 5555155 3
3 9997999 4
7 3700000 5
I wish to add a column in Bunch #1 such that if the CHR column of both bunches are the same, AND the POS column of #2 is within +/-500 of POS in #1, then copy over the index of Bunch #2.
Like so (Column A,B,C):
CHR POS NEW_COLUMN
1 126234 #N/A
3 5555555 3
3 9999999 #N/A
9 3700000 #N/A
I got as far as getting exact matches for both columns in C
{=INDEX(E:G,match(1,(E:E=A1)*(F:F=B1),0),3)}`
Some help in getting the range condition into the match would be very much appreciated.

The newer AGGREGATE¹ function makes quick work of multiple conditions. In C2 as,
=IFERROR(INDEX(G$1:G$9, AGGREGATE(15, 6, ROW($1:$9)/((E$1:E$9=A2)*(F$1:F$9<=B2+500)*(F$1:F$9>=B2-500)), 1)), "no match")
Fill down as necessary.
      
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Related

Presenting a value based on number or text in cell

I have a list of 4 values in Sheet1 and 4 values in Sheet2.
In Sheet3 I will combine a random selection of these numbers and return the value in a column. (edit: no random selection from Excel, its a part picked from a bucket)
(A fifth column in Sheet3 will be used to do calculations with ValueS1 and ValueS2)
Sheet1
NumberS1
ValueS1
1
17.10
2
17.20
3
17.12
4
17.15
Sheet2
NumberS2
ValueS2
1
16.10
2
16.20
3
16.12
4
16.15
Sheet3
NumberS1
NumberS2
ValueS1
ValueS2
1
3
17.10
16.12
2
2
17.20
16.20
4
1
17.15
16.10
3
4
17.12
16.15
What kind of function can give the desired return?
I have looked into examples using "Indirect" but cannot see how they will solve my problem.
for the randomization: =ROUNDUP(RAND()*4,0)
rand() gives you a number between 0 and 1, so rand()*4 gives you a number between 0 and 4.
roundup(x,y) round up the number x with y digits you want to round the number up to (in our case 0).
for import the right number from sheet 1 or 2: =VLOOKUP(A1,Sheet1!A1:B2,2,0)
A1 - The value you look for in sheet 1 or 2.
Sheet1!A1:B4 - The array he look for your value on the firs column, always on the first column.
2 - The column you want to import the value from. (because we write an array of tow columns. we can write here only 1 or 2)
0 - it's an Optionally index (0 or 1). o is if you want an exact match of the return value.
Regular Lookup could do:
=LOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5) in Sheet3!C2
And
=LOOKUP(B2:B5,Sheet2!A2:A5,Sheet2!B2:B5) in Sheet3!D2
Note that LOOKUP will give the result to the closest match smaller than the search value.
Or VLOOKUP:
=VLOOKUP(A2:A5,Sheet1!A2:B5,2,0) / =VLOOKUP(B2:B5,Sheet2!A2:B5,2,0)
VLOOKUP will error if the value is not found (the way used above). It uses arguments like this:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE)
Office 365 has XLOOKUP which combines the logic of the two above and some more:
=XLOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5,"value not found",0)
XLOOKUP uses the following arguments:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

EXCEL Sum up points based on placements (combine VLOOKUP and SUM)

e.g. I have a list of race results:
A B C D E F...
NAME P. RACE1 RACE2 RACE
abc =? 1 3 3
bcd 3 2 4
cde 4 4 2
def 2 1 1
and another sheet with points for each result:
A B
PLACE POINT
1 10
2 5
3 2
4 1
Is it possible to get the total points in sheet1 column B based on the race results in column C-E..?
Is it a connection from VLOOKUP and SUM?
Yes, that's possible. You can use a SUMPRODUCT formula for that. You may use this one in column B:
=SUMPRODUCT((C2:E2=$A$13:$A$16)*$B$13:$B$16)
Your result will look like this:
This is an array function. The term C2:E2=$A$13:$A$16 will check for race 1 to 3 if it was 1st, 2nd, 3rd or 4th place. This will result in an "imaginary" array of TRUE and FALSE. For name "abc", it will look like that.
Those results are then multiplied with the points from B13:B16 and the sum is formed.
In Excel O365, one could use:
Formula in B2:
=SUM(VLOOKUP(C2:E2,H$2:I$5,2))

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

excel formula to filter range based on criteria

I have a strange problem I've been trying to find a good solution to for the past few hours. I have a table in excel similar to the following:
|A B C D E F
-----+-----+-----+-----+-----+-----+-----
1 |2011 1 0 -5 4 2
2 |2011 2 1 1.2 2 3
3 |2011 3 1 2 4 -4
4 |2011 0 1 -3 3 -2
5 |2012 5 1 0 0 1
6 |2012 0 1 0.25 0 0
the data falls into different categories based on columns A-C, with columns D-F being dollar amounts.
What I'm trying to figure out is, is there a way to return the max absolute value of columns D-F for a subset of these rows using the values in columns A-C as filter values? Now, I know how to return the max absolute value of a range: =max(abs(START:END)), but what I don't know how to do is filter out some of the rows from the range based on their column A-C values.
Perhaps a specific example of what I'm looking for:
How would I get the range D-F where:
A=2011
B<>0
C=1
For the above set of conditions and data, the answer I'd like to have returned is 4, from E3.
I am not opposed to adding helper columns within reason, but there are many more sets of filter conditions, which was the undoing of a few other solutions I cobbled together; 16-32 helper columns would not be accepted by the group I'm trying to develop this for.
If your excel version supports the newer MAXIFS function, use that with the ABS function and MINIFS function.
=max(maxifs(d:f, a:a, 2011, b:b, "<>", c:c, 1), abs(minifs(d:f, a:a, 2011, b:b, "<>", c:c, 1)))
If not then AGGREGATE will provide the conditions.
=AGGREGATE(14, 6, ABS(D1:F6)/((A1:A6=2011)*(B1:B6<>0)*(C1:C6=1)), 1)

Find summation and count only if they are EQUAL in Excel

In EXCEL sheet I have 1728 rows and 2 columns (L and O). I am doing addition of these 2 columns in column P. Further I want to count the occurrence in this column if addition is EQUAL to 2 or 4 or 6 or 8 BUT condition here is that The COUNT should be such that BOTH the columns L and O are EQUAL and Their addition is either 2 or 4 or 6 or 8.
This means that only the columns in L and O with values "1+1" , "2+2", "3+3", "4+4" should be counted. The addition of "1+3", "4+2" should not be counted.
=COUNTIF(P:P,4)
does not work.
L O P M
===========================
1 1 2 1 (NO OF 2'S)
2 2 4 1 (NO OF 4'S)
3 3 6 1 (NO OF 6'S)
1 3 4* NO TO BE COUNTED
4 4 8 1 (NO OF 8'S)
2 4 6* NOT TO BE COUNTED
4 2 6*
AS SEEN ABOVE RESULT OF COUNTING IS STORED IN M. Let me know the formula
=IF(L29=M29,SUMPRODUCT(--($L$29:$L$35=$M$29:$M$35)*(L29=$L$29:$L$35)),"Not Counted")
My data started in row 29 so you will need to adjust the references. It counts the entire table in 1 shot. So if you added a row to the bottom that had 1 and 1 and 2, the results in column M in your first row would become 2 and the same for the row you just added.
Will this formula help...?
=IF(AND(A1=B1,OR(SUM(A1,B1)=2,SUM(A1,B1)=4,SUM(A1,B1)=6,SUM(A1,B1)=8)),SUM(A1,B1),"NOT TO BE COUNTED")
Just drag the formula till you have data. You will need to adjust the references.
Here is the reference data.

Resources