SOLVED

Problem using Row() function in Offset() function

%3CLINGO-SUB%20id%3D%22lingo-sub-1574086%22%20slang%3D%22en-US%22%3EProblem%20using%20Row()%20function%20in%20Offset()%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1574086%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20want%20to%20use%20the%20Row()%20function%20in%20conjunction%20with%20the%20Offset()%20function%20and%20then%20both%20in%20SumProduct()%20and%20I've%20found%20it%20doesn't%20work.%20For%20example%2C%20if%20I%20use%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DSUMPRODUCT(OFFSET(Filtered!%24A%242%2C28%2C8%2C1%2C1)%2C--(OFFSET(Filtered!%24A%242%2C28%2C8%2C1%2C1)%20%26lt%3B0))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20a%20valid%20result.%20However%2C%20if%20I%20substitute%20columns%3D8%20for%20Row()%2B5%20it%20I%20get%20%23VALUE!%20in%20the%20cell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DSUMPRODUCT(OFFSET(Filtered!%24A%242%2C28%2CROW()%2B5%2C1%2C1)%2C--(OFFSET(Filtered!%24A%242%2C28%2CROW()%2B5%2C1%2C1)%20%26lt%3B0))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20I%20to%20conclude%20that%20Excel%20doesn't%20let%20you%20use%20the%20Row()%20function%20in%20the%20Offset()%20function%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1574086%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1574290%22%20slang%3D%22en-US%22%3ERe%3A%20Problem%20using%20Row()%20function%20in%20Offset()%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1574290%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20appears%20ROW%20is%20returning%20a%20single%20element%20array.%20There%20is%20an%20old%20thread%20here%20that%20discusses%20it.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fanswers.microsoft.com%2Fen-us%2Fmsoffice%2Fforum%2Fall%2Frow-function-returning-array-though-it-should-not%2Ffcce040c-c297-43d9-a02e-a0038b6be5e0%3Fauth%3D1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fanswers.microsoft.com%2Fen-us%2Fmsoffice%2Fforum%2Fall%2Frow-function-returning-array-though-it-should-not%2Ffcce040c-c297-43d9-a02e-a0038b6be5e0%3Fauth%3D1%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20looks%20like%20a%20workaround%20is%20to%20wrap%20ROW%20with%20the%20SUM%20function%20to%20get%20the%20array%20to%20a%20single%20value.%3C%2FP%3E%3CP%3E%3DSUMPRODUCT(OFFSET(Filtered!%24A%242%2C28%2CSUM(ROW())%2B5%2C1%2C1)%2C--(OFFSET(Filtered!%24A%242%2C28%2CSUM(ROW())%2B5%2C1%2C1)%20%26lt%3B0))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%2C%20you%20could%20use%20ROWS%3A%3C%2FP%3E%3CP%3E%3DSUMPRODUCT(OFFSET(Filtered!%24A%242%2C28%2CROWS(%24A%241%3A%24A3)%2B5%2C1%2C1)%2C--(OFFSET(Filtered!%24A%242%2C28%2CROWS(%24A%241%3A%24A3)%2B5%2C1%2C1)%20%26lt%3B0))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi,

I want to use the Row() function in conjunction with the Offset() function and then both in SumProduct() and I've found it doesn't work. For example, if I use this:

 

=SUMPRODUCT(OFFSET(Filtered!$A$2,28,8,1,1),--(OFFSET(Filtered!$A$2,28,8,1,1) <0))

 

I get a valid result. However, if I substitute columns=8 for Row()+5 it I get #VALUE! in the cell.

 

=SUMPRODUCT(OFFSET(Filtered!$A$2,28,ROW()+5,1,1),--(OFFSET(Filtered!$A$2,28,ROW()+5,1,1) <0))

 

Am I to conclude that Excel doesn't let you use the Row() function in the Offset() function?

5 Replies
Best Response confirmed by robtcallahan (New Contributor)
Solution

It appears ROW is returning a single element array. There is an old thread here that discusses it.

https://answers.microsoft.com/en-us/msoffice/forum/all/row-function-returning-array-though-it-should...

 

It looks like a workaround is to wrap ROW with the SUM function to get the array to a single value.

=SUMPRODUCT(OFFSET(Filtered!$A$2,28,SUM(ROW())+5,1,1),--(OFFSET(Filtered!$A$2,28,SUM(ROW())+5,1,1) <0))

 

Or, you could use ROWS:

=SUMPRODUCT(OFFSET(Filtered!$A$2,28,ROWS($A$1:$A3)+5,1,1),--(OFFSET(Filtered!$A$2,28,ROWS($A$1:$A3)+5,1,1) <0))

 

 

@JMB17 ,

 

Thanks so much for your answer. It solved my problem. However, it is very non-intuitive. In fact, the definition of ROW() from Formula Builder states, "Returns the row number of a reference." It does not say array. Further, the definition of ROWS() states, "Returns the number of rows in a reference or array." 

 

So I concluded the MS goofed here. Row() should ALWAYS return an integer and Rows() should always return an array. Same for Column() and Columns(). Since this is not the case, they are inconsistent. 

 

Rob

 

@robtcallahan 

Rob, that's an opposite.

ROWS(range) calculates number of rows in the range and always returns single number.

ROW(range) returns an array with rows numbers within the range which is widely used in Excel formulas to before SEQUENCE() appeared.

And yes, ROW() or ROW(A1) returns an array from only one elements which usually is silently converted to the scalar value, but not always. ROW() is not the only such function.

 

I agree, support page doesn't explain that properly, perhaps intentionally not to complicate the things.

 

By the way, why do you need SUMPRODUCT() in your formula if OFFSET returns only one element? 

@Sergei Baklan,

 

You are right. Doh! I stand corrected. Thanks.

 

Re: SumProduct, I'll be using it with a range returned from Offset. Just didn't show it here.

 

Rob

@robtcallahan 

If you are on Excel with dynamic arrays, you may use SUM with multiplication of returned arrays, like

=SUM(OFFSET($A$2,28,ROW()+5,1,1)*(OFFSET($A$2,28,ROW()+5,1,1)<0))

it works with single element as well.