SOLVED

Formula keeps incrementing when inserting rows

%3CLINGO-SUB%20id%3D%22lingo-sub-2378163%22%20slang%3D%22en-US%22%3EFormula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2378163%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20keeping%20a%207%20day%20rolling%20average%20of%20daily%20carbohydrate%20intakes.%26nbsp%3B%20The%20formula%20for%20the%20column%20is%20defined%20in%20row%202%20and%20automatically%20replicated%20incrementally%20for%20each%20row.%26nbsp%3B%20To%20keep%20the%20most%20current%20day's%20rows%20at%20the%20top%2C%20I%20insert%20each%20new%20row%20from%20row%203%2C%20leaving%20row%202%20empty%20except%20for%20the%20formulas.%26nbsp%3B%20The%20formula%20in%20row%202%20is%20supposed%20to%20remain%20at%20%3DAVERAGE(D2%3AD16)%20and%20the%20second%20value%20should%20remain%20the%20same%2C%20so%20that%20rows%203%20to%20n%20increase%20incrementally%20by%20row.%26nbsp%3B%20Even%20though%20I%20do%20not%20modify%20row%202%2C%20as%20I%20add%20rows%20in%20position%203%2C%20the%202nd%20value%20in%20row%202%20will%20increment%20from%2016%20to%2017%20to%2018%2C%20ect.%20as%20each%20new%20row%20is%20added%20below%20it.%26nbsp%3B%20I%20don't%20know%20how%20to%20force%20Excel%20to%20keep%20the%20value%20in%20row%202%20constantly%20at%20D16.%20Everyday%2C%20I%20need%20to%20reset%20the%20value%20in%20the%20formula%20in%20row2%20back%20to%20D16%20and%20then%20update%20the%20whole%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20attached%20image%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2378163%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2378174%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2378174%22%20slang%3D%22en-US%22%3EOops%2C%20I%20meant%20to%20say%207%20day%20running%20average%20of%20the%20Glucose%20readings.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2378577%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2378577%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3BTry%20it%20this%20way%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGE(%24D%242%3AOFFSET(%24D%242%2C14%2C0))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ED2%20is%20the%20%22fixed%22%20starting%20point%20and%20the%20end%20of%20the%20range%20is%20determined%20by%20offsetting%2014%20rows%20down%20from%20D2.%20%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2378583%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2378583%22%20slang%3D%22en-US%22%3E%3COL%3E%3CLI%3EThe%20data%20start%20in%20row%203%2C%20correct%3F%26nbsp%3B%20Row%202%20is%20empty%20except%20for%20the%20formula.%3C%2FLI%3E%3CLI%3EAlso%2C%20if%20you%20want%20a%207-day%20average%2C%20the%20formula%20should%20reference%20only%207%20days%20of%20data%2C%20not%20go%20all%20the%20way%20to%20D16%2C%20which%20would%20give%20you%20a%2014%20(or%2015)%20day%20average.%3C%2FLI%3E%3C%2FOL%3E%3CP%3EIn%20any%20case%2C%20to%20get%207%20days%20of%20data%20starting%20with%20D3%20and%20not%20have%20to%20adjust%20the%20formula%20when%20you%20push%20data%20in%20D3%20down%20each%20day%2C%20use%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGE(OFFSET(D2%2C1%2C0%2C7%2C1))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2379156%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2379156%22%20slang%3D%22en-US%22%3EThanks%20for%20the%20suggestion%20to%20use%20the%20offset%20function%2C%20which%20I%20was%20not%20familiar%20with.%20Actually%2C%20using%20the%20dollar%20signs%20did%20not%20work.%20Each%20row%20got%20the%20same%20value%20as%20the%20current%20row%20value.%20So%2C%20I%20tried%20removing%20the%20dollar%20signs%2C%20and%20now%20each%20row%20gets%20its%20unique%20value.%20To%20test%2C%20I%20inserted%20two%20rows%20for%20today's%20readings%2C%20and%20found%20that%20the%20formula%20remains%20consistent.%20Thanks.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2379159%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2379159%22%20slang%3D%22en-US%22%3EThanks%20for%20responding%20and%20suggesting%20to%20use%20the%20Offset%20function.%20That%20is%20what%20I%20needed%20to%20know.%3CBR%20%2F%3E1)%20Yes.%20I%20leave%20it%20blank%2C%20primarily%20because%20it%20seems%20that%20if%20I%20insert%20on%20row%202%2C%20next%20to%20the%20header%20row%2C%20the%20formatting%20of%20the%20inserted%20rows%20gets%20messed%20up.%20I%20don't%20know%20why.%3CBR%20%2F%3E2)%20If%20you%20look%20at%20my%20attachment%2C%20you%20will%20see%20that%20my%20wife%20normally%20does%20two%20readings%20a%20day%2C%20so%2014%20rows%20approximates%207%20days.%20If%20she%20were%20to%20occasionally%20skip%20a%20reading%2C%20or%20do%20an%20extra%20reading%2C%20then%2014%20rows%20would%20not%20truly%20reflect%20exactly%207%20days%2C%20but%20for%20the%20purpose%2C%20such%20accuracy%20is%20not%20needed.%20I%20also%20have%20a%20corresponding%20line%20graph%20which%20shows%20each%20reading%20and%20the%20%227%22%20day%20averages.%3CBR%20%2F%3E3)%20Before%20getting%20to%20your%20response%2C%20I%20had%20tried%20Riny's%3A%20%3DAVERAGE(D2%3AOFFSET(D2%2C14%2C0))%20without%20the%20%24s%20and%20it%20seems%20to%20work%20OK.%20Not%20being%20sure%20what%20the%20additional%20parameters%20are%2C%20which%20are%20reflected%20in%20your%20formula%2C%20I'll%20will%20look%20up%20the%20Offset%20function%20to%20find%20out.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2379269%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2379269%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20variant%20that%20could%20be%20for%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%20426px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F282986iE8D9968E4F58FEA5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ewith%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGEIFS(%0A%20%20%24D%243%3A%24D%241001%2C%20%24D%243%3A%24D%241001%2C%20%22%26lt%3B%26gt%3B%22%2C%0A%20%20%24A%243%3A%24A%241001%2C%20%22%26lt%3B%3D%22%20%26amp%3B%20%24A%243%2C%0A%20%20%24A%243%3A%24A%241001%2C%20%22%26gt%3B%3D%22%20%26amp%3B%20%24A%243-7%0A)%0Aand%20similar%20within%20column%20for%20running%20average%0A%0Aor%0A%3DAVERAGEIF(%0A%20%24D%243%3AINDEX(%24D%243%3A%24D%241000%2CMATCH(%24A%243-8%2C%24A%243%3A%24A%241000%2C0)-1)%2C%22%26lt%3B%26gt%3B0%22%2C%0A%20%24D%243%3AINDEX(%24D%243%3A%24D%241000%2CMATCH(%24A%243-8%2C%24A%243%3A%24A%241000%2C0)-1))%0A%0Aor%0A%3DAVERAGE(%0A%20%20%20FILTER(D%3AD%2C(A%3AA%26lt%3B%3D%24A%243)*(A%3AA%26gt%3B%3D(%24A%243-7))*(D%3AD%26lt%3B%26gt%3B%22%22))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381554%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381554%22%20slang%3D%22en-US%22%3E%3DAVERAGE(D2%3AOFFSET(D2%2C14%2C0))%20that%20I%20got%20in%20my%20first%20response%20(but%20with%20%24s%20removed)%20seems%20to%20work%20OK.%20Is%20there%20some%20advantage%20to%20these%20more%20complicated%20formulas%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381928%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381928%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20we%20have%20Date%20column%20it'll%20be%20more%20correct%20to%20calculate%20average%20for%207%20days%20based%20on%20it%2C%20not%20taking%20exactly%2014%20records.%20With%20running%20average%20down%20to%20column%20J%20that's%20could%20be%20up%20to%20couple%20of%20records%20difference.%20Plus%20OFFSET%20is%20volatile%20function.%3C%2FP%3E%0A%3CP%3EPerhaps%20both%20are%20not%20critical%20for%20this%20model%2C%20however%20why%20not%20to%20indicate%20different%20possibilities.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382027%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382027%22%20slang%3D%22en-US%22%3E%3DAVERAGE(FILTER(D%3AD%2C(A%3AA%26lt%3B%3D%24A%243)*(A%3AA%26gt%3B%3D(%24A%243-7))*(D%3AD%26lt%3B%26gt%3B%22%22))%3CBR%20%2F%3EThis%203rd%20option%20seems%20simpler%20to%20deal%20with%2C%20but%20I%20don't%20understand%20all%20the%20details.%20Do%20you%20have%20time%20to%20explain%20the%20use%20of%20each%20element%3F%20for%20Example%2C%20I%20don't%20know%20what%20D%3AD%20or%20A%3AA%20does%3F%20What%20does%20the%20%22-7%22%20do%3F%20And%20what%20does%20the%20multiplication%20do%3F%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382035%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382035%22%20slang%3D%22en-US%22%3ESorry.%20Ignore%20my%20question%20about%20the%20-7.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382816%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382816%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20FILTER()%20is%20available%20only%20o%20Excel%20365.%20I%20guess%20it%20works%20for%20you%2C%20but%20if%20you%20share%20workbook%20with%20someone%20else%20the%20person%20also%20shall%20have%20365.%3C%2FP%3E%0A%3CP%3EWith%20D%3AD%20and%20A%3AA%20we%20select%20entire%20columns%20D%20and%20A.%20Alternatively%20you%20may%20use%20something%20like%20D2%3AD1000%20and%20A2%3AA1000%2C%20the%20only%20it's%20important%20that%20the%20ranges%20have%20the%20same%20size.%20Even%20better%20to%20use%20dynamic%20ranges%20but%20that's%20another%20step%2C%20not%20critical%20with%20this%20model.%3C%2FP%3E%0A%3CP%3EFILTER(range%2C%20condition1*condition2*condition3)%20returns%20the%20range%20filtered%20by%20conditions.%20Multiplication%20here%20is%20equivalent%20of%20AND()%20operation.%20FILTER%20doesn't%20work%20with%20AND()%20and%20OR()%2C%20if%20you%20need%20the%20latest%20use%20sum%20of%20conditions%20with%20%2B.%3C%2FP%3E%0A%3CP%3EFirst%20condition%20returns%20the%20records%20for%20which%20date%20is%20less%20than%20A3%2C%20second%20one%20records%20with%20dates%20greater%20than%207%20days%20behind%20A3.%20Third%20condition%20filters%20empty%20cells.%20Finally%20we%20average%20returned%20from%20column%20D%20filtered%20range.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2384259%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2384259%22%20slang%3D%22en-US%22%3EI%20made%20response%2C%20but%20when%20I%20attempted%20to%20post%20it%2C%20it%20somehow%2C%20it%20got%20lost%2C%20so%20I'll%20do%20it%20again.%20When%20I%20copy%20and%20pasted%20your%20filtered%20average%20formula%20into%20row%20J2%2C%20Excel%20complained%20about%20the%20syntax%20and%20added%20a%20missing%20closing%20%22)%22%20on%20the%20end%2C%20an%20easy%20thing%20to%20miss.%20When%20I%20ran%20it%20as%20written%2C%20all%20rows%20received%20the%20same%20value%20as%20cell%20J2.%20As%20with%20the%20OFFSET%20AVERAGE%20formula%2C%20I%20tried%20removing%20the%20%22%24%22s%20in%20your%20formula%2C%20and%20found%20that%20it%20now%20works%20correctly--all%20rows%20have%20their%20unique%20values%20again.%20Perhaps%20you%20can%20explain%20why%20you%20thought%20you%20needed%20to%20use%20the%20%24s%20and%20why%20they%20did%20not%20work.%3CBR%20%2F%3E%3CBR%20%2F%3EYour%203rd%20filter%20condition%20also%20fixed%20another%20problem%20I%20had%20not%20reported.%20When%20a%20glucose%20cell%20is%20missing%20a%20value%20(missed%20doing%20a%20glucose%20reading%20before%20the%20meal)%2C%20the%20calculations%20ceased%20from%20that%20point%20on.%20No%20new%20rows%20would%20get%20calculated%2C%20forcing%20me%20to%20enter%20a%20estimated%20%22dummy%22%20value%20to%20keep%20the%20calculations%20working.%20Now%2C%20with%20the%20filter%20condition%2C%20a%20glucose%20reading%20can%20be%20missing%20and%20the%20calculations%20continue%20past%20the%20affected%20row.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20tested%20inserting%20two%20rows%20above%20row%203%20for%20today%2C%20and%20found%20that%20the%20function%20continued%20to%20work%20properly.%20It%20started%20it%20calculations%20with%20row%205%2C%20which%20had%20been%20row%203%2C%20the%20last%20row%20with%20no%20empty%20values.%20It%20ignored%20all%20rows%20with%20no%20glucose%20values.%20Thanks%20for%20your%20help.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2384538%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2384538%22%20slang%3D%22en-US%22%3EUsing%20the%20filter%20function%20causes%20Excel%20to%20slow%20down%20when%20adding%20new%20rows%20or%20when%20changing%20values%20in%20the%20glucose%20column.%20It%20takes%20nearly%203%20seconds%20to%20update.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2384612%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2384612%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActually%2C%20the%20filter%20function%20does%20not%20seem%20to%20be%20working%20as%20expected.%26nbsp%3B%20Look%20at%20the%20actual%20Excel%20document%20for%20sheet%20Q1.%26nbsp%3B%20After%20getting%20strange%20results%20with%20the%20inserted%20rows%20and%20the%20dummy%20row%202%2C%20I%20removed%20the%20dummy%20row%202%20and%20the%20two%20inserted%20rows.%26nbsp%3B%20Now%2C%20J2%20for%20each%20row%20for%20the%20same%20day%20gets%20the%20same%20value.%26nbsp%3B%20I%20would%20expect%20that%20each%20row%20in%20the%20same%20day%20would%20get%20its%20own%20unique%20value%2C%20but%20that%20is%20not%20the%20case%2C%20now.%26nbsp%3B%20You%20can%20play%20with%20it%20and%20see%20what%20is%20happening.%26nbsp%3B%20Insert%20a%20row%20and%20see%20what%20happens.%26nbsp%3B%20Then%20give%20it%20a%20date%20and%20see%20the%20result%20in%20the%20inserted%20row.%20Then%20add%20a%20glucose%20i.e.%20150%2C%20and%20see%20what%20happens.%26nbsp%3B%20I%20may%20need%20to%20return%20to%20the%20Average-Offset%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActually%2C%20when%20inserting%20a%20new%20row%2C%20or%20changing%20a%20date%20or%20the%20glucose%20values%2C%20it%20take%20over%203%20seconds%20for%20Excel%20to%20update%20when%20using%20the%20filter%20function.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385103%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385103%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20you%20use%20structured%20table%20let%20change%20formula%20on%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIFERROR(AVERAGE(%0A%20%20FILTER(%5BGlucose%5D%2C%0A%20%20%20%20%20(%5BDate%5D%26lt%3B%3D%5B%40Date%5D)*%0A%20%20%20%20%20(%5BDate%5D%26gt%3B%3D(%5B%40Date%5D-7))*%0A%20%20%20%20%20(%5BGlucose%5D%26lt%3B%26gt%3B%22%22))%0A)%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIt%20closes%20the%20performance%20issue%2C%20please%20check%20attached.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESame%20average%20for%20same%20date%20-%20yes%2C%20that's%20in%20accordance%20to%20initial%20logic.%20We%20keep%20average%20for%207%20days%2C%20let%20assume%20we%20use%20zero%20instead%20of%207.%20Then%20it'll%20be%20average%20for%20the%20same%20day%2C%20it%20doesn't%20matter%20how%20many%20records%20we%20have%20for%20this%20day%2C%20average%20will%20be%20the%20same%20for%20each%20of%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20could%20be%20another%20logic%2C%20e.g.%20from%20Time%20Slot%20value%20at%20this%20day%20till%20same%20Time%20Slot%20value%207%20days%20ago.%20But%20you%20have%20long%20list%20of%20Time%20Slot%20values%2C%20it's%20not%20clear%20which%20logic%20to%20use%20if%207%20days%20ago%20there%20was%20no%20same%20Time%20Slot.%3C%2FP%3E%0A%3CP%3EOr%20you%20may%20use%20average%20for%20latest%2014%20records%20as%20it%20was%20initially%20suggested%2C%20doesn't%20matter%20how%20many%20days%20it'll%20be.%20Even%20in%20this%20case%20I'd%20don't%20use%20OFFSET%2C%20better%20something%20like%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGE(%5B%40Glucose%5D%3AINDEX(%5BGlucose%5D%2C%20ROW()-ROW(tblQ1%5B%5B%23Headers%5D%2C%5BGlucose%5D%5D)%2B14))%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAbove%20is%20not%20working%20formula%2C%20only%20an%20idea%20if%20go%20in%20this%20direction%20-%20adjustment%20is%20required%20for%20the%20last%2014%20records%20in%20the%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2389616%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2389616%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help.%26nbsp%3B%20You%20may%20recall%2C%20that%20originally%2C%20I%20kept%20row%202%20as%20a%20dummy%20row%20and%20inserted%20new%20rows%20from%20row%203.%26nbsp%3B%20Then%2C%20as%20we%20worked%20through%20the%20formulas%2C%20I%20ended%20up%20getting%20rid%20of%20the%20dummy%20row%202.%26nbsp%3B%20I%20forgot%20that%20one%20reason%20I%20had%20the%20dummy%20row%2C%20was%20because%20it%20caused%20a%20problem%20with%20the%20Carbs%2FDay%20calculation%20when%20I%20inserted%20new%20rows%20from%20row%202.%26nbsp%3B%20Attached%20is%20the%20file%20you%20sent%20me%20modified%20with%20the%20two%20rows%20inserted%20from%20row%202.%26nbsp%3B%20It%20includes%20the%20date%20and%20both%20sample%20glucose%20readings%20and%20sample%20carbs%20values.%20You%20will%20notice%20that%20all%20the%20previous%20days%2C%20when%20the%20second%20entry%20for%20the%20day%20is%20entered%2C%20both%20the%20morning%20entry%20and%20the%20evening%20entry%20show%20the%20total%20carbs%20for%20the%20day%2C%20similar%20to%20how%20your%20formula%20shows%20the%20same%20value%20for%20the%20average%20glucose%20values%20for%20the%20day.%26nbsp%3B%20Well%2C%20as%20you%20can%20see%2C%20when%20I%20insert%20new%20rows%20from%20row%202%2C%20the%20carbs%20per%20day%20no%20longer%20show%20the%20total%20carbs%2Fday%20in%20both%20rows.%26nbsp%3B%20The%20first%20row%20shows%20its%20carbs%20and%20the%20second%20entry%20shows%20the%20sum%20of%20the%20values%20from%20both%20entries%20for%20day.%26nbsp%3B%20The%20only%20way%20I%20can%20fix%20the%20issue%20is%20to%20insert%20below%20the%20last%20good%20row%20and%20copy%20the%20data%20from%20the%20last%20good%20row%20then%20delete%20the%20last%20good%20row.%26nbsp%3B%20Then%20insert%20from%20that%20new%20row%203%20to%20make%20a%20new%20dummy%20row%202%20and%20then%20insert%20new%20rows%20from%20the%20new%20row%203.%20Then%2C%20the%20formula%20will%20again%20do%20the%20total%20carbs%2Fday%20in%20both%20the%20morning%20and%20evening%20rows.%26nbsp%3B%20As%20you%20can%20see%2C%20I%20have%20a%20graph%20that%20shows%20carbs%20for%20each%20row%20and%20the%20total%20carbs%2Fday.%26nbsp%3B%20The%20chart%20looks%20much%20better%20when%20both%20rows%20for%20the%20day%20show%20the%20same%20value.%26nbsp%3B%20Do%20you%20understand%20why%20the%20formula%20does%20not%20work%20the%20same%20when%20new%20rows%20are%20inserted%20from%20row%20two%20than%20when%20they%20are%20inserted%20from%20row%203%3F%26nbsp%3B%20See%20attached.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2397471%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2397471%22%20slang%3D%22en-US%22%3E%3CP%3EI%20suspect%20we've%20discussed%20this%20as%20much%20as%20any%20of%20us%20want.%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%26nbsp%3B%20So%2C%20this%20will%20be%20my%20last%20post%20in%20this%20discussion.%26nbsp%3B%20I%20also%20assume%20the%20version%20of%20Excel%20in%20use%20supports%20the%20necessary%20formulas%20and%20features.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20idea%20behind%20the%20below%20is%20that%20I've%20never%20been%20a%20fan%20of%20asking%20someone%20to%20%22make%20space%20at%20the%20top%22%20to%20enter%20data%2C%20though%2C%20sad%20to%20say%2C%20I've%20done%20it.%26nbsp%3B%20But%20with%20the%20newer%20capabilities%20of%20Excel%2C%20we%20can%20avoid%20that%20kind%20of%20UI%2FUX.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20the%20dates%20in%20column%20A%20and%20the%20readings%20in%20column%20%3CLI-EMOJI%20id%3D%22lia_anguished-face%22%20title%3D%22%3Aanguished_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20a%207%20day%20average%20for%20the%20most%20recent%207%20days%2C%20use%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGEIFS(D%3AD%2CA%3AA%2C%22%26gt%3B%3D%22%26amp%3BMAX(A%3AA)-7)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ETo%20get%20a%20list%20of%20the%20latest%207%20days%20and%20the%20average%20reading%20per%20day%2C%20I'd%20use%20the%20dynamic%20array%20formulas%3A%3C%2FP%3E%3CP%3EIn%20N4%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DMAX(A%3AA)-SEQUENCE(7%2C%2C0)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EIn%20O4%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DAVERAGEIFS(D%3AD%2CA%3AA%2CN4%23)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2398151%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20keeps%20incrementing%20when%20inserting%20rows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2398151%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F321448%22%20target%3D%22_blank%22%3E%40wcstarks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENot%20sure%20I%20understood.%20If%20we%20speak%20about%20Carbs%20%2F%20Day%20formula%20it%20could%20be%20like%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIF(%0A%20%20(%5B%40%5BTime%20Slot%5D%5D%3D%22%22)*%0A%20%20(ROW()-ROW(tblQ1%5B%5B%23Headers%5D%2C%20%5BTime%20Slot%5D%5D))%3D2%2C%20%5B%40Carbs%5D%2C%0A%20%20SUMPRODUCT(%5BCarbs%5D*(INT(%5BDate%5D)%3D%5B%40Date%5D))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Esee%20Carbbs2%20column%20in%20attached.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20Glucose%207%20day%20avr%20shall%20we%20exclude%20these%20dummy%20rows%20from%20average%3F%26nbsp%3B%20But%20that%20affects%20only%20these%20dummy%20rows.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I am keeping a 7 day rolling average of daily carbohydrate intakes.  The formula for the column is defined in row 2 and automatically replicated incrementally for each row.  To keep the most current day's rows at the top, I insert each new row from row 3, leaving row 2 empty except for the formulas.  The formula in row 2 is supposed to remain at =AVERAGE(D2:D16) and the second value should remain the same, so that rows 3 to n increase incrementally by row.  Even though I do not modify row 2, as I add rows in position 3, the 2nd value in row 2 will increment from 16 to 17 to 18, ect. as each new row is added below it.  I don't know how to force Excel to keep the value in row 2 constantly at D16. Everyday, I need to reset the value in the formula in row2 back to D16 and then update the whole column.

 

See attached image

 

 

18 Replies
Oops, I meant to say 7 day running average of the Glucose readings.

@wcstarks Try it this way:

=AVERAGE($D$2:OFFSET($D$2,14,0))

D2 is the "fixed" starting point and the end of the range is determined by offsetting 14 rows down from D2.  

  1. The data start in row 3, correct?  Row 2 is empty except for the formula.
  2. Also, if you want a 7-day average, the formula should reference only 7 days of data, not go all the way to D16, which would give you a 14 (or 15) day average.

In any case, to get 7 days of data starting with D3 and not have to adjust the formula when you push data in D3 down each day, use

=AVERAGE(OFFSET(D2,1,0,7,1))

 

 

 

 

@wcstarks 

Thanks for the suggestion to use the offset function, which I was not familiar with. Actually, using the dollar signs did not work. Each row got the same value as the current row value. So, I tried removing the dollar signs, and now each row gets its unique value. To test, I inserted two rows for today's readings, and found that the formula remains consistent. Thanks.
Thanks for responding and suggesting to use the Offset function. That is what I needed to know.
1) Yes. I leave it blank, primarily because it seems that if I insert on row 2, next to the header row, the formatting of the inserted rows gets messed up. I don't know why.
2) If you look at my attachment, you will see that my wife normally does two readings a day, so 14 rows approximates 7 days. If she were to occasionally skip a reading, or do an extra reading, then 14 rows would not truly reflect exactly 7 days, but for the purpose, such accuracy is not needed. I also have a corresponding line graph which shows each reading and the "7" day averages.
3) Before getting to your response, I had tried Riny's: =AVERAGE(D2:OFFSET(D2,14,0)) without the $s and it seems to work OK. Not being sure what the additional parameters are, which are reflected in your formula, I'll will look up the Offset function to find out.

@wcstarks 

As variant that could be for

image.png

with

=AVERAGEIFS(
  $D$3:$D$1001, $D$3:$D$1001, "<>",
  $A$3:$A$1001, "<=" & $A$3,
  $A$3:$A$1001, ">=" & $A$3-7
)
and similar within column for running average

or
=AVERAGEIF(
 $D$3:INDEX($D$3:$D$1000,MATCH($A$3-8,$A$3:$A$1000,0)-1),"<>0",
 $D$3:INDEX($D$3:$D$1000,MATCH($A$3-8,$A$3:$A$1000,0)-1))

or
=AVERAGE(
   FILTER(D:D,(A:A<=$A$3)*(A:A>=($A$3-7))*(D:D<>""))
)
=AVERAGE(D2:OFFSET(D2,14,0)) that I got in my first response (but with $s removed) seems to work OK. Is there some advantage to these more complicated formulas?

@wcstarks 

Since we have Date column it'll be more correct to calculate average for 7 days based on it, not taking exactly 14 records. With running average down to column J that's could be up to couple of records difference. Plus OFFSET is volatile function.

Perhaps both are not critical for this model, however why not to indicate different possibilities.

=AVERAGE(FILTER(D:D,(A:A<=$A$3)*(A:A>=($A$3-7))*(D:D<>""))
This 3rd option seems simpler to deal with, but I don't understand all the details. Do you have time to explain the use of each element? for Example, I don't know what D:D or A:A does? What does the "-7" do? And what does the multiplication do?
Sorry. Ignore my question about the -7.
best response confirmed by wcstarks (Contributor)
Solution

@wcstarks 

First, FILTER() is available only o Excel 365. I guess it works for you, but if you share workbook with someone else the person also shall have 365.

With D:D and A:A we select entire columns D and A. Alternatively you may use something like D2:D1000 and A2:A1000, the only it's important that the ranges have the same size. Even better to use dynamic ranges but that's another step, not critical with this model.

FILTER(range, condition1*condition2*condition3) returns the range filtered by conditions. Multiplication here is equivalent of AND() operation. FILTER doesn't work with AND() and OR(), if you need the latest use sum of conditions with +.

First condition returns the records for which date is less than A3, second one records with dates greater than 7 days behind A3. Third condition filters empty cells. Finally we average returned from column D filtered range.

I made response, but when I attempted to post it, it somehow, it got lost, so I'll do it again. When I copy and pasted your filtered average formula into row J2, Excel complained about the syntax and added a missing closing ")" on the end, an easy thing to miss. When I ran it as written, all rows received the same value as cell J2. As with the OFFSET AVERAGE formula, I tried removing the "$"s in your formula, and found that it now works correctly--all rows have their unique values again. Perhaps you can explain why you thought you needed to use the $s and why they did not work.

Your 3rd filter condition also fixed another problem I had not reported. When a glucose cell is missing a value (missed doing a glucose reading before the meal), the calculations ceased from that point on. No new rows would get calculated, forcing me to enter a estimated "dummy" value to keep the calculations working. Now, with the filter condition, a glucose reading can be missing and the calculations continue past the affected row.

I tested inserting two rows above row 3 for today, and found that the function continued to work properly. It started it calculations with row 5, which had been row 3, the last row with no empty values. It ignored all rows with no glucose values. Thanks for your help.
Using the filter function causes Excel to slow down when adding new rows or when changing values in the glucose column. It takes nearly 3 seconds to update.

@Sergei Baklan 

Actually, the filter function does not seem to be working as expected.  Look at the actual Excel document for sheet Q1.  After getting strange results with the inserted rows and the dummy row 2, I removed the dummy row 2 and the two inserted rows.  Now, J2 for each row for the same day gets the same value.  I would expect that each row in the same day would get its own unique value, but that is not the case, now.  You can play with it and see what is happening.  Insert a row and see what happens.  Then give it a date and see the result in the inserted row. Then add a glucose i.e. 150, and see what happens.  I may need to return to the Average-Offset function.

 

Actually, when inserting a new row, or changing a date or the glucose values, it take over 3 seconds for Excel to update when using the filter function.

@wcstarks 

Since you use structured table let change formula on

=IFERROR(AVERAGE(
  FILTER([Glucose],
     ([Date]<=[@Date])*
     ([Date]>=([@Date]-7))*
     ([Glucose]<>""))
),"")

It closes the performance issue, please check attached.

 

Same average for same date - yes, that's in accordance to initial logic. We keep average for 7 days, let assume we use zero instead of 7. Then it'll be average for the same day, it doesn't matter how many records we have for this day, average will be the same for each of them.

 

That could be another logic, e.g. from Time Slot value at this day till same Time Slot value 7 days ago. But you have long list of Time Slot values, it's not clear which logic to use if 7 days ago there was no same Time Slot.

Or you may use average for latest 14 records as it was initially suggested, doesn't matter how many days it'll be. Even in this case I'd don't use OFFSET, better something like

=AVERAGE([@Glucose]:INDEX([Glucose], ROW()-ROW(tblQ1[[#Headers],[Glucose]])+14))

Above is not working formula, only an idea if go in this direction - adjustment is required for the last 14 records in the table.

@Sergei Baklan 

Thanks for your help.  You may recall, that originally, I kept row 2 as a dummy row and inserted new rows from row 3.  Then, as we worked through the formulas, I ended up getting rid of the dummy row 2.  I forgot that one reason I had the dummy row, was because it caused a problem with the Carbs/Day calculation when I inserted new rows from row 2.  Attached is the file you sent me modified with the two rows inserted from row 2.  It includes the date and both sample glucose readings and sample carbs values. You will notice that all the previous days, when the second entry for the day is entered, both the morning entry and the evening entry show the total carbs for the day, similar to how your formula shows the same value for the average glucose values for the day.  Well, as you can see, when I insert new rows from row 2, the carbs per day no longer show the total carbs/day in both rows.  The first row shows its carbs and the second entry shows the sum of the values from both entries for day.  The only way I can fix the issue is to insert below the last good row and copy the data from the last good row then delete the last good row.  Then insert from that new row 3 to make a new dummy row 2 and then insert new rows from the new row 3. Then, the formula will again do the total carbs/day in both the morning and evening rows.  As you can see, I have a graph that shows carbs for each row and the total carbs/day.  The chart looks much better when both rows for the day show the same value.  Do you understand why the formula does not work the same when new rows are inserted from row two than when they are inserted from row 3?  See attached.

I suspect we've discussed this as much as any of us want.   So, this will be my last post in this discussion.  I also assume the version of Excel in use supports the necessary formulas and features.

 

The idea behind the below is that I've never been a fan of asking someone to "make space at the top" to enter data, though, sad to say, I've done it.  But with the newer capabilities of Excel, we can avoid that kind of UI/UX.

 

With the dates in column A and the readings in column

 

For a 7 day average for the most recent 7 days, use

=AVERAGEIFS(D:D,A:A,">="&MAX(A:A)-7)

To get a list of the latest 7 days and the average reading per day, I'd use the dynamic array formulas:

In N4:

=MAX(A:A)-SEQUENCE(7,,0)

In O4:

=AVERAGEIFS(D:D,A:A,N4#)

 

@wcstarks 

@wcstarks 

Not sure I understood. If we speak about Carbs / Day formula it could be like

=IF(
  ([@[Time Slot]]="")*
  (ROW()-ROW(tblQ1[[#Headers], [Time Slot]]))=2, [@Carbs],
  SUMPRODUCT([Carbs]*(INT([Date])=[@Date]))
)

see Carbbs2 column in attached. 

If Glucose 7 day avr shall we exclude these dummy rows from average?  But that affects only these dummy rows.