+ Reply to Thread
Results 1 to 30 of 30

Need formula to count table range depending on conditions in selected table columns

Hybrid View

  1. #1
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Need formula to count table range depending on conditions in selected table columns

    MOD NOTE: Query has been amended - see post #3.

    I have a worksheet for a game that logs a fighters stats, specifically Hit Points, What style of fight, the attack and defence, result etc.

    It has a sheet named "Fighter1" with a table that all the data goes into, and an overview page. The overview sheet will give me data based on the style of fight (aggressive, Defensive, Accurate, Balanced).

    I want these formulas on the Overview sheet to link to the "Fighter1" sheet dynamically so that when I add a fighter, I can copy and paste the "Fighter1" sheet and overview and all my formulas reference the new sheet the same way.
    I have done this through the indirect function, and naming my Sheet and the table within that sheet "Fighter1" and this is referenced back to the overview page at A1, where A1= Fighter1.

    I have been able to insert a formula for the Won:Lost column in the overview that has worked:

    =(COUNTIFS(INDIRECT($A$1&"[Result]"),"Won",INDIRECT($A$1&"[Style]"),B2))&":"&(COUNTIFS(INDIRECT($A$1&"[Result]"),"Lost",INDIRECT($A$1&"[Style]"),B2))

    This references the table in sheet "Fighter1" and tells me for each fighting style how many wins vs losses (in this case for Aggressive)

    I have then tried to create a formula for "basic hits" that has given me the #VALUE error:

    =IF(AND(INDIRECT($A$1&"[Style]")=B2,INDIRECT(A1&"[Attack Defense]"="Attack")),COUNT(INDIRECT(A1&"[[1]:[13]]"),"N/A"))

    This aims to give me how many times the fighter hit his opponent, (in this case in the "Aggressive" style, and in attack only).

    I have tried for ages to change the formula but cant work it out, I think I may be writing the logic function incorrectly with the indirect function?
    Any Help would be greatly appreciated!
    Attached Files Attached Files
    Last edited by AliGW; 05-26-2022 at 03:24 AM. Reason: Mod note added.

  2. #2
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Just To clarify, The answer to the basic hits formula I am trying to find in "aggressive" style should = 16 (Fighter hit 16 times, missed 1 time)

  3. #3
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Need formula to count table range depending on conditions in selected table columns

    Hi, I have a table with data that is entered from a game, the "Hit Points" are entered individually in each column (Column "1","2","3" etc). Next to those hit point columns there is a column "style" which tells me what style it was and a column with either attack or defence.

    I am trying to produce a summary depending on the Style.

    So I have tried a formula:

    =IF(AND(Fighter1[Style]=A3,Fighter1[Attack Defense]="Attack"),COUNT(Fighter1[[1]:[13]]),"N/A")

    I want this to tell me: depending on the style which in this case is reference A3 ("Aggressive"), and only for "Attack", how many times it "Hit".

    I am getting the #Value! error. Anyone know how I can do this or why the result is an error?

    Thanks in advance
    Attached Files Attached Files

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: how to find values in a table based on criteria from that table

    One way:

    =SUMPRODUCT((Fighter1[Style]=$A3)*(Fighter1[Attack Defense]="Attack")*TEXT(Fighter1[[1]:[13]],"General;-General;0;\0"))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  5. #5
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: how to find values in a table based on criteria from that table

    Thanks for getting back to me, Apologies, I should have had in the "basic Hits" summary, "Number of Hits", so rather than summing the total of the hits with those conditions I would like to know how many hits for those conditions (because there are cells that reference a "MISS" which I dont want to include)

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Please see the forum rules about duplicating queries.

    Having checked the workbooks provided in both threads, I have concluded that today's thread was indeed a duplicate, therfore |I have merged it with the original thread.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Hi, Its not the same workbook or question. I did not get a reply to my previous post I think because it may have been a bit complicated so I have given up on that workbook and created a new one that is simpler.

  8. #8
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Quote Originally Posted by AliGW View Post
    Please see the forum rules about duplicating queries.

    Having checked the workbooks provided in both threads, I have concluded that today's thread was indeed a duplicate, therfore |I have merged it with the original thread.
    Hi, Its not the same workbook or question. I did not get a reply to my previous post I think because it may have been a bit complicated so I have given up on that workbook and created a new one that is simpler.

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Well, the result table shown was identical, as was the lookup table. The only difference was that they are on the same worksheet in the closed thread.

    Continue here, please - feel free to update the title of the opening post, if you wish.

  10. #10
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Quote Originally Posted by AliGW View Post
    Well, the result table shown was identical, as was the lookup table. The only difference was that they are on the same worksheet in the closed thread.

    Continue here, please - feel free to update the title of the opening post, if you wish.
    I didnt change The Results table because I only brought it over as an example (these are not the results I am entering, I am just showing an example) but the summary table is different as is the formula and question I was asking, hence why I wanted to start a new thread so I didnt confuse people. Is there a way I can delete old post and start again, or can I delete my posts in this one so its not so confusing?

  11. #11
    Registered User
    Join Date
    03-01-2022
    Location
    Eire
    MS-Off Ver
    O365 Beta
    Posts
    84

    Re: Need formula to count table range depending on conditions in selected table columns

    Can you add some expected results to your sample file? I do not follow the explanation...

  12. #12
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Quote Originally Posted by ardross View Post
    Can you add some expected results to your sample file? I do not follow the explanation...
    Done,

    So I'm looking for Number of Hits (i changed the heading)= 16 (in Aggressive), Number Of misses etc, hopefully that makes sense
    Attached Files Attached Files

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

    Re: Need formula to count table range depending on conditions in selected table columns

    I will add a note to the opening post and you can amedn the title, as I suggested.

    Please provide the extra information requested in post #10.

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Try this:

    =SUMPRODUCT((Fighter1[Style]=A3)*(Fighter1[[1]:[13]]<>"")*(Fighter1[[1]:[13]]<>"MISS"))

    and this:

    =SUMPRODUCT((Fighter1[Style]=A3)*(Fighter1[[1]:[13]]="MISS"))
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Great, thankyou this is what I was after
    Last edited by AliGW; 05-26-2022 at 03:44 AM. Reason: PLEASE don't quote unnecessarily!

  16. #16
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    if I wanted to have this worksheet as a standard template for entering data, and have a separate overview sheet, How would I write this formula so it dynamically links to the fighter sheet. (so I can continually add New fighters and extra overview for those fighters)? I have added an example:
    Attached Files Attached Files
    Last edited by AliGW; 05-26-2022 at 04:11 AM. Reason: PLEASE don't quote unnecessarily!

  17. #17
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    This Is what I thought but I get A #REF error:

    =SUMPRODUCT((INDIRECT(A2&"[Style]"=B3)*(INDIRECT(A2&"[[1]:[13]]"<>"")*(INDIRECT(A2&"[[1]:[13]]"<>"MISS")))))

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you 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 all those who offered help.

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

    Re: Need formula to count table range depending on conditions in selected table columns

    First, change the Fighter2 table name from Fighter14 to Fighter2 in Name Manager.

    Then:

    =SUMPRODUCT((INDIRECT(A2&"[Style]")=B3)*((INDIRECT(A2&"[[1]:[13]]")<>"")*((INDIRECT(A2&"[[1]:[13]]")<>"MISS"))))

    for Fighter1 and:

    =SUMPRODUCT((INDIRECT(A8&"[Style]")=B10)*((INDIRECT(A8&"[[1]:[13]]")<>"")*((INDIRECT(A8&"[[1]:[13]]")<>"MISS"))))

    for Fighter2.
    Attached Files Attached Files
    Last edited by AliGW; 05-26-2022 at 04:22 AM.

  20. #20
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Thankyou, looks like I was on the right track, I had just missed some parenthesis.
    Last edited by AliGW; 05-26-2022 at 04:57 AM. Reason: PLEASE don't quote unnecessarily!

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

    Re: Need formula to count table range depending on conditions in selected table columns

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Administrative Note:

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below or the REPLY button instead of REPLY WITH QUOTE.

  22. #22
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Hi, I am attempting to add another condition to this formula, I have several values in the table that contain an "SP" at the start (e.g. SP 108), I want to ignore these cells in the formula but I cant seem to write it correctly. I have tried using a wildcard after the SP like this:

    =SUMPRODUCT((INDIRECT(A2&"[Style]")=B3)*((INDIRECT(A2&"[[1]:[13]]")<>"")*((INDIRECT(A2&"[[1]:[13]]")<>"MISS")*((INDIRECT(A2&"[[1]:[13]]")<>"SP"&"*")))))

    This is still including cells with "SP" in the count so I must be writing it wrong. I thought this would say "do not include cells with SP at the beginning with anything following
    ?

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Please provide me with a sample workbook and I will happily take a look.

  24. #24
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Thankyou,

    Ive just updated the old worksheet
    Attached Files Attached Files

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

    Re: Need formula to count table range depending on conditions in selected table columns

    Nothing there with SP:

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    9
    1 2 3 4 5 6 7 8 9 10 11 12 13
    10
    140
    100
    113
    81
    99
    106
    MISS
    146
    11
    -144
    -180
    MISS
    -116
    -185
    -151
    -181
    -147
    12
    177
    85
    141
    137
    138
    47
    182
    13
    -66
    -293
    -89
    -286
    MISS MISS
    -110
    14
    118
    88
    MISS
    143
    83
    178
    127
    MISS
    90
    60
    107
    15
    -124
    -99
    -142
    -58
    -110
    -106
    -85
    -11
    -187
    MISS
    -107
    16
    121
    144
    198
    85
    114
    107
    31
    182
    98
    17
    -71
    MISS
    -99
    -129
    -100
    -73
    MISS
    -230
    18
    Sheet: Fighter1

    Based on the last workbook you shared, and the one I shared back, you could try this:

    =SUMPRODUCT((INDIRECT($A$2&"[Style]")=$B3)*((INDIRECT($A$2&"[[1]:[13]]")<>"")*(ISNUMBER((INDIRECT($A$2&"[[1]:[13]]"))))))
    Attached Files Attached Files

  26. #26
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Sorry I uploaded the wrong one, I have reuploaded the correct one.

    In regards to the formula you suggested, I believe that is saying to include cells with numbers only? I Have another criteria in some cells that have OSH at the end which I still want the formula to include, I believe the formula you suggested wouldnt?
    Attached Files Attached Files

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

    Re: Need formula to count table range depending on conditions in selected table columns

    No, that's correct, so try this instead:

    =SUMPRODUCT((INDIRECT(A2&"[Style]")=B3)*((INDIRECT(A2&"[[1]:[13]]")<>"")*((INDIRECT(A2&"[[1]:[13]]")<>"MISS")*((LEFT(INDIRECT(A2&"[[1]:[13]]"),2)<>"SP")))))

  28. #28
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Ahh Great thankyou.
    Any Idea why the wildcard was not working in the formula I tried? I have used this in the past and I thought it would usually say dont include anything in cell starting with sp? Or Criteria in cell is SP with anything following it?

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

    Re: Need formula to count table range depending on conditions in selected table columns

    No except to say that I have had similar issues with it in the past.

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  30. #30
    Registered User
    Join Date
    05-25-2022
    Location
    adelaide
    MS-Off Ver
    2016
    Posts
    34

    Re: Need formula to count table range depending on conditions in selected table columns

    Thankyou much appreciated

+ 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. Replies: 1
    Last Post: 07-28-2020, 10:30 AM
  2. Replies: 16
    Last Post: 01-25-2018, 12:18 PM
  3. Populate a table depending on dropdown data selected
    By ftrindade in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 04-25-2017, 07:08 AM
  4. [SOLVED] table(A) as an array using all rows but only selected columns to compare with table(B)
    By se3unlock in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-27-2015, 10:15 AM
  5. Replies: 3
    Last Post: 03-12-2014, 09:07 PM
  6. Replies: 1
    Last Post: 07-05-2013, 08:40 PM
  7. Replies: 5
    Last Post: 06-22-2010, 03:17 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