I am using Excel 2003 and am trying to average every two rows of data in one column,
starting from A1 and ending in A4, for example,
1
2
1
2
I try to do this average on the B1 column/row as follows (based on this info)
=AVERAGE(IF(MOD(ROW(A1:A4),2)=0,A1:A4))
However, when doing the above, B1 returns a 0, even though I intended to get a 1.
What would be the best way to make this kind of averaging work?
=AVERAGE(IF(MOD(ROW(A1:A4),2)=0,A1:A4))
The above formula is an array formula. To finalize it you need to press ctrl+shift+enter simultaneously; not just enter. This has also been abbreviated as CSE.
When you do this correctly, excel will wrap the formula in braces (e.g. { and }) like this:
{=AVERAGE(IF(MOD(ROW(A1:A4),2)=0,A1:A4))}
You do not type these braces in yourself; they are added automatically when a formula is entered as an array formula.
The solution to the question was as follows:
{=AVERAGE(IF(MOD(ROW(A1:A4)-1,2)=0,A1:A4))}
where the {} appears after pressing ctrl+shift+enter due to it being an array formula (cannot type that in manually).
The -1 is the offset based on where the data starts, and depending on the modulus operation, since MOD(ROW(A1),2) was 1,
i.e.: if my data instead started on A27, and I instead wanted to average values in every 4 rows, then MOD(ROW(A27),4) would return a 3 and the formula would correspondingly be offset by -3.
You could avoid array formulas using the below:
=IF((INT(ROW()/2)=ROW()/2)=TRUE,AVERAGE((A1,OFFSET(A1,-1,0))),"")
Image:
Related
I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)
I have searched the Net and tried multiple solution which never worked. You are my last hope.
I have a table like that:
NAMES.......... VALUES
A...........................4
A...........................1
B...........................4
B...........................3
B...........................2
B...........................1
C...........................4
C...........................3
As you can see, the first column has names only where the second one values.
Both Names and Values often repeat them self.
The idea is to TAG the names (first column) with the MIN value taken from the second column.
So the correct result should be:
NAMES.......... VALUES
A...........................1
B...........................1
C...........................3
I am trying to do that through Excel using the INDEX+Match formula where I am trying to add a MIN formula without success:
=MIN(INDEX($D$25:$D$36,MATCH(C25,$C$25:$C$36,0),1))
I have put the MIN everywhere but none seems to work. Which is the correct syntax and if this is not the right solution, which formula might do the job?
Thank you for your time and help
With data in column A and B, in C1 through C3 enter:ABC then in D1 enter the array formula:
=MIN(IF(A$1:A$100=C1,B$1:B$100,""))
and copy down:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
If the data never changes, a Pivot Table is easier to implement.
Two non-array alternatives.
With the newer MINIFS function.
=minifs(d:d, c:c, c25)
Using INDEX in its array format but entered as a standard formula,
=min(index((d$25:d$36)+(c$25:c$36<>c25)*1e99, , ))
I am trying to get the max value of a column based on the Left function
What I am doing is the following :
These are the results I get when i write this into column C :
=MAX(LEFT(A:A, 2))
But what I truly want is to get in column C the max value of all column A not for each cell.
So the result should be in this case 90 for all rows.
What should be the formula here?
Just another option that gets entered normally:
=AGGREGATE(14,6,--LEFT($A$1:INDEX(A:A,MATCH("ZZZ",A:A)),2),1)
Array formulas will calculate the enitre referenced array. So care should be taken to limit the number of iterations to only the data set.
The $A$1:INDEX(A:A,MATCH("ZZZ",A:A)) part of the formula does that. It finds the last cell in column A with data in it and sets that as the upper bound. So in this instance the reference range is A1:A3. But, it will grow dynamically as data in Column A is added, so no need to change the formula each time data is added.
Update 2
Here is another solution which I think is better than my original (below)
=INT(SUMPRODUCT(MAX(SUBSTITUTE(A:A,"-",".")*1)))
it can be entered as normal (just Enter)
Orignal Answer
You need numbers and arrays
=MAX(IFERROR(LEFT(A:A,2)*1,0))
Let's break this down. Multiplying by turns your strings into numbers - since Left only returns a string
LEFT(A:A,2)*1
Unfortunately this method returns #Value if you multiply an empty string by 1. You will definitely have some empty strings in the range A:A so we wrap the whole thing with an IFERROR function.
IFERROR(LEFT(A:A,2)*1,0)
Now we still need excel to treat this as an array (i.e. a whole column of numbers, rather than just one number). So we put the MAX formula in and enter it with Ctrl+Shift+Enter rather than just Enter. The result is that the formula looks like this in the formula bar
{=MAX(IFERROR(LEFT(A:A,2)*1,0))}
which would return 90 in your example, as required
Update 1
If you are using Excel 2013 or later, you can also use the NUMBERVALUE function
=MAX(NUMBERVALUE(LEFT(A:A,2)))
again, enter it with Ctrl+Shift+Enter
I want a formula that will look in a 2D array of cells for the row that has the most blank cells in it. Then I want the number of that row's blank cells returned as shown in the picture. The "Title 2" row has the most blanks at 4 as displayed in B8. I would want the formula to take the whole table into considerations, so cells B2:G5
Or this array formula**:
=MAX(MMULT(0+(LEN(B2:G5)=0),TRANSPOSE(COLUMN(B2:G5)^0)))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
Sometimes it's easier to break things up into two tasks:
A formula in Column H that counts blanks by row. Something like: =COUNTIF(B2:G2, "="&"") which you would drag down through row #5.
Then, just make Cell B8 the maximum of that new column: =MAX(H2:H5).
I'd be curious if there is some type of array formula trick to accomplish this is one formula. Nevertheless, personally, I find separating the logic into smaller, more manageable, formulas easier to maintain.
In H2 enter:
=COUNTBLANK(B2:G2)
and copy down. In B8 enter:
=MAX(H2:H5)
For example:
Several great answers already, but I'll throw this out there:
=MAX(COUNTBLANK(INDIRECT("B"&ROW(2:5)&":"&"G"&ROW(2:5))))
Enter as an array formula: Ctrl+Shift+Enter
This:
"B"&ROW(2:5)&":"&"G"&ROW(2:5)
… returns an array of strings {"B2:G2" , "B3:G3" , "B4:G4" , "B5:G5"}:
That array is fed to the INDIRECT function, which changes it into an array of ranges {B2:G2 , B3:G3 , B4:G4 , B5:G5}.
That new array is fed to the COUNTBLANK function, which (using your example) returns the array of numbers {2 , 4 , 1 , 3}.
That's fed to the MAX function, so the end result is the number 4.
It's a bit convoluted, so I'm wondering if my INDIRECT parameter can be simplified.
I want to do something similar to summing 1/x from 1 to 100 without creating an extra column to help with the calculation. I want my first column to be the numbers 1 through 100. And I want a cell to show the sum of 1/x where x is each cell in the first column. Currently the only way I can think to do this is to create a second column to do 1/x for each individual cell then sum the second column. Is there any solution to doing this without having to create the second column?
Thanks!
You can use this "array formula"
=SUM(1/A1:A100)
confirmed with CTRL+SHIFT+ENTER
....or avoid array entry by using SUMPRODUCT
=SUMPRODUCT(1/A1:A100)
both versions assume you don't have zeroes (or blanks) in A1:A100
if you might have zeroes or blanks then use this array formula
=SUM(IF(A1:A100,1/A1:A100))
if you mean 1 + 1/2 + 1/3 + ... + 1/100, use following array formula (entered by Ctrl+Shift+Enter instead of just Enter):
=sum(1/row(A1:A100))
You need to use an array formula as below:
{=SUM(1/A1:A100)}
where A1:A100 contains 1 to 100
You create the array formula bu typing the formula as =SUM(1/A1:A100) and then pressing Control-Shift-Enter.
If you do it correctly the formula then shows up with the curly brackets {} but you don't enter the curly brackets yourself.