+ Reply to Thread
Results 1 to 19 of 19

How to avoid counting same values in multiple countifs

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    How to avoid counting same values in multiple countifs

    Hi all I'm having a bit of a brain freeze today and wondering could someone point me in the right direction.

    I have several COUNTIFS formulas in a single cell in a worksheet, all added together. The idea is that I am counting numbers of staff from a time & attendance worksheet where they fall under the criteria to be excused from this particular report. There is a lot of criteria and with the function I am using, for some departments I am getting more excused numbers of staff than actually exist in the department.

    I think this is because some staff are being counted twice or more. Can someone point me to the correct logic I should be looking for in the COUNTIFS to ensure that the results of one COUNTIFS is not also counted in another?

    Here's the formula I am using:

    =COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!M:M,"<0.25",'DAA Exception Report'!M:M,"<>0")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!N:N,"<0.25",'DAA Exception Report'!M:M,"<>0")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!E:E,"*Flex*",'DAA Exception Report'!L:L,"Unmatched target")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!J:J,">"&'DAA Exception Report'!I:I)+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!F:F,"Y",'DAA Exception Report'!L:L,"<>Missed a clocking")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!F:F,"Y",'DAA Exception Report'!L:L,"<>Swiped outside of shift & Missed a clocking & Unmatched target")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!F:F,"Y",'DAA Exception Report'!L:L,"<>Swiped outside of shift & Missed a clocking")+COUNTIFS('DAA Exception Report'!C:C,Main!B9,'DAA Exception Report'!F:F,"Y",'DAA Exception Report'!L:L,"<>Missed a clocking & Unmatched target")
    Last edited by Fotis1991; 12-23-2014 at 07:31 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How would I do this (simple logic question)?

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    Hi, see a sample xls attached. The formula is in D4 of "Calculation" sheet. It's counting the exceptions correctly, but it's obviously counting too many as it should I think only be a few hundred. How could I best count each criteria without counting them more than once? Thanks for any help.
    Attached Files Attached Files

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How would I do this (simple logic question)?

    Can't you use the Unauthorised Absence column?

    So then Calculation!D4 becomes:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    That's the thing, we're doing this because the system does not work the way we want it to. So the Unauthorised absence column in the report is never populated properly.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How would I do this (simple logic question)?

    Can you add a helper column to your source file?

  7. #7
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    I'm not sure what you mean?

    All we need is way to count each of the above COUNTIFS only where it's also NOT one of the other exceptions, if you know what I mean. That's where I'm stuck.

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How would I do this (simple logic question)?

    Hi.

    Perhaps you should state the logical conditions which are to be used to generate that figure, rather than simply giving your current formula, since there may be both errors and inconsistencies in the logic you have used there.

    I'm afraid that, just looking at it, it is not at all easy to guess what that logic is. However, I can tell you that in general, if you're not sure what you're doing then of course you can end up with such a result.

    For example, if I had a list of 10 people, and I wanted to find out how many of those 10 did not own a car and also did not own a house, I could not do this by simply calculating how many did not have a car, then calculating how many did not have a house, and finally adding the two together. I don't know if that's the mistake you've made here, though I hope you can see why that approach fails logically.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  9. #9
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    You make some good points, it is possible my logic is entirely wrong.

    What I'm trying to count under the "Excused Exceptions" heading is the following:

    1) Where Late clock ins are less than 15 mins (0.25 in decimal time) and do not equal zero
    2) Where Early clock outs are less than 15 mins (0.25 in decimal time) and do not equal zero
    3) Where Shift column (column E) contains the word "Flex" AND the corresponding row in column L is "Unmatched target"
    4) Where worked hours (col J) is greater than target hours (col I)
    5) Where Swap (col F) is equal to "Y" AND column L DOES NOT equal "Missed a clocking" or DOES NOT equal "Swiped outside of shift & Missed a clocking & Unmatched target" or DOES NOT equal "Swiped outside of shift & Missed a clocking" or DOES NOT equal "Missed a clocking & Unmatched target"

    These are the explanations of the countifs I currently have. The problem, as you can imagine, is that a count in 1) might also be counted in 4) for example. Do you have any idea how this could be avoided?

    Or, indeed, if there is a better way of doing it that I am not thinking of? All help appreciated. It is entirely possible my brain is fried thinking about this too much and I am off track!

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How would I do this (simple logic question)?

    That's very helpful. Many thanks.

    Could I just ask for one final thing? Can you let me know what your manually-calculated expected result is, just so I know what I'm aiming for?

    Regards

  11. #11
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    Honestly I'm not entirely certain, as what we were calculating before contained multiples as above. It should not be more than the total at the very least. If I know the result does not contain multiples then I'm happy to be honest!

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How would I do this (simple logic question)?

    But can't you manually obtain your result by selective filtering on the appropriate columns?

    Regards

  13. #13
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    Yes but that will give me the same cumulative total as on the sheet. The part I don't know how to do is ensure I don't count each exception more than once. Manually I guess I could mark each entry I've already counted but that would take a huge amount of time

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How would I do this (simple logic question)?

    No - I mean surely there's a way for you to manually calculate what the actual result should be! Even if it's a long-hand process using several steps and pen and paper if necessary.

    Regards

  15. #15
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How would I do this (simple logic question)?

    I spoke too soon, I marked each line of the report as I went through the steps (obviously this only counts each exception once) and it came out at 674 - so that should be the figure to reach. If you could help get that in a formula I think we'd be done!

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How would I do this (simple logic question)?

    Thanks. Can you just clarify, when you say:

    Quote Originally Posted by eoindub View Post

    1) Where Late clock ins are less than 15 mins (0.25 in decimal time) and do not equal zero
    2) Where Early clock outs are less than 15 mins (0.25 in decimal time) and do not equal zero
    3) Where Shift column (column E) contains the word "Flex" AND the corresponding row in column L is "Unmatched target"
    4) Where worked hours (col J) is greater than target hours (col I)
    5) Where Swap (col F) is equal to "Y" AND column L DOES NOT equal "Missed a clocking" or DOES NOT equal "Swiped outside of shift & Missed a clocking & Unmatched target" or DOES NOT equal "Swiped outside of shift & Missed a clocking" or DOES NOT equal "Missed a clocking & Unmatched target"
    are these all "AND" conditions, so that all of 1) to 5) must be met to generate the count?

    Or are they five separate "OR" conditions, so that we work out a total for each of 1) to 5) and then sum those?

    I assume it's the latter since, if we just take condition 1), there are only 4 results in the entire sheet for which the Late Clock In is <0.25 and also <>0.

    Regards

  17. #17
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How to avoid counting same values in multiple countifs

    They are indeed separate OR conditions

  18. #18
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to avoid counting same values in multiple countifs

    This formula covers all conditions. The range taken is Rows 2:10 (Eg G2:G10).Change the range as required and verify th formula result. There will not be any duplicate countng.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    09-10-2014
    Location
    Dublin
    MS-Off Ver
    2010
    Posts
    18

    Re: How to avoid counting same values in multiple countifs

    Thanks a lot, that works but it pulls in a few more than anticipated so I'll have a deeper look later.

    I've also managed to do it another way which I think works. I created a new column in the exception report and used the following:

    Please Login or Register  to view this content.
    To put the word "count" on each row that meets the criteria, and then I simply count them. It gives me the 674 I need so I think it's good.

    Many Thanks to everyone for their help!

+ 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. Need help transferring this logic to simple excel formula
    By yougandhar1 in forum Excel General
    Replies: 4
    Last Post: 09-22-2014, 05:24 PM
  2. [SOLVED] Simple multiple logic test help
    By rexy69 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2014, 11:31 AM
  3. if(and(or...logic question
    By jw01 in forum Excel General
    Replies: 3
    Last Post: 01-15-2012, 02:20 PM
  4. Logic question
    By rhyan66 in forum Excel General
    Replies: 3
    Last Post: 02-18-2009, 05:08 PM
  5. Simple Copy-Paste logic not working
    By Brian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2005, 02:40 PM

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