how to average first n numbers in ms excel - excel

I have two columns in an Excel spreadsheet that look like:-
Key Values
f 1
f 2
u 3
g 4
g 5
h 6
h 7
j 8
j 9
k 10
k 11
k 12
I want to create apply formula which creates an average of first n numbers in ms excel.
I Try this:-
=AVERAGE(B:B,10)
but could not get the answer.
Please help me for give me appropriate answer.

Avoid volatile set-ups with OFFSET or INDIRECT where possible:
=AVERAGE(B2:INDEX(B:B,n+1))
Or, as pointed out by #JvdV:
=AVERAGE(TAKE(B:B,n+1))
Replace n as desired.

in cell E1: enter the number of rows to take into account for average
in cell F1: enter ="B1:B"&E1
in cell E4: enter =AVERAGE(INDIRECT(F1))
Rgds
Frederik

Related

average specific values in column

I have two columns in an Excel spreadsheet that look like:
Key Values
f 1
f 2
u 3
g 4
g 5
h 6
h 7
j 8
j 9
k 10
k 11
k 12
Is it possible to create formula which creates an average that uses values that are associated with a specific key? For example if I only wanted to include values for f,u,h, and k only (where the average calculated by hand is: 6.5)?
Unfortunately, I can't use VBA in this instance.
As mentioned by Brad, just use AverageIf() worksheet function:
(In my example I started the first 'f' in cell B2)
=AVERAGEIF(B2:B13;"=f";C2:C13)
Adding all the criteria the provided links show could be quite tedious, here is a way that MAY be simpler. So just as an option:
=SUM(SUMIFS($B$1:$B$12,$A$1:$A$12,{"f","u","h","k"}))/SUM(COUNTIFS($A$1:$A$12,{"f","u","h","k"}))
No need to enter as array formula, which should be an advantage.

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

EXCEL counting empty rows

A B C D E F G H
1 Y Y Y X
2 X X
3 Y Y
4 X X
5 Y Y Y X
Count the number of empty rows (from Columns A to E) and put result here. Answer should be 2 from example above.
Hi Folks,
I'm struggling to find the correct Excel formula to count the number of rows with no data from columns A through E, and putting that answer in a cell. These 'empty rows' may have data in later columns (like F, G, H), but I just want to count the rows with no data from columns A to E.
Any help would be appreciated.
Since array formulas tend to confuse people, here's a non-Array formula approach:
Place =IF(COUNTA(A1:E1)=0,1,0) into row 1 of (for example) column I and drag down to row 5. Then place a sum formula below that to get the answer, for example: =SUM(I1:I5)
Try this array formula,
=SUM(IF(ROW(1:5), IF(A1:A5&B1:B5&C1:C5&D1:D5&E1:E5="", 1)))
Remember to finalize with ctrl+shift+enter, not just enter.
You could also use a variation on the standard formula for getting row sums of a 2d array
=SUM(N(MMULT(N(A1:E5=""),TRANSPOSE(COLUMN(A1:E5)^0))=COLUMNS(A1:E5)))
or
=SUM(N(MMULT(N(A1:E5="Y"),TRANSPOSE(COLUMN(A1:E5)^0))=0))
Again they are array formulas and have to be entered with CtrlShiftEnter

Find first n summed values in Excel with criteria

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.

How do transform a "matrix"-table to one line for each entry in excel

I have something like
1 2 3
a x o x
b x x o
c o o o
and want to transform it into lines like
1 a x
1 b x
1 c x
2 a o
2 b x
2 c o
3 a x
3 b o
3 c o
by using a formula in the excel document. Playing with $ for assigning values for each row and column does give me proper results. Each time I have to do some manual changes to the formula.
Any hint how to write it the right way?
Suppose that your matrix in the cells A1:D4
in A6 put:
=OFFSET($A$1;0;QUOTIENT(ROW()-ROW($A$6);3)+1)
in B6 put:
=OFFSET($A$1;MOD(ROW()-ROW($A$6);3)+1;0)
in C6 put:
=VLOOKUP($B6;$A$1:$D$4;MATCH($A6;$A$1:$D$1;0);FALSE)
Den drag down (copying formulas) A6:C6 up to A14:C14
(I translate my formulas from italian so there could be some glitch)
PS: 3 in the formulas refers to the number of rows (and column) of the example.
I know that it was answer years ago, BUT there is a much easier way to flatten the pivot table. This is also called the unpivot or reverse pivot.
see this:
https://www.youtube.com/watch?v=N3wWQjRWkJc
or this:
https://www.youtube.com/watch?v=pUXJLzqlEPk&list=LLzMcMocJLlJOCteGbfN3xvA&index=2

Resources