+ Reply to Thread
Results 1 to 45 of 45

Calculating a percentage based on rows above and below

  1. #1
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Calculating a percentage based on rows above and below

    Hello and thank you in advance for any help provided,

    One row is all values regarding one single entry and I would like to create a formula (or how many necessary, or any other suggestions or is it even possible to do so?) which would analyze every single row taking into consideration 8 rows above and 8 below without counting with the row itself, giving me the probability to have any of the "B5", "B4", "B3", "B2" or "B1" in Column C rather than "B0" when there's a row with "R" in Column I, and then the same in another column but now checking up to 20 rows away (above or below). I do something similar (regarding to check the rows above and below) with the formula =LET(A,B2:INDEX(B:B,MATCH("ZZzz",B:B)),B,C2:INDEX(C:C,MATCH("ZZzz",C:C)),C,X2:X7,D,Y2:Y7,F,ROW(B),BYROW(A,LAMBDA(z,LET(G,FILTER(B,(F>ROW(z)-9)*(F<ROW(z)+9)*(F<>ROW(z))),SUM(IFERROR(XLOOKUP(G,C,D),0)))))) which gives me a score based on 8 rows above and below, unrelated to the current question but just thought in putting it here if it helps with the rows above and below request.

    Goal is to see the probability of having a "B5", "B4", "B3", "B2" or "B1" value instead of a "B0" when a value is within 8 rows above or below of a "R" in Column I (percentage on the same row as I= "R", Column J) and then doing the same to compare the probability when it's up to 20 rows away (above or below) on Column K as per the provided spreadsheet.

    For example in the provided spreadsheet, I14, on J14 it's 6.25% of having B5, B4, B3, B2 or B1 on column C in the 8 rows above or below (only C21 in the the range with "B5" so 1 out of 16). K14 is 10% (3 out of 30, 12 rows up, 18 bellow) 10%. It will be 20 rows up and below but this is a limited spreadsheet to serve as example.

    I've attached a test spreadsheet through Onedrive link (and uploaded the file just in case the link didn't work) with limited rows for you to be able to see and all the formulas used on that spreadsheet are on the first row. Do let me know if I didn't explained correctly, English isn't my first language and it's not something exactly easy to explain, happy to provide any more information that anyone might require to help me.

    Test1.xlsx

    https://1drv.ms/x/s!An0SvH8nZTgpg-l8...7qpOw?e=FCgXWY

    Thank you
    Last edited by ExcelNewbie92; 04-25-2024 at 07:30 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Where are your expected results?

    There is no worksheet called Main. I can't find the LET formula anywrere.

    Please add some annotations and better signposting to the sample workbook.
    Last edited by AliGW; 04-25-2024 at 06:42 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Hello AliGW and thank you for your reply, I've removed some unnecessary things from the spreadsheet (as in, no need for the worksheet Main for example) and did the two examples on column J and K, updating some bits in the first post. Looking for doing that on J14, J21 and K14, K21 automatically with a formula, detecting the value "K" on Column I and do that percentage on a spreadsheet with many more rows

    Thank you and do let me know if I missed something else that you require.
    Last edited by AliGW; 04-25-2024 at 07:35 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Sorry - I am still struggling.

    I have no clue what this actually means: "one out of 16 (C21 is a B5) total count of 8 rows up and 8 below), 6.25%".

  5. #5
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    So on that case, counting 8 rows above and 8 rows below (total 16) only one of those rows has in the equivalent Column C "B5", "B4", "B3", "B2" or "B1" (which in that example is C21). So the probability of having any "B5", "B4", "B3", "B2" or "B1" on Column C of rows below or above the row with Column I = "R" is 6.25%

    Did it make more sense? If not I can try again, sorry about it.

    On Column K is the same thing but with 20 rows above and 20 rows below instead of 8
    Last edited by AliGW; 04-25-2024 at 07:46 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Sorry - I think I'll leave this to someone else. I don't know enough about probability to work out a suitable formula for what you want, and you haven't said what the manual calculation should be.

  7. #7
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Thanks anyway AliGW! Just for reference, in the 8 rows above and below, the total number is always 16, once the amount of "B5", "B4", "B3", "B2" or "B1" are counted in Column C within that range, the sum number is divided by the total number. On the example previous mentioned is 1 (which is the number of times there was "B5", "B4", "B3", "B2" or "B1"in that range) divided per the total which is 16 giving 0.0625, 6.25%
    Last edited by AliGW; 04-25-2024 at 09:12 AM. Reason: Please STOP quoting unnecessarily!

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    OK - I sort of follow this, but have no clue how you get that percentage. Exactly WHICH rows are you counting for I14 and how is C21 relevant? I'm not quite getting it.

    Talk me through the EXACT calculation step-by-step.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Hang on - I think I get it.

    Try this in J14:

    =LET(r,ROW()-1,f,FILTER(F2:F32,(ROW(F2:F32)>r-8)*(ROW(F2:F32)<r+8)),SUMPRODUCT((f<>0)*(f="B5"))/16)

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    I think I've got it. Try this in J2 copied down:

    =IF(I2="R",LET(r,ROW()-1,f,FILTER($D$2:$D$32,(ROW($D$2:$D$32)>r-8)*(ROW($D$2:$D$32)<r+8)),SUMPRODUCT((f<>0)*(f=1))/16),"")

    But I don't understand column K ...
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    OK - I sort of follow this, but have no clue how you get that percentage. Exactly WHICH rows are you counting for I14 and how is C21 relevant? I'm not quite getting it.

    Talk me through the EXACT calculation step-by-step.
    So in that example, R is on I14, 8 rows above so until I6 and I22 (not counting with I14 itself).

    You last comment it works and it's giving the right answer, but could it be a coincidence? The Column to check and count is C, counting all the same that there is "B5", "B4", "B3", "B2" or "B1" withing the range (I14 and I22)

    I'm almost coming up with an answer myself using:

    =IF(I2="R", COUNTIFS(OFFSET(C2,-8,0,17,1), "B5")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B4")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B3")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B2")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B1")-1, "")/16

    Don't know if it's more efficient or less than yours. Only downside is that I get #VALUE! on the empty rows (would rather your version which I could make it blank)

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    The Column to check and count is C, counting all the same that there is "B5", "B4", "B3", "B2" or "B1" withing the range (I14 and I22)
    This is the bit I'm not getting.

    I have asked you to talk me through the EXACT mechanics of that calculation. You still haven't done this and I'm afraid I do not fully undertstand what that calculation should be. If you'd just talk me through it, I could give it another go. Or you could highlight the cells in the workbook that need to be counted.

  13. #13
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    This is the bit I'm not getting.

    I have asked you to talk me through the EXACT mechanics of that calculation. You still haven't done this and I'm afraid I do not fully undertstand what that calculation should be. If you'd just talk me through it, I could give it another go. Or you could highlight the cells in the workbook that need to be counted.
    Sorry, would try do it but I just noticed where perhaps the problem is. "B5", "B4", "B3", "B2" or "B1" is a grading system of my own and this values and not regarding any value on cells B5 B4 B3 etc

    If the value of I="R" then I take into consideration 8 rows above and 8 rows below the row where I="R", in these rows I check Column C and count how many of them have "B5", "B4", "B3", "B2" or "B1" and finally I divide this last number for the total of rows checked (which is 16)

    Example in the spreadsheet:

    I14="R" so I went and counted in Column C how many times do I have the values "B5", "B4", "B3", "B2" or "B1" through C6 and C22 (ignoring C14, as that is the row where I="R"). In this case it only happens once through C6 to C22 (value of C21 is "B5"). Now I divide 1, which was the total number of times that I had "B5", "B4", "B3", "B2" or "B1" and divide it by 16, the total number of rows checked giving me 0.0625 (6.25% chance of having a value "B5", "B4", "B3", "B2" or "B1")

    Let's do the other example. I21="R". Now I'm going to check Column C 8 rows above and below row 21, so from C13 to C29 and this time the count of "B5", "B4", "B3", "B2" or "B1" on Column C was 2 (value of C29 is "B3" and value of C14 is "B5"). 2/16 gives gives 12.5%

    I do hope I was clearer this time, and thank you for your patience AliGW. I'm going to work on Column K as I just noticed a mistake there, and will need to provide a slightly bigger example with more rows so that I can do it manually and show it.

  14. #14
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Column K.xlsx

    Column K spreadsheet with example and explanation there.

  15. #15
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Calculating a percentage based on rows above and below

    perhaps in K30
    =IF(I30="R",(SUM(COUNTIF($C$2:C21,{"B1","B2","B3","b4","B5"}))+SUM(COUNTIF(C39:$C$58,{"B1","B2","B3","b4","B5"})))/40,"")

    or
    =IF(I30="R",(COUNTIF($C$2:C21,"<>B0")+COUNTIF(C39:$C$58,"<>B0"))/40,"")

  16. #16
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by davsth View Post
    perhaps in K30
    =IF(I30="R",(SUM(COUNTIF($C$2:C21,{"B1","B2","B3","b4","B5"}))+SUM(COUNTIF(C39:$C$58,{"B1","B2","B3","b4","B5"})))/40,"")

    or
    =IF(I30="R",(COUNTIF($C$2:C21,"<>B0")+COUNTIF(C39:$C$58,"<>B0"))/40,"")
    That did it for that example! How could I apply to a whole spreadsheet, as in apply the formula to K2 and then apply it to the whole column? As the original spreadsheet have thousands of entries

  17. #17
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    This is the bit I'm not getting.

    I have asked you to talk me through the EXACT mechanics of that calculation. You still haven't done this and I'm afraid I do not fully undertstand what that calculation should be. If you'd just talk me through it, I could give it another go. Or you could highlight the cells in the workbook that need to be counted.
    I'm trying to adapt your formula to:

    =IF(I2="R",LET(r,ROW()-1,f,FILTER(C:C,(ROW(C:C)>r-8)*(ROW(C:C)<r+8)),SUMPRODUCT((f="B5")+(f="B4")+(f="B3")+(f="B2")+(f="B1"))/16),"")

    But in certain situations doesn't quite work, perhaps is it still counting the row where I="R" or perhaps it's not counting the 8th cell? Still working on it and see if I can adapt it myself

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    I don't remember seeing anywhere that the row the formula is on shouldn't be counted until now.

    Change my formula to this to see which cells it's counting (put it in a cell somewhere where it can spill down):

    =LET(r,ROW()-1,f,FILTER(F2:F32,(ROW(F2:F32)>r-8)*(ROW(F2:F32)<r+8)),s,SUMPRODUCT((f<>0)*(f="B5"))/16,f)

    I'm going offline now, but if you still want help, I'll be back tomorrow morning.

  19. #19
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    I don't remember seeing anywhere that the row the formula is on shouldn't be counted until now.

    Change my formula to this to see which cells it's counting (put it in a cell somewhere where it can spill down):

    =LET(r,ROW()-1,f,FILTER(F2:F32,(ROW(F2:F32)>r-8)*(ROW(F2:F32)<r+8)),s,SUMPRODUCT((f<>0)*(f="B5"))/16,f)

    I'm going offline now, but if you still want help, I'll be back tomorrow morning.
    Thanks for all your help AliGW! I ended up fixing this formula which does what I need and now leaving in blank when there's nothing to report:

    =IF(I2="R", (COUNTIFS(OFFSET(C2,-8,0,17,1), "B5")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B4")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B3")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B2")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B1")-1)/16, "")

    All I need now is to find a way to apply your formula davsth to the whole column and doing exactly what it does to every time that I="R", I've been trying but so far no luck

  20. #20
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by davsth View Post
    perhaps in K30
    =IF(I30="R",(SUM(COUNTIF($C$2:C21,{"B1","B2","B3","b4","B5"}))+SUM(COUNTIF(C39:$C$58,{"B1","B2","B3","b4","B5"})))/40,"")

    or
    =IF(I30="R",(COUNTIF($C$2:C21,"<>B0")+COUNTIF(C39:$C$58,"<>B0"))/40,"")
    Any ideas on how to turn one of these formulas do work exactly as it does but for every time I="R"? Still stuck at it

    Thanks

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Thet's what the IF clause does.

    Please attach a fresh workbook with the formula in place and notes about where it is not currently working.

  22. #22
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    Thet's what the IF clause does.

    Please attach a fresh workbook with the formula in place and notes about where it is not currently working.
    Here you go AliGW, with only K column related information, manual example and how I got it plus davsth formula which works, but would just need something to actually apply the same logic for every time that I="R" as in the original spreadsheet this happens a few times.

    Column K.xlsx

  23. #23
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    In K2 copied down:

    =IF(I2="R",LET(d,$C$2:$C$118,r,ROW(I2),f,VSTACK(FILTER(d,((ROW(d)<r-8)*(ROW(d)>=r-28))),FILTER(d,((ROW(d)>r+8)*(ROW(d)<=r+28)))),SUMPRODUCT((f<>"")*(f<>"B0"))/40),"")
    Attached Files Attached Files

  24. #24
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Any good???

  25. #25
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Quote Originally Posted by AliGW View Post
    In K2 copied down:

    =IF(I2="R",LET(d,$C$2:$C$118,r,ROW(I2),f,VSTACK(FILTER(d,((ROW(d)<r-8)*(ROW(d)>=r-28))),FILTER(d,((ROW(d)>r+8)*(ROW(d)<=r+28)))),SUMPRODUCT((f<>"")*(f<>"B0"))/40),"")
    Sorry had to be away from the computer, just tested and seems to work perfectly!! Thank you AliGW

  26. #26
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  27. #27
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    I have given reputation indeed, well deserved! Thank you so much
    Last edited by AliGW; 04-26-2024 at 10:56 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  28. #28
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    It took me a long time to understand what was required.

    For future questions, consider highlighting cells that need to be included in a count where it's not straightforward - visuals in the workbook can help enormously.

    I'm glad I cracked it, because it was bugging me.

  29. #29
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Hello and sorry to reply on a solved thread as I just noticed a small problem with the formulas

    This formula from below from you AliGW it works great but if the value of "IR" is too close to the beginning or the end of the sheet values I get a #CALC! error as it probably doesn't have the amount of values to calculate. Is there a way around it?

    And if so, in this cases the last bit of the formula "/40" would have to be adapted to the actually amount of cells analysed, otherwise it would report an incorrect value (for example, if it looks up to 40 rows, 5 of those rows match so 5/40. But in these cases if it only looks up to say 29 rows for example (due to being in the beginning/end of the sheet), let's say 5 of those rows match but should be 5/29 in these cases.

    =IF(W7="IR",LET(d,C:C,r,ROW(W7),f,VSTACK(FILTER(d,((ROW(d)<r-8)*(ROW(d)>=r-28))),FILTER(d,((ROW(d)>r+8)*(ROW(d)<=r+28)))),SUMPRODUCT((f<>"")*(f<>"B0"))/40),"")


    And then If I could ask for assistance in this formula below that I'm using, which in a similar way as the formula above checks rows above and below (without counting the row itself where it applies, in this case W7="IR"). It's giving a #REF! error which I assume is due to the same situation, doesn't have enough values to check as it's too close to the beginning/end of the sheet

    Sorry to come back at this post especially on a Sunday! Happy to provide an updated test sheet if necessary.

    Thanks

    =IF(W7="IR", (COUNTIFS(OFFSET(C7,-8,0,17,1), "B5")+COUNTIFS(OFFSET(C7,-8,0,17,1), "B4")+COUNTIFS(OFFSET(C7,-8,0,17,1), "B3")+COUNTIFS(OFFSET(C7,-8,0,17,1), "B2")+COUNTIFS(OFFSET(C7,-8,0,17,1), "B1")-1)/16, "")

  30. #30
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    Use this instead:

    =IF(I2="R",LET(d,$C$2:$C$118,r,ROW(I2),f,VSTACK(FILTER(d,((ROW(d)<IF(r-8<1,r,r-8))*(ROW(d)>=IF(r-28<1,1,r-28)))),FILTER(d,((ROW(d)>r+8)*(ROW(d)<=r+28)))),SUMPRODUCT((f<>"")*(f<>"B0"))/40),"")

    I'm not able to fix the same error at the top of the table at the moment - I'll look again later.

    No time now.
    Last edited by AliGW; 04-28-2024 at 10:27 AM.

  31. #31
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Thank you AliGW, it fixes the error however the maths are incorrect, I believe it's because in that situation it's still doing "/40" at the end when in reality it should be as many cells as it managed to count ("/40" maximum if enough values are provided)

    I've edited your file and added a new example in Column L7 and new notes there

    Column K(2) AliGW.xlsx

  32. #32
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    OK - I'm out for now - got to go and eat. Maybe someone else will have a go.

  33. #33
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    No worries you've helped so much already!

    I've done an updated sheet example with notes for my other problem in this thread with the formula

    =IF(I2="R", (COUNTIFS(OFFSET(C2,-8,0,17,1), "B5")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B4")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B3")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B2")+COUNTIFS(OFFSET(C2,-8,0,17,1), "B1")-1)/16, "")

    Test1.xlsx

  34. #34
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    This has become too complicated for my tiny brain - sorry. I'm going to call it a day, but I'll put out a call for help. Good luck!

  35. #35
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Your brain is far from tiny and you've helped so much already AliGW, really gratefull Maybe it's not possible or too hard to create a formula with these requirements

  36. #36
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    I don't think it's impossible, but I have brain freeze on it at the moment. I may at some point get a flash of inspiration - it's still swilling around my head, anyway.

  37. #37
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Anyone else wants to have a go at this two problems? do let me know if I can provided any more information or explain something better. I've been trying but so far no luck

    Thanks

  38. #38
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    I thought I'd posted in Call in the Cavalry yesterday - I'll check that I did. But the thread's had a lot of views, so I think a lot of us are scratching our heads on this one.

    EDIT: Yes, I did, but I've bumped it. There's nothing more that I can do - hope someone can finish it for you.

  39. #39
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    I think what would be helpful, actually, is a copy of the sample data with ALL of the results mocked up for the first and last 28 rows as if they were all R - this would help members trying to check possible solutions. Can you do that?

  40. #40
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Absolutely, don't have much free time right now but I will post that still today.

    Do you want it for both problems sheets?

  41. #41
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Calculating a percentage based on rows above and below

    If you do it for the one I was working on first - that should be enough, I think, but if anyone else wants to have a go, they can ask for the other. Caveat for me: I'm in Norwich for the day, so won't be looking again until tomorrow.

  42. #42
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    Here you go, Column J is all made manually:

    Column K(2) AliGW.xlsx

  43. #43
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Calculating a percentage based on rows above and below

    With B1 being the number of rows to count, if you want to fix it (8 or 20, etc.) without using cell B1, in the formula you replace B1 with that number.
    From column M to column R is the explanation part, split the formula into parts for you to understand how it works, column T is the final formula.
    Hope this works correctly.
    T2:
    Please Login or Register  to view this content.
    P/S: I forgot to mention that, in formula, B32 is the last used row in column B.
    Attached Files Attached Files
    Last edited by bebo021999; 05-01-2024 at 11:38 PM.
    Quang PT

  44. #44
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Calculating a percentage based on rows above and below

    Please try
    =LET(c,$C$2:$C$118,r,ROW(c),s,ROW(),y,(r>=s-28)*(r<s-8)+(r>s+8)*(r<=s+28),IF(I2="R",SUM(y*(c>"B0"))/SUM(y),""))

    or spill array

    =MAP(I2:I118,LAMBDA(x,IF(x="R",LET(c,C2:C118,r,ROW(c),s,ROW(x),y,(r>=s-28)*(r<s-8)+(r>s+8)*(r<=s+28),SUM(y*(c>"B0"))/SUM(y)),"")))

    round( number, 3) if needed
    Attached Files Attached Files

  45. #45
    Registered User
    Join Date
    03-02-2024
    Location
    UK
    MS-Off Ver
    365
    Posts
    54

    Re: Calculating a percentage based on rows above and below

    That work Bo_Ry and bebo021999! Thank you so much, had almost given up on this one and just reject the first and last batch of results.

    I've also adapted your formula Bo_Ry to fix my other problem in this thread to:

    =MAP(X2:X10000,LAMBDA(x,IF(x="R",LET(c,C2:C10000,r,ROW(c),s,ROW(x),y,(r>=s-8)*(r<s-0)+(r>s+0)*(r<=s+8),SUM(y*(c>"B0"))/SUM(y)),"")))

    Will mark as thread solved, reputation given. Thank you all!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculating bonus value based on percentage of goal met
    By embailey in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-26-2024, 04:37 PM
  2. [SOLVED] Calculating 'running' percentage (%) for rows with blank cells (but will be populated)
    By Kaycee831 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-03-2023, 10:32 AM
  3. Help on calculating percentage based on multiple criterias
    By Nitinkumar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-17-2019, 06:34 AM
  4. [SOLVED] calculating a percentage based on a yes/no column
    By hceoc_energy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-07-2014, 08:33 PM
  5. Calculating percentage of completed tasks in various rows
    By excelnoob808 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-29-2013, 05:37 AM
  6. Calculating percentage based on new data
    By Ken_NJ in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-22-2013, 02:38 PM
  7. Calculating Percentage based on Dynamic Cells
    By dimitrz in forum Excel General
    Replies: 4
    Last Post: 12-16-2008, 12:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1