I have a list of 4000 different price values in one column. I want to calculate the average of the first X values in the column and display the result in cell "B21". The value of X can be changed and is located in cell "B20". How would I use excel functions to do this? Perhaps Average and Offset?
This will do it:
=AVERAGE(A1:INDEX(A:A,B20))
Note that a 0 or blank in B20 will average the whole column. You could filter that out with an IF statement:
=IF(B20=0,"NA",AVERAGE(A1:INDEX(A:A,B20)))
As Barry mentioned in his comment, I chose INDEX because it's not as volatile as OFFSET and INDIRECT.
How about:
=AVERAGE(INDIRECT("A1:A" & B20))
I'll throw my hat in the ring as well using the functions the op suggested.
=average(offset(A1,0,0,B20))
As Doug's comment this will also give an error with blanks or 0 in B20.
Gordon
Related
I'm trying to use the formula =MAX(FREQUENCY(IF(T2:AC2>1,ROW(T2:AC2)),IF(T2:AC21>=1,ROW(T2:AC2))))to find more than one maximum value before a zero from a range.
ROW has this values
1 2 0 1 2 3 4 5 6 0
I want a formula/formulas that will return 2 and 6
Thank you
You can use this formula
=LET(list,
FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(CONCAT(A1:A16),"d","l"),"l","</s><s>")&"</s></t>","//s"),
LEN(list)-LEN(SUBSTITUTE(list,"w","")))
Got this working:
=IFERROR(INDEX(R:R,AGGREGATE(15,6,ROW(R$3:R$100)/((R$3:R$1100=0)*(R$2:R99<>0)),ROWS(S$3:S3))-1),"")
Assuming the data is in column R, put the formula in column S. Link: https://www.mrexcel.com/board/threads/find-more-than-one-maximum-value-before-a-zero.1188659/post-5793250.
I am looking to sum values in a row based on a horizontal month range and vertical name range.
Here is what I am trying to achieve:
**Name** 1 2 3 4 5
Michael $24,000 $36,000 $24,567 $45,000 $36,900
Jerry $27,000 $39,090 $55,567 $85,000 $39,900
Sandra $24,000 $36,000 $24,567 $45,000 $36,900
Michelle $24,000 $36,000 $24,567 $45,000 $36,900
I want to be able to sum based on the month range.
For example, If I want to know what the value is for Sandra in months 3-5 ($24,567 + $45,000 + $36,900)
So everytime I play around with the range it should give me the sum of those values.
I tried an index match match function but I could only do it for a specific month not a range.
This was the formula I used :
=INDEX(Quota!$A$3:$P$29,MATCH('Summary by Rep'!A7,Quota!$A$3:$A$29,0),MATCH('Summary by Rep'!B4,Quota!$A$3:$P$3,0))
Any help would be greatly appreciated!
Use this array formula:
=SUM(INDEX(B2:F5,MATCH(I4,A2:A5,0),N(IF({1},ROW(INDIRECT(I2&":"&I3))))))
confirm with Ctrl-Shift-Enter instead Enter when exiting edit mode:
Or this that can be entered normally:
=SUMPRODUCT(B2:F5*(A2:A5=I4)*(B1:F1>=I2)*(B1:F1<=I3))
Just building on Scott Craner's answers with another solution that does not involve array or array like formulas.
The INDEX function actually returns a cell address instead of a value. Therefore you can use index once to define your starting cell of the range to sum, and then again to define the end cell of the range.
=SUM(INDEX():INDEX())
So based on the above formula you just need to figure out how your are going determine the start cell and then repeat the process for your end cell. I did it with the MATCH function. and used the following formula:
=SUM(INDEX($B$2:$F$5,MATCH($H4,$A$2:$A$5,0),MATCH($I4,$B$1:$F$1,0)):INDEX($B$2:$F$5,MATCH($H4,$A$2:$A$5,0),MATCH($J4,$B$1:$F$1,0)))
One small caveat that I have not tested, is that your name list and month list will may need to be sorted in ascending order.
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
How can I find the minimum value in columns B:C in the table below if the volume is <= 10.
The expected result is in yellow.
Regards,
Elio Fernandes
Either:
=AGGREGATE(15,6,C2:C9/(A2:B9<=10),1)
or, array formula**:
=MIN(IF(A2:B9<=10,C2:C9))
If there may be blank cells in B2:C9:
=AGGREGATE(15,6,1/(1/C2:C9)/(A2:B9<=10),1)
or:
=MIN(IF(A2:B9<=10,IF(ISNUMBER(C2:C9),C2:C9)))
Regards
You can use this formula to get the minimum value (Which according to me should be 20 in your data set)
=MIN(1/AGGREGATE(14,6,1/((A2:A9<=10)*B2:B9),1),1/AGGREGATE(14,6,1/((A2:A9<=10)*C2:C9),1))
for each additional column(say D) you will have to add the formula 1/AGGREGATE(14,6,1/((A2:A9<=10)*D2:D9),1) inside the MIN() formula.
Looking for a better way to do this.
EDIT:
Alternatively you could add a new row below your data. for each column you add the below formula to get the min for that column
=1/AGGREGATE(14,6,1/(($A$2:$A$9<=10)*B2:B9),1)
Now you can drag this formula to as many columns you want. Take the MIN() of this row to get the overall minimum.
I need to return a median of only a certain category on a spread sheet. Example Below
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
ect.
How can I write a formula to only return a median value of the Airline Categories. Similar to Average if, only for median. I cannot re-arrange the values. Thank you!
Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) in another cell and then pressing CTRL+SHIFT+ENTER.
Using CTRL+SHIFT+ENTER tells Excel to treat the formula as an "array formula". In this example, that means that the IF statement returns an array of 6 values (one of each of the cells in the range $A$1:$A$6) instead of a single value. The MEDIAN function then returns the median of these values. See http://www.cpearson.com/excel/arrayformulas.aspx for a similar example using AVERAGE instead of MEDIAN.
Make a third column that has values like:
=IF(A1="Airline",B1)
=IF(A2="Airline",B2)
etc
Then just perform a median on the new column.
Expanding on Brian Camire's Answer:
Using =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) with CTRL+SHIFT+ENTER will include blank cells in the calculation. Blank cells will be evaluated as 0 which results in a lower median value. The same is true if using the average funtion. If you don't want to include blank cells in the calculation, use a nested if statement like so:
=MEDIAN(IF($A$1:$A$6="Airline",IF($B$1:$B$6<>"",$B$1:$B$6)))
Don't forget to press CTRL+SHIFT+ENTER to treat the formula as an "array formula".
one solution could be to find a way of pulling the numbers from the string and placing them in a column of just numbers the using the =MEDIAN() function giving the new number column as the range