+ Reply to Thread
Results 1 to 23 of 23

Unique count of values based on corresponding ID and IF statement with similar condition

  1. #1
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Unique count of values based on corresponding ID and IF statement with similar condition

    Hi all,

    Sample data attached with expected results in columns highlighted in yellow. I require 4 formulas as follows (Hope I have described the logic correctly):

    Formula 1 - Unique count of Active Serial Numbers belonging to an ID
    Unique count of Col A (serial numbers) belonging to a unique ID in Col D where Col L = Yes

    Formula 2 - Unique Count of active serial numbers that are expiring within 90 days.
    Unique count of Col A (serial numbers) belonging to a unique ID in Col D where Col L = Yes and Expiry date (Col K) is within 90+NOW()

    Formula 3 - Check IF serial number with latest issue date is Valid.
    For each unique ID (Col D), If Col L = Yes for the serial number (Col A) with the latest issue date (Col J) return word "Valid"

    Formula 4 - Check latest expiry date for serial numbers belonging to unique ID
    For each unique ID (Col D), If Col C = "Issued" "Renewed" or "Repair" for the serial number (Col A), check:

    If LATEST expiry date (Col K) is within 90+NOW() then return Value "90 Days" or if it is within 30+NOW() then return "30 Days"
    If LATEST expiry date (Col K) is greater than 90+Now() then return value "Valid"
    If LATEST expiry date (Col K) is less than NOW() then return value "Expired"
    Attached Files Attached Files
    Last edited by makaveeti; 04-14-2022 at 05:32 PM.

  2. #2
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Hi,
    1. are you using Office 365?
    2. what does it mean:
    "Unique count of Col A (serial numbers) belonging to a unique ID in Col D where Col L = Yes" ?
    if the ID in column D is not unique then the ID in A should not be included on your list?

  3. #3
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    1. Yes I’m using 365
    2. Column D contains User IDs, Column A contains token serial numbers which belong to a User ID.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    2. Column D contains User IDs, Column A contains token serial numbers which belong to a User ID.
    They're not unique, as far as I can see. The first four entries are two pairs of identical records.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    works as expected except for the first four entries.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Just to be sure I understand your request - please see attached in A27 and down, and advise if these are the results you are expecting for formula 1

    =UNIQUE(FILTER(A2:A25,L2:L25="yes"))
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    TMS - You got it right. Yes the first 4 expected entries are incorrect and should read 1. I'll upload an updated workbook in post 1.

    As far as the thread goes.

    1. Formula 1 - TMS has answered.

    Now I just need the other 3 formulas as stated in the original post.

  7. #7
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    TMS - I forgot to mention that in my real data some of the values in column A are alpha numeric. Will that require a change to the formula?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    I forgot to mention that in my real data some of the values in column A are alpha numeric. Will that require a change to the formula?
    If it works as is, no. If it doesn't, yes. Have you tried it? What part of the formula makes you think it may need to change?

  9. #9
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Yes I just tried it. I added rows 26-29 to the sample data. Column A rows 26-27 contain alphanumeric values. The expected result is 2 but the formula is returning 0.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    The formula works.
    Maybe you didnt update the ranges $A$2:$A$25, $L$2:$L$25, $D$2:$D$25
    change it to 29 instead of 25 .

  11. #11
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Apologies - School boy error.

    Thank you belinda200. I updated the ranges as stated. TMS's formula handles the alphanumeric values too and is working.

  12. #12
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    TMS - I have adapted your formula to answer Formula 2.

    =IFERROR(ROWS(UNIQUE(FILTER($A$2:$A$29, ($D$2:$D$29=$D2)*($L$2:$L$29="Yes")*($K$2:$K$29<90+NOW())))),0)

    I just need Formula 3 and 4 now..

  13. #13
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Formula 3 - Check IF serial number with latest issue date is Valid.
    For each unique ID (Col D), If Col L = Yes for the serial number (Col A) with the latest issue date (Col J) return word "Valid"

    I have this for formula 3 so far. How can it be adapted so that it only checks column L based on the latest date in column J?

    =IF(AND(COUNTIFS($D$2:$D$29,D2,$L$2:$L$29,"Yes")),"Valid","")


    If a unique identifier is required to add to the formula you can use Column A
    Last edited by makaveeti; 04-14-2022 at 05:15 PM.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    To avoid the schoolboy errors, these formulae determine the last row of data based on column D (note that column D has numeric content).

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

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

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by TMS; 04-14-2022 at 06:51 PM.

  15. #15
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Thanks TMS. So these 3 formulas are working fine.

    Formula 3 is giving me the expected results. Can I just clarify though, your post above says 'these formulae determine the last row of data based on column D' - Does your formula do a sort whereby the last row of data in column D happens to be the latest issue date (Col J)? I ask because I see no reference to Col J in the formula.. maybe there is no need to reference Col J?

    When I download the report from the server, Col J is unsorted by default. So that I understand it can you explain the design of it please?
    Last edited by makaveeti; 04-14-2022 at 07:49 PM.

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    The formula has nothing to do with column J. It just uses a very large numeric value to check against the values in column D. It will always be bigger than any value present and will, therefore, return the last row number.

    The formula just needs to refer to a column that is fully populated (no blank entries) with numeric values.


    You can test this using
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Note: that is equivalent to just:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Ok thanks for your reply. To be honest I'm still struggling to understand how it works and how it works by not needing to look at column J. Forgive my lack of knowledge and experience as I not a proficient as yourself with Excel.



    What are your thoughts on Formula number 4?

  19. #19
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    TMS -

    How can I adapt formula 1 to look at multi values for the condition when doing the count?

    At present the formula is:

    =IFERROR(ROWS(UNIQUE(FILTER($A$2:$A$25, ($D$2:$D$25=$D2)*($L$2:$L$25="Yes")))),0)

    I would like to adapt the above in red to check column c instead for the following values "Issued" "Renewed" or "Repair"

    I tried replacing ($L$2:$L$25="Yes") with ($C$2:$C$25={"Issued","Renewed","Repair"}) but that doesn't calculate correctly.

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    See if this gives you what you are expecting:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  21. #21
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

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

  22. #22
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    Thanks TMS - They both work perfect.

    This was the formula I was using previously to do the same job however I imagine both formulas above are a much more efficient and less resource intensive way of doing the count?

    =COUNT(0/FREQUENCY(ROW($1:$50),MATCH($A$2:$A$50,$A$2:$A$50,)*($C$2:$C$50={"Issued","Repair","Renewed"})*($D$2:$D$50=$D2)))-1

  23. #23
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Unique count of values based on corresponding ID and IF statement with similar conditi

    No idea. Doesn't seem slow but I have no tools to measure the speed. I only tend to worry about performance when there is a noticeable delay. Logically, you'd expect new functions to be optimised but I wouldn't stake my life on it.

+ 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. Count unique values if consecutive condition
    By EmanuelMuresan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-13-2020, 01:04 PM
  2. Replies: 2
    Last Post: 07-04-2017, 03:20 PM
  3. [SOLVED] Count Unique Values in a Range with Condition
    By vij8y in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-28-2015, 05:45 AM
  4. count unique values based on 1 condition
    By penfolda in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-05-2014, 10:28 PM
  5. Count unique values based on condition
    By pradeev in forum Excel General
    Replies: 4
    Last Post: 06-12-2012, 10:43 AM
  6. Replies: 2
    Last Post: 01-17-2012, 07:48 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