Embedded CONCAT in AVERAGE function results in #VALUE! error

%3CLINGO-SUB%20id%3D%22lingo-sub-1428984%22%20slang%3D%22en-US%22%3EEmbedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1428984%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20dynamically%20put%20a%20variable%20range%20of%20cells%20in%20an%20AVERAGE%20function%20to%20cover%20different%20periods%20preceding%20the%20most%20recent.%26nbsp%3B%20In%20this%20approach%20I%20would%20only%20have%20to%20change%20the%20last%20row%20number%20(in%20this%20case%202820%20in%20C2839)%20instead%20of%20recalculating%20and%20changing%20each%20AVERAGE%20formula.%26nbsp%3B%20I%20have%20tried%20numerous%20approaches%20but%20can't%20seem%20to%20rid%20the%20result%20of%20quote%20characters%20which%20show%20up%20during%20an%20Evaluate%20Formula%20but%20don't%20show%20in%20the%20CONCAT%20cell%20itself.%26nbsp%3B%20It%20may%20be%20something%20simple%20I'm%20overlooking%20but%20at%20this%20point%20I%20could%20use%20some%20help.%26nbsp%3B%20GRProbA%20shows%20the%20normal%20view%3B%20GRProbB%20shows%20the%20formulas.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1428984%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-1429019%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429019%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F684324%22%20target%3D%22_blank%22%3E%40Lucky7423%3C%2FA%3E%26nbsp%3B%20%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20cannot%20just%20create%20a%20text%20string%20and%20use%20that%20like%20a%20range%20reference.%20You%20need%20to%20convert%20the%20text%20to%20a%20range%20with%20the%20Indirect%20function.%20So%2C%20if%20cell%20E2%20contains%20a%20formula%20that%20returns%20%22A1%3AA4%22%20as%20a%20text%2C%20then%20you%20can%20use%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DAVERAGE(INDIRECT(E2))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOr%20you%20can%20build%20the%20concatenation%20right%20into%20the%20Indirect%20function%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DAVERAGE(INDIRECT(C2%26amp%3BC3%26amp%3B%22%3A%22%26amp%3BC4%26amp%3BC5))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EScreenshot%20to%20illustrate%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222020-05-31_9-36-23.png%22%20style%3D%22width%3A%20720px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195539i9EA6FF7EFFD6509A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%222020-05-31_9-36-23.png%22%20alt%3D%222020-05-31_9-36-23.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429024%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429024%22%20slang%3D%22en-US%22%3E%3CP%3Eanother%20approach%20is%20to%20use%20Offset()%20instead%20of%20Indirect()%20to%20create%20a%20variable%20range.%20The%20syntax%20for%20Offset%20is%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOffset(StartRange%2Crows%2Ccolumns%2Cheight%2Cwidth)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOffset(A1%2C0%2C0%2C4)%20will%20generate%20a%20range%20that%20starts%20at%20A1%2C%20goes%200%20rows%20down%2C%200%20columns%20to%20the%20right%20(i.e.%20it%20anchors%20at%20A1)%2C%20is%204%20rows%20high%20and%2C%20since%20no%20width%20is%20specified%2C%20has%20the%20same%20width%20as%20the%20first%20parameter%20(A1%2C%20so%201%20column%20wide).%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DAVERAGE(OFFSET(A1%2C0%2C0%2C4))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EChange%20the%20first%20parameter%20to%20modify%20the%20start%20date%20and%20change%20the%20height%20parameter%20to%20return%20more%20rows.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429440%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429440%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F684324%22%20target%3D%22_blank%22%3E%40Lucky7423%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20to%20add%20to%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F7724%22%20target%3D%22_blank%22%3E%40Ingeborg%20Hawighorst%3C%2FA%3E's%20posts%2C%20it%20should%20be%20pointed%20out%20that%20volatile%20INDIRECT%20and%20OFFSET%20set-ups%20can%20almost%20always%20be%20replaced%20with%20a%20non-volatile%20INDEX%20one%20in%20such%20cases.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20the%20following%20are%20all%20equivalent%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000080%22%3E%3CSTRONG%3E%3DAVERAGE(C1%3AINDEX(C%3AC%2CA1))%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000080%22%3E%3CSTRONG%3E%3DAVERAGE(INDIRECT(%22C1%3AC%22%26amp%3BA1))%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000080%22%3E%3CSTRONG%3E%3DAVERAGE(OFFSET(C1%2C0%2C0%2CA1))%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethough%20only%20the%20first%20is%20non-volatile%20(well%2C%20not%20quite%3A%20technically%20volatile%20just%20once%2C%20i.e.%20when%20the%20workbook%20is%20first%20opened%2C%20but%20for%20all%20intents%20and%20purposes%20that's%20non-volatile).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429769%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429769%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F7724%22%20target%3D%22_blank%22%3E%40Ingeborg%20Hawighorst%3C%2FA%3E%26nbsp%3B%20THANK%20YOU!%20Problem%20solved!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429773%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429773%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676180%22%20target%3D%22_blank%22%3E%40Jos_Woolley%3C%2FA%3E%26nbsp%3B%20Thank%20you%20for%20responding.%20Seeing%20your%20three%20examples%20together%20is%20helpful.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1429777%22%20slang%3D%22en-US%22%3ERe%3A%20Embedded%20CONCAT%20in%20AVERAGE%20function%20results%20in%20%23VALUE!%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1429777%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F684324%22%20target%3D%22_blank%22%3E%40Lucky7423%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20more%20point%20-%20it%20looks%20like%20you%20calculate%20the%20same%20range%20sizes.%20They%20could%20be%20defined%20in%20any%20helper%20range%2C%20e.g.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20171px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195572iA0A64BDE3A1A7335%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAnd%20if%20in%20A1%20the%20last%20row%20to%20use%2C%20e.g.%202820%2C%20formula%20for%207%20days%20average%20could%20be%2C%20as%20suggested%20earlier%2C%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGE(INDEX(D%3AD%2C%24A%241-%24H1%2B1)%3AINDEX(D%3AD%2C%24A%241))%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20drag%20it%20down%20to%20receive%20another%204%20averages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I'm trying to dynamically put a variable range of cells in an AVERAGE function to cover different periods preceding the most recent.  In this approach I would only have to change the last row number (in this case 2820 in C2839) instead of recalculating and changing each AVERAGE formula.  I have tried numerous approaches but can't seem to rid the result of quote characters which show up during an Evaluate Formula but don't show in the CONCAT cell itself.  It may be something simple I'm overlooking but at this point I could use some help.  GRProbA shows the normal view; GRProbB shows the formulas.

6 Replies
Highlighted

Hello @Lucky7423  ,

 

You cannot just create a text string and use that like a range reference. You need to convert the text to a range with the Indirect function. So, if cell E2 contains a formula that returns "A1:A4" as a text, then you can use

 

=AVERAGE(INDIRECT(E2))

 

Or you can build the concatenation right into the Indirect function

 

=AVERAGE(INDIRECT(C2&C3&":"&C4&C5))

 

Screenshot to illustrate:

 

2020-05-31_9-36-23.png

 

Highlighted

another approach is to use Offset() instead of Indirect() to create a variable range. The syntax for Offset is

 

Offset(StartRange,rows,columns,height,width)

 

Offset(A1,0,0,4) will generate a range that starts at A1, goes 0 rows down, 0 columns to the right (i.e. it anchors at A1), is 4 rows high and, since no width is specified, has the same width as the first parameter (A1, so 1 column wide). 

 

=AVERAGE(OFFSET(A1,0,0,4))

 

Change the first parameter to modify the start date and change the height parameter to return more rows. 

 

 

Highlighted

@Lucky7423 

 

Just to add to @Ingeborg Hawighorst's posts, it should be pointed out that volatile INDIRECT and OFFSET set-ups can almost always be replaced with a non-volatile INDEX one in such cases.

 

For example, the following are all equivalent:

 

=AVERAGE(C1:INDEX(C:C,A1))

=AVERAGE(INDIRECT("C1:C"&A1))

=AVERAGE(OFFSET(C1,0,0,A1))

 

though only the first is non-volatile (well, not quite: technically volatile just once, i.e. when the workbook is first opened, but for all intents and purposes that's non-volatile).

 

Regards

Highlighted
Highlighted

@Jos_Woolley  Thank you for responding. Seeing your three examples together is helpful.

Highlighted

@Lucky7423 

One more point - it looks like you calculate the same range sizes. They could be defined in any helper range, e.g.

image.png

And if in A1 the last row to use, e.g. 2820, formula for 7 days average could be, as suggested earlier,

=AVERAGE(INDEX(D:D,$A$1-$H1+1):INDEX(D:D,$A$1))

and drag it down to receive another 4 averages.