Getting #DIV/0 error in Google Sheets for AVERAGE, SUM, COUNT, etc on column generated by ARRAYFORMULA

I am trying to get the average value of a column (column C "Profit Margin" in the screenshot) in Google Sheets. For some reason, I get a #DIV/0 error when trying to use any sort of range functions like SUM, AVERAGE, COUNT, etc on this column:

I feel like it is related to the fact that column C was generated using ARRAYFORMULA, but I'm not sure...

• UPDATE: Sorry, the sharing permissions weren't correctly set on the link I shared. The document should be publicly accessible now. Commented Oct 9, 2019 at 22:58
• Please check the answer and if it solves your question accept it so others can benefit as well. If not, let us know. Commented Oct 10, 2019 at 5:22

Most likely your formula calculated results are given in `TEXT` format, so AVERAGE -which needs numbers to make calculations- can NOT give any results and you end up with `#DIV/0!`.

A quick and easy fix:
To change text cells to number cells, select your range (`C2:C`) and choose a number format for it by going to the top menu, `Format` --> `Number`.

Your other alternative is to use the function VALUE within the Arrayformula so as to get the results formatted as numbers.

EDIT (following OP's sharing the sheet)

Your problem lies on rows 1496-1499.

In your `buys` sheet, rows 1496-1499, in column `M` (Price) the value is `0`.
This causes your formula `=ARRAYFORMULA(1- B2:B3796/A2:A3796)` for Profit margin in `Sheet1`in column `C`to give `#DIV/0!` which in turn gives `#DIV/0!` in column `E` (Average margin).

To solve this (as mentioned above):

1. Change your formula for `Average margin` to `=IFERROR(average(C2:C), "CHECK your buys")`
Extra tip: As an additional step, use conditional formatting in your `buys` sheet, to easily spot the issues.
``````=ARRAYFORMULA(1- IFERROR(B2:B3796/A2:A3796,0))