+ Reply to Thread
Results 1 to 9 of 9

Generate next IDs based on existing list

  1. #1
    Forum Contributor
    Join Date
    09-15-2022
    Location
    Marseille, France
    MS-Off Ver
    O365 (PC) V 2303
    Posts
    265

    Generate next IDs based on existing list

    Hello guys:

    I have a list of models which consists of a code (alphabetical) and an ID (which start from 100), hyphen-separated.

    I need to calculate the immediate next ID to assign by code following this rule:
    - if the model exists, the first ID which is missing in the sequence starting at 100, incremented by 1 (if there are existing models with 100,101,103, then 102 is missing, so 102 shall be returned)
    - if the model does not exist, shall return 100

    There are duplicates models which is normal. We need a formula we can drag down.

    Any ideas? Thanks.

    generate next id.jpg
    Attached Files Attached Files

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

    Re: Generate next IDs based on existing list

    Try:

    =LET(A,$C$5:$C$41,B,RIGHT(FILTER(A,(A<>"")*(LEFT(A,LEN(F4))=F4)),3)+0,C,ISNA(MATCH(SEQUENCE(100,,100),B,0))*SEQUENCE(100),IFERROR(100+MIN(FILTER(C,C>0))-1,100))

    now to try to make the ugly look prettier...
    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.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

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

    Re: Generate next IDs based on existing list

    V2...

    and a Q.

    =IFERROR(BYROW(F4:F7,LAMBDA(x,LET(A,C4:C100,B,SEQUENCE(100),C,ISNA(MATCH(99+B,RIGHT(FILTER(A,(A<>"")*(LEFT(A,LEN(x))=x)),3)+0,0))*B,100+MIN(FILTER(C,C>0))-1))),100)

    Is there an anticipated MAXIMUM length for the numerical portion? >999 for example??
    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 2403
    Posts
    43,984

    Re: Generate next IDs based on existing list

    V3, works for serial numbers up to 9999


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


    Adjust the bits in RED to suit, the 10000 if more than 9999 numbers are needed.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,899

    Re: Generate next IDs based on existing list

    Or try this:

    =AGGREGATE(15,6,(SEQUENCE(900)+99)/(COUNTIF($C$4:$C$22,F4&"-"&(SEQUENCE(900)+99))=0),1)

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Generate next IDs based on existing list

    option with Power Query

    Result
    Ag-100
    Ag-101
    Ag-102
    Ag-103
    Ag-104
    An-100
    An-101
    An-102
    MWc-100
    ZrO-100
    ZrO-101
    ZrO-102
    ZrO-103
    ZrO-104
    ZrO-105
    ZrO-106
    ZrO-107
    ZrO-108
    ZrO-109
    ZrO-110
    ZrO-111
    ZrO-112
    ZrO-113
    ZrO-114
    ZrO-115
    ZrO-116
    ZrO-117
    ZrO-118
    ZrO-119
    ZrO-120

  7. #7
    Forum Contributor
    Join Date
    09-15-2022
    Location
    Marseille, France
    MS-Off Ver
    O365 (PC) V 2303
    Posts
    265

    Re: Generate next IDs based on existing list

    Thank you guys. I will look into the details of your proposals within the next hours.

    @Glenn - there is theoretically no max, although technically 999 should be enough. I understand this parameter has to be manually adjusted.

    Question, just while viewing the formula without playing with it yet - it is not possible to generate a "dynamic" SEQUENCE? If your LET filter the table by the requested "model", you would know the length of your array (5 rows for example) and thus generate the genuine appropriate sequence for 5 serial numbers ( {100;101;102;103;104} and returning the first one missing - instead of pulling 10,000 serial numbers - the issue with the MAX being lifted - does this make sense or am I wrong?
    Last edited by guillaume0314; 02-03-2023 at 07:16 AM.

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

    Re: Generate next IDs based on existing list

    Yes and no. It's possible... but muddling around working out, code by code, the maximum value used... will be slower than generating a simple sequence.

  9. #9
    Forum Contributor
    Join Date
    09-15-2022
    Location
    Marseille, France
    MS-Off Ver
    O365 (PC) V 2303
    Posts
    265

    Re: Generate next IDs based on existing list

    Thank you guys it works.

+ 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] Generate list based on multiple criteria - list active projects by engineer
    By eamono in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-18-2022, 05:54 PM
  2. Replies: 5
    Last Post: 05-30-2018, 08:34 AM
  3. [SOLVED] Trying to generate randomized list of tweets based on existing data set
    By v_subramanyan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-16-2014, 11:04 PM
  4. Auto-Generate List from reference cells based on data validation list selection
    By BoundCustomDesign in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-13-2014, 11:06 AM
  5. Replies: 0
    Last Post: 02-12-2014, 08:22 AM
  6. Replies: 2
    Last Post: 03-01-2013, 02:01 AM
  7. Generate Product Pick List and transfer to Existing Workbook
    By aaron.meza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2011, 03:38 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