+ Reply to Thread
Results 1 to 30 of 30

COUNTIF for distinct values only for two conditions

  1. #1
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    COUNTIF for distinct values only for two conditions

    Hi forum,

    I'm sure there's an easy way of doing this but i want to count values that only have either "*?-?*" or "*??-?*" where * and ? are the wildcards for the COUNTIF(s).

    How would I make it so that The formula will count values only if they appear every odd number of times
    Not really sure how else to explain it.
    Attached is a sheet trying to explain this better.

    I am close to getting a working result but still not quite there.
    Please find attached a sheet displaying what i want to achieve in yellow.

    Cheers,
    Julian
    Attached Files Attached Files
    Last edited by JulianS96; 02-24-2020 at 10:58 AM.

  2. #2
    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,387

    Re: Countif for distinct values only for two conditions

    You are making a rod for your own back here. Counting frequency without duplication (which is what you are describing) is already tricky enough WITHOUT dealing with merged cells. The first question, therefore, is do you really need merged cells? Can the data not be presented in a different way?
    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.

  3. #3
    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,387

    Re: Countif for distinct values only for two conditions

    Please don't post-edit your posts in this way! Always add extra detail in a new post to the thread - thanks.

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

    Re: Countif for distinct values only for two conditions

    It is not clear which values you are wishing to count and the criteria

    your sumproduct is just
    =COUNTIFS(B2:B9,"*-*") each cell has a - in with some characters before and after, so it returns 8


    what is the 6 made up of? you have not been explicit, It may be 10-1 , 5-1, 5-2, 5-5, 5-3, 5-4 the unique values with a - in the middle. But you have not said, putting multiple values in 1 cell which you have done, makes calculation far harder.

  5. #5
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Sorry. I'll explain in a second, hold tight

  6. #6
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Here is the updated excel with the additional criteria.
    Attached Files Attached Files

  7. #7
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    So you suggest i "unmerge" the cells then, instead of ALT-ENTER use enter instead into a new row? Hmm ok. If you're sure it can't be solved this way

  8. #8
    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,387

    Re: Countif for distinct values only for two conditions

    Yes, you should - what was the rationale for merging them?

  9. #9
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Rationale was less rows in the spreadsheet, but i guess i'm "adding" rows "space" by doing ALT Enter anyway.
    I've added colours and disbanded them into separate rows to make it easier to identify which is which pairing.
    Attached Files Attached Files

  10. #10
    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,387

    Re: Countif for distinct values only for two conditions

    With respect, that is NEVER a good enough reason for merging cells! LOL!!!

    Best advice: NEVER merge cells.

    Thanks for the workbook. Give us a while to take it all in.

  11. #11
    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,387

    Re: Countif for distinct values only for two conditions

    Am I losing the plot here?

    5-4 appears twice - how can that be an odd number duplicate appearance???

  12. #12
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Hmm ok. I don't think i explained it properly.
    What I want the formula to do is to count only pairs of numbers. i guess the odd number duplicate occurrence was a bit poorly worded.

    Yep, pairs of numbers, so 10-1 and 10-1 is one pair, 5-2, 5-2 (in beige) & 5-2, 5-2 (in red) equals 2 pairs so count should be 2 for "5-2"
    Last edited by JulianS96; 02-21-2020 at 07:29 AM.

  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,387

    Re: Countif for distinct values only for two conditions

    Can you explain the reason for this? If we understand your ultimate objective, we might be able to suggest an altogether easier way of handing your data.

    Are we able to use a helper column?

  14. #14
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    These are process numbers for each part in an assembly. For each part on the assembly if there is a join-up then those two parts receive a process number i.e. Part 1 and 3 go together and so Part 1 gets 5-1 and Part 3 gets 5-1 also.
    There are multiple assemblies and sometimes, as shown, the same process number will be allocated to the parts in question.
    i.e. In assembly 2, part 3 and 7 need to go together, but with the same process as in assembly 1. and so part 3 receives process number 5-1 part 7 receives process number 5-1
    If this does not make sense I can try to explain in a different way.
    Helper column would be fine, yes.
    Last edited by JulianS96; 02-21-2020 at 07:31 AM.

  15. #15
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Countif for distinct values only for two conditions

    Hi

    Try this huge formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  16. #16
    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,387

    Re: Countif for distinct values only for two conditions

    OK - look, Julian, I really think that it would be sensible to share a larger dataset with us, showing how these entries come together. I am certain, from what you have said, that there will be better ways to organise and analyse your data. This snapshot we are seeing here is, I fear, symptomatic of a dataset that lacks proper normalisation, and one that is only going to continue to throw up problems for you as you try to do your analyses going forward.

    I would recommend that you stop now and do a root and branch appraisal of your work: I suspect that your entire dataset can be normalised.

  17. #17
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Thanks for this, it works on the sheet, i'll check if it works on the data on Monday! cheers bud!

    And thanks ~ALiG will do, i'll organise it better on Monday

  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,387

    Re: Countif for distinct values only for two conditions

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

  19. #19
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    Ok so just to come back to this query again, as it is now Monday Morning!

    The formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    works on the sample data sheet but not on all of the data in the real sheet.

    So to reduce any further errors in the future, I have attached the same workbook but with all of the data from the parts this time. With part numbers and process numbers for clarity.

    Cheers,
    Julian
    Attached Files Attached Files

  20. #20
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    To be clear, the end of the data in Cell P is where I want the formula to be. I used the formula that was mentioned by Jose in post#15 but it does not work for some reason with the full data.
    I really have no idea what the formula is doing, but from mini research i know that 1/COUNTIF(Cell range, Cell range) find duplicates so that's good I suppose?

    What I want is highlighted in yellow in R171

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

    Re: Countif for distinct values only for two conditions

    Your problem Is that now you have included blanks in the range. I am thinking about a solution!

    Also 5-1 (and 4.2 and 4.1) occurs 4 times in the column do you wish to count as 1 or 2?


    in r3 as a helper column and copy down

    =IFERROR(1/COUNTIFS($P$2:$P$170,P3,$P$2:$P$170,"*?-?*"),0)


    then just sum this column
    Last edited by davsth; 02-24-2020 at 08:11 AM.

  22. #22
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: Countif for distinct values only for two conditions

    I wish to count it as "2" as that will be "2 pairs" of 5-1, 4-1 and 4-2.

    OK I'll try that thanks!

    The total has come to 13 when it should be 16? How do I rectify this error?
    Last edited by JulianS96; 02-24-2020 at 08:49 AM.

  23. #23
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: COUNTIF for distinct values only for two conditions

    Out of interest could it be possible to use this formula but ignore blanks?
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    OR When I sort my data the rows get hidden anyway, could this formula be used avoiding hidden rows?

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  24. #24
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: COUNTIF for distinct values only for two conditions

    I had a bit of tinkering around this morning with the formula and tried the COUNTBLANK function.
    the formula became:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This, however, does not work and still gives DIV#/0

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

    Re: COUNTIF for distinct values only for two conditions

    Perhaps the below as a helper column
    =IFERROR(1/COUNTIFS($P$2:$P$170,P2,$P$2:$P$170,"*?-?*")*CEILING(COUNTIFS($P$2:$P$170,P2,$P$2:$P$170,"*?-?*")/2,1),0)


    seems to work on a small test

  26. #26
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: COUNTIF for distinct values only for two conditions

    That seems to work! Awesome!
    Out of any interest is there a way to do it without a helper column? No worries if not! That works just fine!

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

    Re: COUNTIF for distinct values only for two conditions

    You could have a custom function written in vba to return the answer.
    below is a rough guide to them, but I am not expert using them!

    https://www.excel-easy.com/vba/examp...-function.html


    As a formula it starts to get messy. You having one instance where there is not a duplicate, makes it harder to do, as does having blanks in the data. There may be a way, but I've not thought of it yet!

  28. #28
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: COUNTIF for distinct values only for two conditions

    You having one instance where there is not a duplicate, makes it harder to do, as does having blanks in the data.
    Ah OK, so if I were to eliminate the one where it says 2-2 (with itself) or double it and say 2-2, then that would possibly be able to avoid helper column?

    Like this?
    Attached Files Attached Files

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

    Re: COUNTIF for distinct values only for two conditions

    if you avoided the single entries (or doubled them!)

    you can then count the pattern and divide by 2
    COUNTIFS($P$2:$P$170,"*?-?*")/2

    is your total

  30. #30
    Forum Contributor JulianS96's Avatar
    Join Date
    11-01-2019
    Location
    England
    MS-Off Ver
    365 (work-99%), 2016 (home-1%)
    Posts
    283

    Re: COUNTIF for distinct values only for two conditions

    Perfect! You've been very helpful davsth! Cheers,
    PROBLEM SOLVED

+ 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. [SOLVED] COUNTIF / SUMS where distinct Criteria is MET
    By rz6657 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-24-2020, 02:55 PM
  2. [SOLVED] get distinct values from criteria AND sum all of the values of the distinct
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-10-2017, 02:57 PM
  3. Countif Distinct and Criteria HELP!!!
    By deadlyliquidxxx in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-23-2015, 04:22 PM
  4. Count distinct records that meet multiple conditions
    By rubthebuddha in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-18-2013, 09:54 AM
  5. Distinct COUNTIF
    By TheNewUnion in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-19-2012, 06:27 AM
  6. Formula - Count distinct / Countif??
    By Africa in forum Excel General
    Replies: 3
    Last Post: 02-29-2012, 11:24 AM
  7. Replies: 9
    Last Post: 04-18-2011, 05:10 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