averageif with multiple criteria
I am trying to find the average of time in position (demographics range 1)when the job class (demographics range 3) is manager or higher. I'm currently using =avg(collect to try to specify the multiple criteria but am getting a #divide by zero error message.
I have my formula written as =AVG(COLLECT({Demographics Range 1}, {Demographics Range 3}, "MG", {Demographics Range 3}, "VP"))
Can anyone tell me what I might be doing wrong?
Best Answers
-
Few things. First of all you should always name your ranges. There is no way anyone can understand what the references are just by reading the formula, and with good design they always should be able to. Second, you reference the same range twice inside of a collect without one of them being the return, this is generally a bad idea as it makes the design more complicated and especially on formula that reference other sheets can be very inefficient. Lastly the collect formula loves @cell references, if nothing seems to be working, toss a couple of those in there and see if it likes it better. Or even start by adding them, can't hurt.
=AVG(COLLECT({Demographics Range 1}, {Demographics Range 3}, or(@cell = "MG", @cell = "VP"))
The divide by zero could be caused by a few things, most commonly in my experience it is caused by uneven ranges. All ranges referenced inside of a collect formula must have the same amount of cells. Smartsheet has this fun little glitch where it likes to delete your ranges after you click away from them the first time, you should double check that they are referencing the correct cells/columns.
Sorry for the lecture, I just really like the collect formula, and have a lot sheets that function only because of it.
-
=countifs({Demographics Job Class}, or(@cell = "MG", @cell = "SM", @cell = "VP"),{Demographics Gender},@cell = "F"
Answers
-
Few things. First of all you should always name your ranges. There is no way anyone can understand what the references are just by reading the formula, and with good design they always should be able to. Second, you reference the same range twice inside of a collect without one of them being the return, this is generally a bad idea as it makes the design more complicated and especially on formula that reference other sheets can be very inefficient. Lastly the collect formula loves @cell references, if nothing seems to be working, toss a couple of those in there and see if it likes it better. Or even start by adding them, can't hurt.
=AVG(COLLECT({Demographics Range 1}, {Demographics Range 3}, or(@cell = "MG", @cell = "VP"))
The divide by zero could be caused by a few things, most commonly in my experience it is caused by uneven ranges. All ranges referenced inside of a collect formula must have the same amount of cells. Smartsheet has this fun little glitch where it likes to delete your ranges after you click away from them the first time, you should double check that they are referencing the correct cells/columns.
Sorry for the lecture, I just really like the collect formula, and have a lot sheets that function only because of it.
-
Thank you so much! That worked!
I also need to find how many Females are in the gender column, if their job class is MG, SM, or VP. I've tried a bunch of countifs variations and can't seem to find the right syntax.
Would you know the proper formula to find this as well?
-
=countifs({Demographics Job Class}, or(@cell = "MG", @cell = "SM", @cell = "VP"),{Demographics Gender},@cell = "F"
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 139 Industry Talk
- 471 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 496 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!