IFERROR formula contain with average and divide function - excel-formula

I am trying to turn those error value to blank but seems the formula below doesn't work.'
=IFERROR(H58-AVERAGE(H20,H24,H16,H12,H35,H47,H43,H39,H8,H31,H54),"")/IFERROR(AVERAGE(H20,H24,H16,H12,H35,H47,H43,H39,H8,H31,H54),"")
The below is the original formula that I let the formula go Value minus average then only go for divide average but some cell still did not contain any formula, then I need to add IFERROR formula to hide the error value in the cell. Anyone can advise a better formula solution on this?
=(D53-AVERAGE(D15,D19,D11,D7,D30,D42,D38,D34,D23,D46))/AVERAGE(D15,D19,D11,D7,D30,D42,D38,D34,D23,D46)

The IFERROR needs to be applied only once. Applying it separately after the divide operation could still result in a number being divided by 0, which would give an error.
=IFERROR((D53-AVERAGE(D15,D19,D11,D7,D30,D42,D38,D34,D23,D46))/AVERAGE(D15,D19,D11,D7,D30,D42,D38,D34,D23,D46), "")
In Ms365 or excel 2021, you can use LET to do the average calculation only once:
=LET(
Avg, AVERAGE(D15, D19, D11, D7, D30, D42, D38, D34, D23, D46),
IFERROR((D53-Avg)/Avg, "")
)

Related

Looking for excel function to return cell above the max value

So I am trying to find a formula that I will put in cell A6, that will search the cells A3:G3 for a max value and will return the value of the cell above the max value. In the case of the example photo i want the formula to be able to return the value of E2 sice E3 is the highest value.
See photo here!
Also, in case of same values, I would like it to return all days separated with a comma or something.
I hope my description wasn't very confusing. Thank you for your time and help.
Why don't try the simple max to achieve the result.
=MAX(A3:G3)
Okay to get the right result, you have to do the following.
=INDEX(A2:G2,MATCH(MAX(A3:G3),A3:G3,0))
Since your data is more likely in Row, so VLookup is not useful and Hlookup won't get max. Index Match formula is used to get Max.
If no extra cell for intermediate calculation, textjoin function will be needed:
=textjoin(",",TRUE,if(A3:G3=max(A3:G3),A2:G2,""))
for the worst, just change max to min
and this is array formula, ctrl+shift+enter is required

Get Count of Cells used in Excel Formula

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

How to exclude calculating cells in a formula that contain "0"?

I'm getting the average % change among an array of cells (A1-D1). Cell A11 is =COUNT(1:1)-1 (to get the number of cells that actually contain anything). The formula I'm using to get the average is =SUMPRODUCT(OFFSET(B1,,,,A11)/OFFSET(A1,,,,A11))/A11-1,0) (someone on a different forum helped me out with that one). This works fine for the most part. The problem is that some of the cells--let's say A1 and B1--contain "0". This results in a "Divide by Zero" error. Is there a way to exclude any cell that contains zero from the calculation? Thanks!
Try using this formula to ignore the cells that would give a #DIV/0! error
=SUM(IFERROR(OFFSET(B1,,,,A11)/OFFSET(A1,,,,A11),0))/SUM(--ISNUMBER(OFFSET(B1,,,,A11)/OFFSET(A1,,,,A11)))
IFERROR in the numerator sets the result of any divisions by zero to zero.
ISNUMBER in denominator gives a TRUE for all divisions which are not divisions by zero, and this is converted to a '1' by the --.
The formula has to be entered as an array formula using CtrlShiftEnter
EDIT
=SUM(IFERROR(OFFSET(B1,,,,A11)/OFFSET(A1,,,,A11),0))/COUNTIF(OFFSET(A1,,,,A11),"<>0")
gives the same result and is shorter (note that if the last number i.e. D1 is zero, you don't get a #DIV/0! error).
Like the question, this assumes there are no empty cells between numbers - otherwise you couldn't use COUNT and OFFSET to get the range.

Convert SUMIFS to SUMPRODUCT

This is my SUMIFS which SUM the number in D12:D1000 if the number in E12:E1000 is within 21 to 30.
SUMIFS(D$12:$D$1000,E$12:$E$1000,">20",E$12:$E$1000,"<31")
I tried to convert it to SUMPRODUCT:
SUMPRODUCT(D12:D1000*(E12:E1000=">20")*(E12:E1000="<31"))
But I get 0 as the result. The formula doesn't seem to work.
Your SUMPRODUCT formula should written like this,
=SUMPRODUCT (-- (A2 :A11 >=20),--(A2 :A20<=30),C2 :C20)
Please change data range as you need.

Count/Sum a column but exclude #N/A

Currently using the following forumlas to count the number of records in all of column Z that does not have #N/A but it does not work. All the rows in Column Z have a formula itself (Which is why some of them display #N/A, its a VLOOKUP).
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))
=SUMPRODUCT(--(TRIM(Z:Z)<>"#N/A"))
These return a "0" value which is not true, what am I doing incorrect?
If you are using Excel 2010 or later, to count non-error values you can use (regular formula)
=AGGREGATE(3,6,Z:Z)
No reason to use an array formula for this, you can just do something like
=COUNTIFS(Z:Z, "<>#N/A",Z:Z, "<>")
or
=COUNTA(Z:Z) - COUNTIF(Z:Z,"=#N/A")
The first one counts every nonblank, non #N/A cell. The second does what you're trying to do now and subtracts the total of #N/A cells from the total of every nonblank cell. Maybe using ISNA is technically more correct or faster, but this probably works just as well for most cases.
This array formula sums the cells of range Z:Z that are not NA's :
=SUM(IF(NOT(ISNA(Z:Z)),Z:Z)) Ctrl+Shift+Enter
This one (which is probably what you want) sums all but errors:
=SUM(IF(NOT(ISERROR(Z:Z)),Z:Z)) Ctrl+Shift+Enter
And another (simpler) one
=SUM(IFERROR(H:H, 0)) Ctrl+Shift+Enter
Are you entering it as an array formula? Press Ctrl-Shift-Enter instead of just enter. I think the first formula should work.
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))

Resources