I have the following excel formula:
=CORREL(INDIRECT("Raw0!"&COL_LETTER(Raw0!B$795)&MATCH("z";Raw!$B1:$B795;0)&":"&COL_LETTER(Raw0!B$795)&CELL("row";Raw0!B795));INDIRECT(COL_LETTER($B797)&MATCH("z";Raw!$B5:$B795;0)+ROW(B7)-1&":"&CELL("address";$B797)))
It looks complicated but the idea is rather simple, I want to define 2 arrays with INDIRECT functions in order to calculate cross-correlation between the arrays, i.e.:
=CORREL(array1;array2).
The above formula always gives me #N/A, i.e. excel error message "not available".
However, if I put the arguments of the two INDIRECT functions above in a couple of cells, let's say C803 and C804, and the I use the formula
=CORREL(INDIRECT(C803);INDIRECT(C804))
it works fine.
How is it possible? as cells C803 and C804 contains exactly the same writings I used in the first function above, i.e.:
C803 contains
="Raw0!"&COL_LETTER(Raw0!B$795)&MATCH("z";Raw!$B1:$B795;0)&":"&COL_LETTER(Raw0!B$795)&CELL("row";Raw0!B795)
and C804 contains
=COL_LETTER($B797)&MATCH("z";Raw!$B5:$B795;0)+ROW(B7)-1&":"&CELL("address";$B797)
Note: COL_LETTER() is a simple VBA function I created that returns the letter of the column of the cell argument. It works fine, I tested it.
Thanks for the attention.
Related
I have a column in a spreadsheet in which numbers are sometimes
stored in text format or are mixed with text values.
For converting them to numbers I would
normally use VALUE. And because of the other text values in the same column I would additionally wrap it
with IFERROR, defaulting the result to 0 to prevent any issues with the
conversion.
All this I wanted to use in SUMPRODUCT and I am reluctant to add any new intermediate columns to the sheet.
I face an issue with IFERROR returning a single value (or even a #VALUE! error) when it is used in SUMPRODUCT as one of the arrays. What's even worse, the sum is correctly assessed in the Function Arguments window.
I created an isolated case, that you can see here SUMPRODUCT using IFERROR problem. One of the numbers in column C is preceded with with single quotation "'" and the C column holds both text and number values.
A long version of the SUMPRODUCT formula
=SUMPRODUCT(IFERROR(VALUE($C1:$C4),0),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>"")) and the simplified one =SUMPRODUCT(IFERROR(VALUE(C19:C21),0)). It returns a correct number in the Function Arguments window when in the spreadsheet it shows #VALUE! error or respectively an incorrect sum.
I wonder if I am using the aforementioned functions wrong (can't IFERROR be used as an array here?), or is this some sort of an Excel bug (why the assessed value is different from the result in the spreadsheet?).
Thanks in advance for your comments and suggesting a solution.
Your formula :
=SUMPRODUCT(IFERROR(VALUE($C1:$C4),0),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>""))
and
=SUMPRODUCT(IFERROR(VALUE(C19:C21),0))
all need to be confirmed with Ctrl+Shift+Enter
Another option,
Change your formula into :
=SUMPRODUCT(N(+$C1:$C4),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>""))
and
=SUMPRODUCT(N(+C19:C21))
the change using N(+.... instead of IFERROR(VALUE(....
also, the above 2 formulas need not array entry
I have a formula that looks like this
=IFERROR(B83,"OPEN")
So if a certain cell has an error it changes it to OPEN, but if it doesn't then it returns the values within that cell.
I am trying to make the cell also short the text that is being returned to 7 characters.
I made this formula:
IFERROR(B83,"OPEN"),AND(LEFT(B83,7))
However it does not work and instead returns an "NA".
Appreciate any help.
Try
IFERROR(LEFT(B83,7),"OPEN")
You need to put your desired result as the first argument of IFERROR.
This is the formula that I am currently using:
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=A359)*1)
It works great, but I would like to use this instead:
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=INDIRECT("A"&(ROW())))*1)
Unfortunately I get a #VALUE!. What am I doing wrong? Both INDIRECT("A"&ROW(())) and A359 return the same value, so I'm not sure why this won't work.
The reason I am not using a simple COUNTIF function is because I stripped my formula of all unnecessary components and only left the part that I am having trouble with (i.e. I need to use the SUMPRODUCT formula and a COUNTIF formula will not work)
Thanks in advance!
I'm not sure why you need INDIRECT instead of ordinary cell references but the specific problem here is that ROW function returns an "array", even when it returns a single value, e.g. it returns {"x"} rather than just "x" - and in some circumstances Excel can't process that.
Try wrapping the second ROW function in a SUM function - the value doesn't change but it gets rid of the array, i.e.
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=INDIRECT("A"&SUM(ROW())))*1)
This will eliminate #VALUE! eror while leaving the essential structure of your formula unchanged
Try this one:
=SUMPRODUCT((($A$2:INDEX($A:$A,ROW()-1))=INDEX($A:$A,ROW()))*1)
it gives you the same result.
But above formula is volatile. Instead I would use next one, say in B3 :
=SUMPRODUCT((($A$2:$A2)=$A3)*1)
I am working with the following table in Excel:
The following formula in evaluates normally when entered directly into a cell:
=DATE(YEAR(DATEVALUE($A$1)),MONTH(DATEVALUE($A$1)),DAY(INDIRECT(ADDRESS(2,COLUMN()))))
However, when I try to place put this in the named function test and call =test in another cell it returns a #VALUE! error. The best answer I have come up with after researching is that named formulas and the indirect function are not always compatible.
If anyone can shed some light to help explain what I am doing wrong or why I can not put an indirect call inside of a named range I would greatly appreciate it!
Yes, I don't believe INDIRECT will work with a named range - you shouldn't really need such a convoluted formula - try just
=(C$2&$A$1)+0
format as date
Edit: as per comments below, INDIRECT is OK but I don't think COLUMN() is liked in the named range. ROW and COLUMN functions sometimes behave badly because they return "arrays" even when single values, so you need another function like MAX or SUM to convert {2} to 2, e.g.
=DATE(YEAR(DATEVALUE($A$1)),MONTH(DATEVALUE($A$1)),DAY(INDIRECT(ADDRESS(2,MAX(COLUMN())))))
although I think there are shorter methods as I indicated above....
Problem definition:
Enter any number in cell A1. Now try the following formulae anywhere on first row.
=SUM(INDIRECT("A"&ROW()))
and
=SUMPRODUCT(INDIRECT("A"&ROW()))
The first formula evaluates, the second one gives a #VALUE error.
This is caused by the ROW() function behaving differently inside SUMPRODUCT().
In the first formula, ROW() returns 1. In the second formula, row returns {1} (array of one length), even though the formula has not been entered as a CSE formula.
Why does this happen?
Background
I need to evaluate a formula of the type
=SUMPRODUCT(INDIRECT(*range formed by concatenation and using ROW()*)>1)
This is working out to an error. As a workaround to this issue, I now calculate ROW() in another cell (in the same row, obviously) and concatenate that inside my INDIRECT(). Alternately, I also have tried encapsulating it inside a sum function, like SUM(ROW()), and that works as well.
I would sure appreciate it if someone could explain (or point me to a resource that can explain) why ROW() returns an array inside SUMPRODUCT() without being CSE entered.
Interesting question. There are subtle issues here which I haven't seen documented.
It seems INDIRECT("A"&ROW()) returns an array consisting of one element which is a reference to a cell - not the value in that cell. Many functions cannot resolve this type of data correctly but a few functions such as N and T can "dereference" the array and return the underlying value.
Take this case where there are two elements in the array:
=SUM(N(INDIRECT("A"&ROW(1:2))))
This returns A1+A2 when array entered but it only returns A1 when entered normally. However changing ROW(1:2) to {1;2} in this formula returns the correct result when entered normally. The equivalent SUMPRODUCT formula returns A1+A2 whether array entered or not.
This may be related to how the arguments are registered in the function. According to http://msdn.microsoft.com/en-us/library/bb687900.aspx there are essentially two methods to register function arguments to handle Excel data types:
Type R/U: "Values, arrays, and range references."
Type P/Q: "Excel converts single-cell references to simple values and multi-cell references to arrays when preparing these arguments."
SUM arguments seem to conform with type R/U while SUMPRODUCT arguments behave like type P/Q. Array-entering the SUM formula above forces the range reference argument in ROW to be evaluated as an array whereas this happens automatically with SUMPRODUCT.
Update
After a little more investigation, here's further evidence that might support this theory. Based on the link in the comment, the formula =SUM((A1,A2)) gives the same values as:
?executeexcel4macro("CALL(""Xlcall32"",""Excel4"",""2JRJR"",4,,1,(!R1C1,!R2C1))")
Registering the last argument as type P by changing 2JRJR to 2JRJP gives an error in this case but does allow for single area ranges like !R1C1:!R2C1. On the other hand, changing the 4 (xlfsum) to 228 (xlfsumproduct) only allows single area references either way it's called just like SUMPRODUCT.
As ROW() returns an array, use INDEX to get the 1st element.
You example then becomes: =SUMPRODUCT(INDIRECT("A"&INDEX(ROW(),1)))
I don't think ROW() behaves differently here, it returns an array in both cases. I assume that SUM and SUMPRODUCT treat that array differently - not sure why.
Many functions or combinations of them return arrays - you don't need CTRL+SHIFT+ENTER to make that happen, you only need CSE in many cases to process the arrays created.
I would just use INDEX in place of INDIRECT (which also benefits you by avoiding a volatile function), i.e.
=SUMPRODUCT(INDEX(A:A,ROW()))
....expanding that to your range this formula will count the number of values > 1 in a range in column A where x defines the start row and y the end row
=COUNTIF(INDEX(A:A,x):INDEX(A:A,y),">1")
x and y can be calculated by formulas
you can use SUMPRODUCT or COUNTIFS in a similar way if there are more conditions to add