Home

Taking values from certain rows based on data input

%3CLINGO-SUB%20id%3D%22lingo-sub-858458%22%20slang%3D%22en-US%22%3ETaking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858458%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20I'm%20trying%20to%20get%20a%20value%20into%20the%20column%20%22Cat%20A%20Tied%22%20(C%20column).%20This%20value%20depends%20on%20the%20number%20in%20the%20%22%23%20People%20Tied%20With%22%20column%20(D%20Column).%20In%20this%20case%2C%20cell%20D2%20has%20the%20number%203%20in%20it.%20I%20want%20the%20sum%20of%20the%20first%20three%20rows%20of%20the%20B%20column%20(not%20including%20column%20headers)%20and%20then%20divide%20that%20by%203.%20However%2C%20I%20want%20the%20cell%20to%20be%20dynamic%20so%20if%20I%20change%20the%20number%20to%205%20it%20will%20then%20automatically%20take%20the%20sum%20of%20the%20first%205%20rows%20and%20divide%20by%205.%20Additionally%2C%20if%20I%20put%20this%20value%20into%20D3%2C%20the%20second%20row%20of%20my%20table%2C%20I'd%20want%20the%20first%20number%20(3%20or%205%2C%20or%20any%20number%20put%20in)%20of%20rows%20from%20that%20same%20row%20onwards%20instead%20of%20from%20the%20first%20row%20of%20the%20data%20set.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20345px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F132067i5A2B86F779BB8BBD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Screenshot_1.jpg%22%20title%3D%22Screenshot_1.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EAny%20help%20would%20be%20greatly%20appreciated%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-858458%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EColumns%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERows%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETables%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-858538%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858538%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F410176%22%20target%3D%22_blank%22%3E%40Drakerla%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20try%20this%20and%20let%20me%20know%20if%20this%20is%20what%20you%20are%20trying%20to%20achieve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20C2%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3DIF(D2%3D%22%22%2C%22%22%2CSUM(OFFSET(%24B%241%2CROW(D2)-1%2C%2CD2)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eand%20then%20copy%20it%20down.%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-858552%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858552%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3EYes%20that's%20brilliant!%20Thanks%20so%20much!%3CBR%20%2F%3EWould%20you%20mind%20explaining%20how%20it%20works%20please%2C%20as%20I%20like%20to%20learn%20these%20things%20for%20future%20use%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-858556%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858556%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20only%20change%20needed%20is%20to%20divide%20that%20SUM%20value%20by%20the%20value%20in%20cell%20D2.%20But%20thank%20you%20so%20much%20for%20your%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3E%3DIF(D2%3D%22%22%2C%22%22%2CSUM(OFFSET(%24B%241%2CROW(D2)-1%2C%2CD2)))%2FD2%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-858638%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858638%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F410176%22%20target%3D%22_blank%22%3E%40Drakerla%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20I%20missed%20the%20division%20part%20but%20that%20was%20easy%20to%20fix%20and%20glad%20you%20did%20it%20right.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20range%20passed%20to%20the%20SUM%20function%20is%20derived%20with%20the%20help%20of%20OFFSET%20function%20in%20which%20the%20anchor%20cell%20is%20%24B%241%20(which%20is%20absolute%20reference%20and%20will%20always%20be%20the%20same%20when%20you%20copy%20the%20formula%20down)%20and%20the%20row%20is%20offset%20by%20ROW(D2)-1%20which%20returns%20the%20first%20cell%20in%20the%20sum%20range%20i.e.%20if%20the%20formula%20is%20placed%20in%20the%20second%20row%2C%26nbsp%3BROW(D2)-1%20will%20return%201%20and%20hence%20the%20first%20cell%20in%20the%20sum%20range%20would%20be%20one%20row%20offset%20from%20the%20anchor%20cell%20B1%20which%20would%20be%20cell%20C1%20(if%20you%20wish%20you%20may%20remove%20the%20D2%20from%20ROW(D2)%20and%20make%20it%20just%20ROW()%20and%20it%20will%20work%20in%20the%20same%20way)%20and%20then%20the%20height%20is%20determined%20by%20the%20number%20in%20the%20D2%2C%20If%20you%20evaluate%20the%20formula%20in%20D2%2C%20it%20would%20be%20easy%20for%20you%20to%20know%20how%20this%20formula%20works.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20that%20takes%20care%20of%20your%20original%20question%2C%20please%20accept%20the%20post%20with%20the%20proposed%20solution%20as%20a%20Best%20Answer%2FResponse%20to%20mark%20your%20question%20as%20Solved.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-859916%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20values%20from%20certain%20rows%20based%20on%20data%20input%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-859916%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F410176%22%20target%3D%22_blank%22%3E%40Drakerla%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20variant%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3DIFERROR(SUM(INDEX(B%3AB%2CROW())%3AINDEX(B%3AB%2CROW()%2B%24D2-1))%2F%24D2%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Drakerla
New Contributor

So I'm trying to get a value into the column "Cat A Tied" (C column). This value depends on the number in the "# People Tied With" column (D Column). In this case, cell D2 has the number 3 in it. I want the sum of the first three rows of the B column (not including column headers) and then divide that by 3. However, I want the cell to be dynamic so if I change the number to 5 it will then automatically take the sum of the first 5 rows and divide by 5. Additionally, if I put this value into D3, the second row of my table, I'd want the first number (3 or 5, or any number put in) of rows from that same row onwards instead of from the first row of the data set.

Screenshot_1.jpg

Any help would be greatly appreciated

 

5 Replies

@Drakerla 

Please try this and let me know if this is what you are trying to achieve.

 

In C2

=IF(D2="","",SUM(OFFSET($B$1,ROW(D2)-1,,D2)))

and then copy it down.

 

 

@Subodh_Tiwari_sktneerYes that's brilliant! Thanks so much!
Would you mind explaining how it works please, as I like to learn these things for future use?

The only change needed is to divide that SUM value by the value in cell D2. But thank you so much for your help!

 

=IF(D2="","",SUM(OFFSET($B$1,ROW(D2)-1,,D2)))/D2

@Drakerla 

It seems I missed the division part but that was easy to fix and glad you did it right.

 

The range passed to the SUM function is derived with the help of OFFSET function in which the anchor cell is $B$1 (which is absolute reference and will always be the same when you copy the formula down) and the row is offset by ROW(D2)-1 which returns the first cell in the sum range i.e. if the formula is placed in the second row, ROW(D2)-1 will return 1 and hence the first cell in the sum range would be one row offset from the anchor cell B1 which would be cell C1 (if you wish you may remove the D2 from ROW(D2) and make it just ROW() and it will work in the same way) and then the height is determined by the number in the D2, If you evaluate the formula in D2, it would be easy for you to know how this formula works.

 

If that takes care of your original question, please accept the post with the proposed solution as a Best Answer/Response to mark your question as Solved.

@Drakerla 

Another variant

=IFERROR(SUM(INDEX(B:B,ROW()):INDEX(B:B,ROW()+$D2-1))/$D2,"")
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
ChirmyRam in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies