Excel 2013: #REF error with formula - excel-formula

Trying to get an average of cells that fit under certain criteria. Getting a #REF error with this formula. Was wondering if anyone could give it a look? Not sure what is wrong with it.
=(AVERAGE(INDEX('2011_2016 Well
Data'!$H$2:$H$181,MATCH(Summary!C1,'2011_2016 Well
Data'!$E$2:$E$181,0)&MATCH(Summary!$D$2,'2011_2016 Well
Data'!$F$2:$F$181,0)&MATCH(Summary!$B$4,'2011_2016 Well
Data'!$G$2:$G$181,0)&MATCH(Summary!$A$3,'2011_2016 Well
Data'!$C$2:$C$181,0))))

MATCH&MATCH&MATCH is not a thing in Excel, at least not in the way you are trying to implement it.
I think what you are looking for is the AVERAGEIFS formula, which allows you to average based on multiple criteria.
This should do the trick, with the caveat that I don't know what you data looks like and I'm making the following assumptions based on the formula you have provided.
'2011_2016 Well Data'!$H$2:$H$181 is the range with the numbers you want to average
Criteria Looked for in this range
Summary!C1 '2011_2016 Well Data'!$E$2:$E$181
Summary!$D$2 '2011_2016 Well Data'!$F$2:$F$181
Summary!$B$4 '2011_2016 Well Data'!$G$2:$G$181
Summary!$A$3 '2011_2016 Well Data'!$C$2:$C$181
Here is the formula
=AVERAGEIFS('2011_2016 Well Data'!$H$2:$H$181,'2011_2016 Well Data'!$E$2:$E$181,Summary!C1,'2011_2016 Well Data'!$F$2:$F$181,Summary!$D$2,'2011_2016 Well Data'!$G$2:$G$181,Summary!$B$4,'2011_2016 Well Data'!$C$2:$C$181,Summary!$A$3)
Or in an easier to read view
=AVERAGEIFS('2011_2016 Well Data'!$H$2:$H$181,
'2011_2016 Well Data'!$E$2:$E$181, Summary!C1,
'2011_2016 Well Data'!$F$2:$F$181, Summary!$D$2,
'2011_2016 Well Data'!$G$2:$G$181, Summary!$B$4,
'2011_2016 Well Data'!$C$2:$C$181, Summary!$A$3)

Related

Formula using sumifs and indirect function for worksheets. Getting Reference error although Had it working with different columns

Using excel 365. I have used this same formula for "asset allocations" and it worked perfectly.
I decided to do the same for sector allocation and I can not figure out what is wrong. This has beat me down. I have tried for 2 days. I thought that I could just exchange the category for sector. Didn't work. Thank you for any help.
Here is the image which shows the sheet that I am using.
The formula in G6 is:
=SUMPRODUCT(SUMIFS(INDIRECT(K$6:K$11&"[Value]"),INDIRECT(K$6:K$11&"[Sectors]"),[#Sector]))
You can see a REF Error on the column "Value".
This image is to show where the "Sectors" are listed on the individual sheets that I wish to sum.
Unusual, but this is working fine in my test scenario.
Use the Evaluate Formula tool to see where the error creeps in. You may have a typo in the list of tables.
I should have found the answer earlier but I didn't question my table columns.
In my last table the Column was accidentally called "Sector" and it should have been called "Sectors". I needed to pinpoint the point of problem by debugging better.
This code does indeed work fine for anyone wishing to sum by a category from more than one sheet. Not saying it is elegant code but it is easy to understand.

How to count cells in a table column that contains a specific text string (COUNT.IF doesn't work)

I need to count how many cells in a table column that contains a specific text string. I'm using this formula and it works well:
=COUNT.IF(TB_table_name[col_name];"*string_to_be_found*")
But I need to count only filtered cells.
I've found may solutions (using SUMPRODUCT) on internet, but only to common cells and not table conlumns.
This is the kind of table that I have:
As you can see, there are many values in the same cell (It happens because it is generated automatically by a survey made in MS Forms). Because of this, I need to search for a specific string to be counted.
Using "COUNT.IF" I have this results:
Please observe that the values in the cell are not random, but predefined - of course the sequence could not be the same, but the list of possible terms are.
Please, can you help me figure this out? Belive me, I have tried many things but nothing worked and it seems to be a thing so easy to achieve :(
The trick is to combine a couple of the ideas you found using SUMPRODUCT.
You likely found this reference (or one just like it) that gave guidance for a formula like this:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B7,ROW(B2:B7)-MIN(ROW(B2:B7)),,1))*(B2:B7="Quality"))
Which translates to your problem-space like this:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(TB_table_name[col_name],ROW(TB_table_name[col_name])-MIN(ROW(TB_table_name[col_name])),,1))*(TB_table_name[col_name]="*string_to_be_found*"))
This works perfectly fine if you're NOT using a wildcard search. But that's what you need. So in this answer it shows that the wildcard in a SUMPRODUCT needs to use the -- operator. So the result is to combine the two answers and you get:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(TB_table_name[col_name],ROW(TB_table_name[col_name])-MIN(ROW(TB_table_name[col_name])),,1))*(--(ISNUMBER(FIND("string_to_be_found",TB_table_name[col_name])))))
Notice that the string_to_be_found does NOT have wildcard * specifiers. That's taken care of by the FIND function.

Problems with SUMIFS in Excel when using external reference

After doing a lot of research and trying various potential solutions, I am still stuck and hoping someone may be able to point me on the right track.
I am using a SUMIFS function in an Excel 2010 spreadsheet, but whilst it works when the reference spreadsheet is open, it gives a #VALUE error when the reference spreadsheet is closed.
My searching so far has identified that this is a known issue with Excel, but though I have tried various workarounds that are posted on forums, I haven't been able to make any work. I don't get a #VALUE error, but instead I get a zero.
The original formula is as follows:
=SUMIFS('P:\Performance\[All calls.xlsm]Jan 2016'!$N:$N,'P:\Performance\[All calls.xlsm]Jan 2016'!$R:$R,$B2,'P:\Performance\[All calls.xlsm]Jan 2016'!$G:$G,$C2,'P:\Performance\[All calls.xlsm]Jan 2016'!$J:$J,"pri")
As I say, this works fine when the other workbook is open (it obviously drops the "P:\Performance\" pre-fix), but not when it is closed (though it does change the reference to the full path).
So as per other suggestions, I have tried using SUMPRODUCT...
=SUMPRODUCT(--('P:\Performance\[All calls.xlsm]Jan 2016'!$R:$R=$B2),--('P:\Performance\[All calls.xlsm]Jan 2016'!$G:$G=$C2),--('P:\Performance\[All calls.xlsm]Jan 2016'!$J:$J="pri"),('P:\Performance\[All calls.xlsm]Jan 2016'!$N:$N)
However, this results in zero, which is clearly incorrect as the SUMIFS version and open workbook gives me a non-zero value.
Working through the calculation steps, I suspect it may have something to do with the reference cells themselves being based on formulae, but I'm not certain. Incidentally, I get the same result whether the reference workbook is open or closed.
Any ideas?
Thanks very much.
PS: I also looked at the Microsoft support site, but although it gives the impression that there is a workaround on the site, the hyperlink leads you back to the same place...
How to correct a #VALUE! error
OK, so first of all thanks to the two people who commented. I didn't need to take a look at the suggested "similar question", because I managed to resolve it myself.
The SUMPRODUCT solution posted elsewhere did in fact work. The issue turned out to be a strange situation with one of the columns I was referencing. On closer examination, I discovered that although the column was formatted as "short date", for some reason, some of the entries were not being recognised as such. I have no idea why this was, but when I converted the column to "number", it was obvious, as some of the dates failed to turn into date numbers. Strange, as all the entries were being created by a formula. So this was why the SUMPRODUCT formula was returning a zero very time.
Anyway, I found the solution here...
Some dates recognized as dates, some dates not recognized. Why?
I have no idea why this worked, but it did. And now the SUMPRODUCT workaround works, with the target spreadsheet closed. Maybe this will help someone else, or maybe it won't, but it does pay to check and double check the format of any cells you are referencing.

Concatenate Formula (Getting a #REF Error)

Afternoon all :)
This is kind of a little difficult to explain but ill happily clarify where ever it is needed. Thank you for taking the time to read this post ^^ Here goes..
I am currently creating a spreadsheet that is been extracted from the database whereby I am tasked to concatenate data from 2 adjacent cells. I change the database on a frequent basis adding or removing data wherever necessary so the range of data is always different. To concatenate the two cells I use the following formula:
e.g: =IF(ISBLANK(B8&H8),"",B8&H8)
This formula works out great when im dealing with increasing amounts of data as I can simply drag the formula down as far as i want and i know that it will pick up the formula whenever I refresh the database without the need of seeing value errors when the formula ends up referring to a blank cell. The snag here (and my query as well) is if I have less data then before the formula within the last set of cells looks something like this:
e.g: =IF(ISBLANK(#REF!&#REF!),"",#REF!&#REF!)
I have dealt with #REF before in other spreadsheets whereby I simply used a ISERROR in the statement but I dont know if there is a possible way of including this within my formula. I need the ISBLANK there so I have more control and dont have to drag the formula as often.
If there is a better way around this or a way to amend the current formula Id appreciate the help :)
The only way you are going to get something like this:
=IF(ISBLANK(#REF!&#REF!),"",#REF!&#REF!)
in the formula bar is if you(or the system you are using) are somehow deleting the cells that were originally referenced. This should be avoidable. You can clear the cells referenced instead of deleting them completely - then you won't get this error - and your formulas will remain intact. Now you can certainly use the formulas provided in the comments to hide the errors - but the root of your problem seems to me to be that the errors are occuring in the first place. Good Luck.

Trying to improve efficiency of array formula

I have a SUM array formula that has multiple nested IF statements, making it very inefficient. My formula spans over 500 rows, but here is a simple version of it:
{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17>0,
IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
As you can see, the first half of the formula checks where the array is greater than zero, and if they are, it sums those in the second part of the formula.
You will notice that the same IF statement is repeated in there twice, which to me is inefficient, but is the only way I could get the correct answer.
The example data I have is as follows:
Sample Data in spreadsheet http://clients.estatemaster.net/SecureClientSite/Download/TempFiles/example.jpg
The answer should be 350 in this instance using the formula I mentioned above.
If I tried to put in a MAX statement within the array, therefore removing the test to find where it was greater than zero, so it was like this:
{=SUM(MAX(IF(B2:B6>B8:B12,B2:B6,B8:B12)-B14:B18,0))}
However, it seems like it only calculates the first row of data in each range, and it gave me the wrong answer of 70.
Does anyone know a away that I can reduce the size of the formula or make it more efficient by not needing to repeat an IF statement in there?
UPDATE
Jimmy
The MAX formula you suggested didnt actually work for all scenarios.
If i changed my sample data in rows 1 to 5 as below (showing that some of the numbers are greater than their respective cells in rows 7 to 11, while some of the numbers are lower)
Sample Data in spreadsheet http://clients.estatemaster.net/SecureClientSite/Download/TempFiles/example2.jpg
The correct answer im trying to achive is 310, however you suggested MAX formula gives an incorrect answer of 275.
Im guessing the formula needs to be an array function to give the correct answer.
Any other suggestions?
=MAX( MAX( sum(A1:A5), sum(A7:A11) ) - sum(A13:A17), 0)
A more calculation-efficient (and especially re-calculation efficient) way is to use helper columns instead of array formulae:
C1: =MAX(A1,A7)-A13
D1: =IF(C1>0,C1,0)
copy both these down 5 rows
E1: =SUM(D1:D5)
Excel will then only recalculate the formulae dependent on any changed value, rather than having to calculate all the virtual columns implied by the array formula every time any single number changes. And its doing less calculations even if you change all the numbers.
You may want to look into the VB Macro editor. In the Tools Menu, go to Macros and select Visual basic Editor. This gives a whole programming environment where you can write your own function.
VB is a simple programming language and google has all the guidebooks you need.
There, you can write a function like MySum() and have it do whatever math you really need it to, in a clear way written by yourself.
I pulled this off google, and it looks like a good guide to setting this all up.
http://office.microsoft.com/en-us/excel/HA011117011033.aspx
This seems to work:
{=SUM(IF(A1:A5>A7:A11,A1:A5-A13:A17,A7:A11-A13:A17))}
EDIT
- doesn't handle cases where subtraction ends up negative
This works - but is it more efficient???
{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)>A13:A17,IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
What about this?
=MAX(SUM(IF(A1:A5>A7:A11, A1:A5, A7:A11))-SUM(A13:A17), 0)
Edit:
Woops - Missed the throwing out negatives part. What about this? Not sure it it's faster...
=SUM((IF(A1:A5>A7:A11,IF(A1:A5>A13:A17,A1:A5,A13:A17),IF(A7:A11>A13:A17,A7:A11,A13:A17))-A13:A17))
Edit 2:
How does this perform for you?
=SUM((((A1:A5>A13:A17)+(A7:A11>A13:A17))>0)*(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17))

Resources