Evaluation of function AVERAGE caused a divide by zero error - arrays

In Google sheets, I just input the following values through Data Validation.
Once the range of values are input in a google sheet, it looks like the following:
From the above figure:
I want to take an average of inputted drop down values in the range between
B6 and B14.
I applied a formula =Average(B6,B14). But, it display error message.
Error!
Evaluation of function AVERAGE caused a divide by zero error.
Anyone knows how to resolve it. Thanks in Advance!

You can use the following formula:
=AVERAGE(ARRAYFORMULA(REGEXEXTRACT(B6:B14, "\d+")*1))
Explanation
The =REGEXTRACT() function will extract the first match of a regular expression for the given string. In this case, the first chain of numbers will be extracted.
Afterwards, the result of the function is multiplied by 1. This is done to transform the type of the result of =REGEXTRACT() from a string to a number, so that we may afterwards calculate the average.
=REGEXTRACT(), by default, operates on single strings - but not on multiple cells at the same time. For that reason, we have to wrap the call with =ARRAYFORMULA() which will allow to call it with a range as a parameter.
Finally, the =AVERAGE() function is called.
Handling empty cells
With the previous response, given a range in which at least a cell is empty/doesn't conform the regex specified in the =REGEXTRACT() call, an error will be returned. We have two main options to handle this situation:
Ignore the cell. The cell will be completely ignored for the average computation:
=AVERAGE(ARRAYFORMULA(IFERROR(REGEXEXTRACT(B6:B14, "\d+")*1, "")))
Treat the cell as a 0 towards the average computation.
=AVERAGE(ARRAYFORMULA(IFERROR(REGEXEXTRACT(B6:B14, "\d+")*1, 0)))
Both the solutions use the =IFERROR() function. In case the call to =REGEXTRACT() returns an error, the value will be replaced respectively for an empty string (which doesn't count in the average computation) or for a 0 instead.

use this fx:
=ARRAYFORMULA(AVERAGE(IFERROR(REGEXEXTRACT(B6:B14; "\d+")*1)))

Related

How to use Round() in an array formula?

I am trying to count the number of unique values in a range of values after the values are rounded to the hundredths place.
This is the formula I am using to count the number of unique values in the range:
=SUMPRODUCT(1/COUNTIF($EZ6:$FD6,$EZ6:$FD6&""))
and this is what I've tried to count the number of unique values in the range after rounding:
=SUMPRODUCT(1/COUNTIF(ROUND($EZ6:$FD6,2),ROUND($EZ6:$FD6,2)&""))
This formula produces an error and doesn't evaluate.
The issue isn't adding the "" at the end, since this formula also produces an error and doesn't evaluate:
=SUMPRODUCT(1/COUNTIF(ROUND($EZ6:$FD6,2),ROUND($EZ6:$FD6,2)))
By produce an error, I mean that a message box appears saying "There is a problem with this formula..."
Yes unfortunately Countif only works with ranges, not arrays - as soon as you introduce the Round function, you are implicitly using arrays.
I would suggest using the Frequencies method for getting unique values:
=SUM(--(FREQUENCY(IF(EZ6:FD6<>"",ROUND(EZ6:FD6,2)),ROUND(EZ6:FD6,2))>0))
This is based on a standard formula see documentation- the only issue is that if you apply the Round function to blank cells, you get zero, which could give you an extra unique value, hence the If statement.
Must be entered as an array formula using CtrlShiftEnter

Using Row(Indirect(string)) not working

I have been trying to use =row(indirect("0-5000")) to work like I have read on all literature I could find and yet I keep getting the #REF error, which occurs when it processes the indirect(string) part of the formula. Is there a setting somewhere that is making my function to act improperly?
I am trying to produce an array of numbers inside a formula at time of calcution (so no stored array), based on a range of two numbers from 2 cells like the example 1/4 of the way down on https://exceljet.net/formula/create-array-of-numbers
Try,
=row(indirect("1:5000"))
There is no row 0 and a colon is used to delimit the upper and lower limits of a range.

Excel > Find first first/lowest non-zero value in unsorted array

Using a complex series of array combinations using standard Excel functions in a single formula (no VBA or UDF's involved), I've got the following result appearing mid-formula. I now need to add one final step to the formula to pull just one number out of this array:
{0,0,0,4,0,6,7...}
Using Excel formulas, how can I retrieve the first non-zero figure (in this example, 4) without any additional references to the array? Due to the complexity of the calculations it took to produce this array from the source data, I'd rather not do this twice in the same formula.
So I'm looking for functions or operators which can be applied to the array in order to yield the required result - ideally something elegant and simple. MATCH and LOOKUP fail because they require the array to be sorted. MIN fails because the lowest value is 0, not 4.
NB: The value of each non-zero figure also corresponds with its position in the array (the first would be 1, second would be 2, etc), so the first non-zero number will always be the smallest.
Try this
=1/AGGREGATE(14,6,1/{0,0,0,4,0,6,7},1)
It finds the maximum of the reciprocals ignoring the error values so the answer is 0.25. Then it takes the reciprocal of that.

Non-Native function returning an array - How to display the output

I apologise if this is a very simple question, but I am at a bit of a loss here.
A bespoke formula I want to use returns an array of values, as seen here:
But I cannot find a way to present this output in a cell separated format, only the first cell (39478) is returned.
There is a note included in the documentation: Hint: This function is a multiple result function. You MUST set an array for the output.
Whilst I understand I am going to need an array to display multiple results, I cannot find the method of doing so. Any tips?
If the bespoke formula wants to return an array of values, there are a couple of ways to get the results into multiple cells.
Put the formula into a cell and hit Enter↵. Next, select that cell along with several cells below it. Tap F2 then hit Ctrl+Shift+Enter↵. The successive values should fill the cells selected until an error (no more returns) is reached.
Put that formula into a cell and hit Ctrl+Shift+Enter↵. The formula should be wrapped in braces (e.g. { and }). If the correct relative and absolute cell addresses were used (e.g. $**A$1 or $**A1, etc) then you should be able to fill, copy or drag down the formula into successive rows.
Use an INDEX function to contain the array of returned values from the bespoke formula and peel off successive values using the row_num parameter.       =INDEX(<bespoke formula>, ROW(1:1))   Filled down.
Sooner or later, you will run out of rows to fill. An IFERROR function used as a wrapper can help avoid he display of errors.
If you want to put all of the values into a single cell, then a User defined Function (aka UDF) could concatenate the array into a single string. This last method is generally not recommended as it renders the values useless for anything other than display purposes.
Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula.
Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum.
See Guidelines and examples of array formulas for more information.

Excel COUNT() vs COUNTIF() with arrays

I think this should be a straightforward question, but for some reason I can't find a solution anywhere.
I have a lengthy formula in excel that, ultimately, returns an array of four items -- i.e. {1,2,0,0}. I want to count how many of the resulting numbers are greater than zero.
When I use =COUNT({1,2,0,0}) on this result, I get the expected answer of 4. But when I try to use =COUNTIF({1,2,0,0}, ">0") it pops up with an error saying that my formula has a problem.
Is there something I'm doing wrong? Is there an array equivalent for COUNTIF() ?
It appears the COUNTIF function only works on ranges, while the COUNT function can utilize an array.
Give SUMPRODUCT a try. Below is a slightly expanded form of your example which I used to test the formula. It basically checks to see if each value in the array is greater than 0, and if it is, it assigns it a value of 1. Then SUMPRODUCT goes through and adds up all the 1s to give you the total number of values greater than 0.
=SUMPRODUCT(IF({1,0,3,0,5,0,0,6,9,9,0,7,0}>0,1,0))
Probably the most concise way to accomplish this is to just convert the TRUE or FALSE value returned from the validation check into a number with the INT function. TRUE translates to 1 and FALSE translates to 0. Then SUM those 1's and 0's.
=SUM(INT({1,2,0,0}>0))
Or as Barry Houdini points out, you can coerce the boolean to an int with:
=SUM(({1,2,0,0}>0)*1)
Or:
=SUM(({1,2,0,0}>0)+0)

Resources