AVERAGEIFS does not work, but AVERAGE(IF( does

RSR_john picture RSR_john · Feb 18, 2015 · Viewed 8.1k times · Source

We have a large spreadsheet that we use to calculate performance for race car drivers. It has been stable for quite some time. Today, I opened it and found that one of the tables was not calculating correctly. I tried recalculating the sheet (it is set to manual calc), and tried rebuilding the tree (ctl+alt+shift+f9) to no avail. Other formulas referencing the same named range function correctly as do other formulas using average if.

Variables

list_of_names = A list of first and last names in a single text string imported from a CSV file

local_name = A name (100% guaranteed to be included in list_of_names) to calculate an average of a drivers performance in a given sector of the track

sector_percent = A percentage of a driver's trips through a particular sector that fall into a pre-determined range

sector_count = The number of trips the driver makes though a sector

My original formula returns a #Value error. This is the original formula (the actual formula contains an IFERROR statement, but I have removed it here for clarity. The #VALUE error happens either way).

{=AVERAGEIFS(sector_percent,list_of_names,local_name,sector_percent,">0",sector_count,">"&min_number_sectors)}

After some experimenting, I have found that the following formula successfully reports the correct answer:

{=AVERAGE(IF(list_of_names=local_name,IF(sector_percent>0,IF(sector_count>min_number_sectors,sector_percent,0))))}

If you strip the list_of_names and local_name variables from the AVERAGEIFS formula, it behaves correctly (given the data that meets the criteria). This led me to believe that the list of names and the local name were not of a matching data type. However the #VALUE error still occurs if both are set to general or text. TYPE(list_of_names) or TYPE(local_name) both return 2 presently. {TYPE(list_of_names)} returns 64 as it should.

The sheet is able to perform the list_of_names to local_name function correctly in other places in the workbook and in other areas of the same sheet.

I have tried:

-Replacing all named ranges with the actual cells referred to by the name in the formula

-Referring to different local_names in the list_of_names

-INDEX(list_of_names,ROW(A1)) correctly reports the list of names when you drag it out.

-Various orders of criteria, using other criteria.

-A number of other heat of the moment changes that I can't currently recall

Essentially, the list_of_names to local_name comparison fails in this area of the sheet every time using AVERAGEIFS where AVERAGE(IF( does not.

To me the formula is correct either way, but the sudden failure in this one part of the sheet is odd.

This is my first post here and I would appreciate any help that is available. Hopefully, I have provided enough information to lead to an answer. If not, let me know and I will fill in any gaps.

Answer

RSR_john picture RSR_john · Feb 18, 2015

Both @barryhoudini and @Jeeped are correct. I had failed to drag the information in one of the source tables far enough creating a size mismatch in the range sizes. I can't figure out how to accept that as an answer other than to answer it myself, which would not apply the proper credit where it is certainly due. I thank you both for the assistance, it was concise and excellent. I still cannot understand why one formula works and one does not. Is it possible that the AVERAGE(If has a less restrictive set of constraints when it comes to range size?