SOLVED

Automate chart data selection

%3CLINGO-SUB%20id%3D%22lingo-sub-1512558%22%20slang%3D%22en-US%22%3EAutomate%20chart%20data%20selection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1512558%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20use%20a%20formula%20to%20automate%20Select%20data...%2C%20so%20that%20it%20detects%20the%20first%20and%20last%20non-zero%20value%20in%20a%20series%20range%2C%20then%20plots%20one%20additional%20category%20(with%20series%20value%20%3D%200)%20before%20and%20after%20them%2C%20as%20shown%20below%20and%20in%20the%20attached%20file.%26nbsp%3B%20I%20considered%20INDEX%2FMATCH%20with%20OFFSET%2C%20but%20that%20led%20to%20a%20dead%20end.%26nbsp%3B%20Any%20suggestions%3F%26nbsp%3B%20Thanks.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22scheij_0-1594317556059.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204448i016AAF5F9A369E01%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22scheij_0-1594317556059.png%22%20alt%3D%22scheij_0-1594317556059.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1512558%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECharting%3C%2FLINGO-LABEL%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-1512769%22%20slang%3D%22en-US%22%3ERe%3A%20Automate%20chart%20data%20selection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1512769%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F705036%22%20target%3D%22_blank%22%3E%40scheij%3C%2FA%3E%26nbsp%3B%20I%20can't%20change%20the%20automatic%20function%20of%20the%20select%20data%20function%20but%20here%20is%20a%20pair%20of%20formulas%20you%20can%20paste%20in%20a%20new%20pair%20of%20columns%20that%20will%20'pull'%20that%20range%20of%20data%20for%20you.%26nbsp%3B%20I%20used%20a%20Defined%20Name%20%22dRange%22%20to%20define%20where%20your%20data%20(y-data)%20is%20located.%26nbsp%3B%20You%20can%20either%20create%20that%20NAME%20in%20the%20Name%20Manager%20or%20replace%20each%20occurrence%20with%20the%20range%20you%20need%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIFERROR(IF(ROW()%3D1%2C%22New%20X%22%2CINDEX(OFFSET(dRange%2CMATCH(TRUE%2CdRange%26gt%3B0%2C0)-2%2C-1%2CMATCH(TRUE%2CdRange%26gt%3B0)-MATCH(TRUE%2CdRange%26gt%3B0%2C0)%2B3)%2CCOUNT(OFFSET(%24A%241%2C0%2CCOLUMN()-1%2CROW()-1))%2B1))%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIFERROR(IF(ROW()%3D1%2C%22New%20Y%22%2CINDEX(OFFSET(dRange%2CMATCH(TRUE%2CdRange%26gt%3B0%2C0)-2%2C0%2CMATCH(TRUE%2CdRange%26gt%3B0)-MATCH(TRUE%2CdRange%26gt%3B0%2C0)%2B3)%2CCOUNT(OFFSET(%24A%241%2C0%2CCOLUMN()-1%2CROW()-1))%2B1))%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EIf%20placed%20starting%20in%20Row%201%20it%20will%20add%20the%20%22New%20X%22%20and%20%22New%20Y%22%20titles.%3C%2FP%3E%3CP%3ENOTE%3A%20these%20are%20both%20ARRAY%20formulas%20and%20you%20must%20hit%20CTRL-SHIFT-ENTER%20after%20you%20paste%20the%20text%20in%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1514384%22%20slang%3D%22en-US%22%3ERe%3A%20Automate%20chart%20data%20selection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1514384%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3B%20This%20remarkable%20solution%20achieves%20much%20of%20what%20I%20need%2C%20but%20the%20array%20formulas%20seem%20to%20%22run%20out%20of%20steam%22%20and%20fail%20to%20detect%20non-zero%20values%20in%20subsequent%20rows%20(highlighted%20in%20attached%20workbook).%26nbsp%3B%20Changing%20B20%20to%20a%20number%20%26gt%3B%200%20extends%20the%20array%20formula%20results%20to%20the%20%3CU%3Enext%3C%2FU%3E%20zero%20value%2C%20but%20not%20to%20the%20%3CU%3Elast%3C%2FU%3E%20zero%20as%20it%20should.%26nbsp%3B%20Thank%20you%20for%20your%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1513068%22%20slang%3D%22en-US%22%3ERe%3A%20Automate%20chart%20data%20selection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1513068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F705036%22%20target%3D%22_blank%22%3E%40scheij%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20add%20two%20named%20ranges%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3EXrange%3A%0A%3DINDEX(Sheet1!%24A%3A%24A%2CAGGREGATE(15%2C6%2C1%2F(Sheet1!%24B%242%3A%24B%2432%26lt%3B%26gt%3B0)*ROW(Sheet1!%24B%242%3A%24B%2432)%2C1)-1)%3AINDEX(Sheet1!%24A%3A%24A%2CAGGREGATE(14%2C6%2C1%2F(Sheet1!%24B%242%3A%24B%2432%26lt%3B%26gt%3B0)*ROW(Sheet1!%24B%242%3A%24B%2432)%2C1)%2B1)%0A%0AYrange%0A%3DINDEX(Sheet1!%24B%3A%24B%2CAGGREGATE(15%2C6%2C1%2F(Sheet1!%24B%242%3A%24B%2432%26lt%3B%26gt%3B0)*ROW(Sheet1!%24B%242%3A%24B%2432)%2C1)-1)%3AINDEX(Sheet1!%24B%3A%24B%2CAGGREGATE(14%2C6%2C1%2F(Sheet1!%24B%242%3A%24B%2432%26lt%3B%26gt%3B0)*ROW(Sheet1!%24B%242%3A%24B%2432)%2C1)%2B1)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20add%20use%20them%20for%20chart%20data%3C%2FP%3E%0A%3CP%3EXrange%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%20657px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204488i65DC7E7AA1A0FF87%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%3EYrange%20(Series)%3A%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%20658px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204489iBF8CE0C862FDFF2D%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%3C%2FLINGO-BODY%3E
Occasional Contributor

I would like to use a formula to automate Select data..., so that it detects the first and last non-zero value in a series range, then plots one additional category (with series value = 0) before and after them, as shown below and in the attached file.  I considered INDEX/MATCH with OFFSET, but that led to a dead end.  Any suggestions?  Thanks.

scheij_0-1594317556059.png

 

15 Replies

@scheij  I can't change the automatic function of the select data function but here is a pair of formulas you can paste in a new pair of columns that will 'pull' that range of data for you.  I used a Defined Name "dRange" to define where your data (y-data) is located.  You can either create that NAME in the Name Manager or replace each occurrence with the range you need:

=IFERROR(IF(ROW()=1,"New X",INDEX(OFFSET(dRange,MATCH(TRUE,dRange>0,0)-2,-1,MATCH(TRUE,dRange>0)-MATCH(TRUE,dRange>0,0)+3),COUNT(OFFSET($A$1,0,COLUMN()-1,ROW()-1))+1)),"")
=IFERROR(IF(ROW()=1,"New Y",INDEX(OFFSET(dRange,MATCH(TRUE,dRange>0,0)-2,0,MATCH(TRUE,dRange>0)-MATCH(TRUE,dRange>0,0)+3),COUNT(OFFSET($A$1,0,COLUMN()-1,ROW()-1))+1)),"")

If placed starting in Row 1 it will add the "New X" and "New Y" titles.

NOTE: these are both ARRAY formulas and you must hit CTRL-SHIFT-ENTER after you paste the text in

 

 

 

Best Response confirmed by scheij (Occasional Contributor)
Solution

@scheij 

You may add two named ranges

Xrange:
=INDEX(Sheet1!$A:$A,AGGREGATE(15,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)-1):INDEX(Sheet1!$A:$A,AGGREGATE(14,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)+1)

Yrange
=INDEX(Sheet1!$B:$B,AGGREGATE(15,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)-1):INDEX(Sheet1!$B:$B,AGGREGATE(14,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)+1)

and add use them for chart data

Xrange

image.png

Yrange (Series):

image.png

@mtarler  This remarkable solution achieves much of what I need, but the array formulas seem to "run out of steam" and fail to detect non-zero values in subsequent rows (highlighted in attached workbook).  Changing B20 to a number > 0 extends the array formula results to the next zero value, but not to the last zero as it should.  Thank you for your help.

@scheij  apparently I put too much faith in how MATCH() was working.  i tweaked that in the attached.  I also tweaked the dRange name to be more flexible of different lengths of data.

@Sergei Baklan 

The two named ranges you recommended work great, except in cases with only zero values, when Excel returns this warning.  For example, see X4range and Y4range in Chart 4.

scheij_0-1596659638813.png

I unsuccessfully tried adding an IF function to create an X category labeled "No Data" and a Y value that's far beyond the expected range.

X4range:
=IF(F5>0,INDEX(Sheet1!$A:$A,AGGREGATE(15,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)-1):INDEX(Sheet1!$A:$A,AGGREGATE(14,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)+1),"NO DATA")

 

Y4range
=IF(F4>0,INDEX(Sheet1!$B:$B,AGGREGATE(15,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)-1):INDEX(Sheet1!$B:$B,AGGREGATE(14,6,1/(Sheet1!$B$2:$B$32<>0)*ROW(Sheet1!$B$2:$B$32),1)+1),99988)

Any suggestions to accommodate non-zero values and avoid the warnings would be appreciated.  The workbook is attached.  Thanks.

@scheij 

We may wrap formulas with IFERROR as

=IFERROR(INDEX(LF!$K:$K,AGGREGATE(15,6,1/(Freq4<>0)*ROW(Freq4),1)-1):INDEX(LF!$K:$K,AGGREGATE(14,6,1/(Freq4<>0)*ROW(Freq4),1)+1),"No Data")

and

=IFERROR(INDEX(LF!$F:$F,AGGREGATE(15,6,1/(Freq4<>0)*ROW(Freq4),1)-1):INDEX(LF!$F:$F,AGGREGATE(14,6,1/(Freq4<>0)*ROW(Freq4),1)+1),99988)

Result is

image.png

Yes, that's a better fix. Thank you.

@scheij , you are welcome

@Sergei Baklan 

I made the recommended changes, but the caution message (pasted above) still appears when the formula finds only zero values, as in Chart 4, Xrange4, and Yrange4.   Also, the category axis label does not show "No Data" as expected in the IFERROR function in named formula, Xrange4.  I noticed S133:S134 are entered as array formulas, but I was not able to do that in the Name Manager with shift-ctrl-enter.  Copying any other value from row 4 to F4 produces the expected results with no warning.  Any suggestions would again be appreciated.

@scheij 

1) I don't see such error on my version of Excel, however formulas for X4 and Y4 return extra zero, my mistake. Corrected,  -1 and +1 after the AGGREGATE changed on -0 and +0. Or they are could be removed at all.

2) S133 and S134 shall return arrays, these formulas are for dynamic ranges. I assumed you are on Excel with dynamic arrays since in comments XLOOKUP and UNIQUE are mentioned. If open in Excel without dynamic arrays these formulas will be shown as array ones. That's okay, but don't Ctrl+Shift+Enter them in named formulas, that doesn't work. In Name Manager keep them as regular formulas.

 

Please check attached file. Right now I have no access to pre-DA Excel and can't test on it, hope will work. On DA Excel it works.

@Sergei Baklan 

I do not yet have Excel-DA because UNIQUE and XLOOKUP are not available functions.  I read about those new features and noted that they would soon be released, beginning in July 2020.  Hope it arrives soon!

 

When I tried to download and open your latest version, these messages initially appeared, but I used File, Open from my Downloads folder to open the workbook.  

scheij_0-1597242263700.png

The warning messages still show when Xrange4 and Yrange4 return only zeros.

 

Chart4 appears as... ,but the X category label should be "No Data."

scheij_0-1597249510771.png

 

We want to keep the extra zeros before the first and after the last categories, so I changed Xrange4 and Yrange4 to original formulas.

@scheij 

To my knowledge deployment of dynamic arrays for Office 365 subscribers is finished, they shall be available for all channels and all platforms.

I opened the file you attached, no errors and chart is correct

image.png

What do you see in R132:T133? In my case that is

image.png

I see the same in R132:T133, and the formulas are arrays enclosed with { }. The cautions still appear, and Chart4 now has no X category label. The 5 value from the last image is gone. I'll check with our company about Office 365 updates that they might have scheduled for us. I sincerely appreciate your help. Thank you.

@scheij 

I see, thank you. Will try to play with that bit more, will update you if find something.

Our agency plans to distribute the new release later this month after testing and approval. I'll let you know if the caution continues with Excel-DA. Thanks again for your help.