Excel: averageif function for more than one cell - excel

I have data like this:
A B C D E
1 6 7 8 9 1
2 1 2 3 4 5
3 N2 N4 N3 N5 N1
All the values are associated with numbers (N1, N2 ...). I know how to get one value by number using SUMIF:
=SUMIF($A$3:$E$3; "N1"; $A$2:$E$2) ' will get "5"
But I have another task: I need to get average of last m values before value founded with SUMIF (or AVERAGEIF).
For example for m=3, N = N1 and row = 2: we'll find number "5" and get average of last three values in row before N1: (5 + 4 + 3) / 3 = 4
How could I do it correctly?

In case you do not have Excel O365, you could use:
Formula in L2:
=SUMPRODUCT(INDEX(A1:E2,I3,ROW(INDEX(A:A,MAX(MATCH(I2,A3:E3,0)-I1+1,1)):INDEX(A:A,MATCH(I2,A3:E3,0)))))/I1
A bit lenghty, but it will also work if you use N4 or N2 while you can have "m=3".
If one has O365, you can use:
=SUM(INDEX(A1:E2,I3,SEQUENCE(I1,,MATCH(I2,A3:E3,0)-I1+1)))/I1
That's made on the assumption you will always have "m" values available.

Another option:
=SUMPRODUCT(A1:E2*(ROW(A1:E2)=H3)*(COLUMN(A1:E2)<=MATCH(H2,A3:E3,0))*(COLUMN(A1:E2)>(MATCH(H2,A3:E3,0)-H1)))/H1

I propose alternate solution (supposing that first column is A)
dataset
Function used for result
=AVERAGE(INDIRECT(CHAR(MATCH($H$2,$A$4:$E$4,0)+65-$H$3)&ROW()&":"&CHAR(MATCH($H$2,$A$4:$E$4,0)+64)&ROW()))
Check this for diff N and m
OR
If your data doesn't start with A always you have to tweak the values for CHAR() i.e. 64 and 64+1=65 only.

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))

Analysing data using the column name

I have the following data.
Z Y Z Z
A1 A2 A3 A4 Total
1 2 5 10 16
2 3 5 11 18
3 4 6 12 21
4 4 7 12 23
I want to sum the rows using Just Zs ( the name of columns). I have a big data set, so I want to write a function to find out Zs in the whole sheet and the then sum them (Total).
Any Help would be appreciated
This can be done with SUMIF():
=SUMIF($1:$1,"Z",2:2)
NOTE
With the above formula it is using full row references so DO NOT put "Z" on top of the total column or it will throw circular errors.
If you want to have "Z" above it then you need to define the ranges:
=SUMIF(A$1:D$1,"Z",A2:D2)
How does this work:
=Sum(If(A$1:D$1="Z",$A$2:$D$100))
Assuming your headers are in row 1, columns A to D, and your data starts in row 2, and goes to row 100.

Excel - Include Row in Sum Based on Comparison to Following Row

Paging All Excel Wizards,
I am trying to see if there is a way to have a one-line SUMIF or something similar to sum up the following criteria in an Excel spreadsheet:
Sum the values of Column C if
If Column A = "Chizzle"
AND If Column B is >= Column B of the next row
Sample Data:
A B C
Type Level Value
__________________
Chizzle 1 23
Chizzle 2 10
Bobbles 3 1.5
Bobbles 3 2.6
Chizzle 2 5.5 <- Should Be counted
Cobbles 2 1
Chizzle 1 3.3 <- Should Be counted
I have tried using something like this:
=SUMIFS(C1:C1000,A1:A1000,"Chizzle", B1:B1000, ">=" & B2:B1001 )
Unfortunately the B2:B1001 part isn't working and it is selecting all values.
If there is a way to do this with a one line calculation, without having to add an additional column? That would be awesome but I'm not sure if it is possible.
Thanks!
Try this SUMPRODUCT():
=SUMPRODUCT(($A$2:$A$8="Chizzle")*($B$2:$B$8>=$B$3:$B$9)*($C$2:$C$8))

Index and Match across a wide range of values

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.

Resources