# Combining IF and AVG help

Options
✭✭✭✭
edited 12/09/19

Hello,

I am trying to combine these two functions to find an average number but only if it meets a specific criteria. For example, I have cases worked that can be canceled for 3 reasons. If the case is canceled because of a "No contact" with the client, I need to know the average number of days the case was active before it was canceled.

I've tried 7 different degrees of IF/AVG formulas to no avail. It either comes back as unparseable or invalid data type.

• ✭✭✭✭✭✭
Options

Can you share all the criteria or examples of your formulas that aren't working? It is a bit hard to visualize what you are looking for exactly.

• ✭✭✭✭
Options

Definitely!

I've tried =IF({Canceled Cases - Internal Training 2019 Range 1}, "Canceled Auto Response - Duplicate", AVG({Canceled Cases - Internal Training 2019 Range 2}))

This returns an invalid data type

If I use =AVG(IF({Canceled Cases - Internal Training 2019 Range 1},"Canceled Auto Response - Duplicate",){Canceled Cases - Internal Training 2019 Range 2})

This returns and #unparseable

I've tried several variations of these and am stumped.

• ✭✭✭✭✭✭
Options

The criteria for an IF statement cannot reference a range. You need to instead use the collect formula

Current formula

=IF({Canceled Cases - Internal Training 2019 Range 1}, "Canceled Auto Response - Duplicate", AVG({Canceled Cases - Internal Training 2019 Range 2}))

=avg(collect({Canceled Cases - Internal Training 2019 Range 2},{Canceled Cases - Internal Training 2019 Range 1},@cell = "Canceled Auto Response - Duplicate"))

Untested so there may be a typo

• ✭✭✭✭✭✭
Options

As a side note, you really should name your ranges instead of letting smartsheet name them for you. This will let you know exactly what you are referencing just by looking at the formulas. Also, the collect formula can be a bit difficult to grasp the concept of. I recommend perusing the formula webpage to learn a little about what it does

https://help.smartsheet.com/function/collect