+ Reply to Thread
Results 1 to 7 of 7

Select only the first N instances of a value in a table

  1. #1
    Registered User
    Join Date
    04-26-2024
    Location
    Portland, OR
    MS-Off Ver
    Microsoft 365 Apps for Business v. 2403
    Posts
    2

    Select only the first N instances of a value in a table

    I feel like there are a hundred simple solutions to my problem but I can not come up with any!! I have a table full of patients and their Primary Care Providers. Some providers have 100 patients, some only have 30. I want to be able to select only the first 30 patients for each provider and make a new table.

    One solution I thought of was to create a column that numbers the patients from 1 to N and then starts over when it gets to a new provider. For example, if I could go from image one (no index column) to image 2 (index column that starts over when it gets to a new provider), I would be home free. However, I can't figure out how to make an index column that resets to one when it gets to a new provider.

    I would greatly appreciate any help on this. Like I said, there are probably many ways to get this done, but I've been thinking about it for weeks and searching forums, talking to AI, and I can't get a solution!

    UPDATE: Replaced screenshots with .xlsx.
    Attached Files Attached Files
    Last edited by mark3824; 04-26-2024 at 05:55 PM.

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

    Re: Select only the first N instances of a value in a table

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    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


  3. #3
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,769

    Re: Select only the first N instances of a value in a table

    how about
    =COUNTIF($B$2:B2,B2)


    but there maybe better ways to pull out your 30 clients
    however, here is the index number you requested

    how about a sample file with the 30 sample you want to extract and expected results... in case it can all be done with 1 formula and NO helper

    I replied based on the images , i see now you have sample file - which is much better (for future , its always worth adding in manually the expected results)


    now images have been removed

    anyway - I have also added to your spreadsheet with the formula suggested and my sample
    =COUNTIF($B$2:B2,B2)
    Attached Files Attached Files
    Last edited by etaf; 04-26-2024 at 06:00 PM.
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  4. #4
    Registered User
    Join Date
    04-26-2024
    Location
    Portland, OR
    MS-Off Ver
    Microsoft 365 Apps for Business v. 2403
    Posts
    2

    Re: Select only the first N instances of a value in a table

    My hero! You're probably right there's a more elegant way to export my top 30, but this at least gets me there with much less brute force than previously required. Really appreciate the help!!!!

  5. #5
    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,530

    Re: Select only the first N instances of a value in a table

    In cell C2, copied down
    Formula: copy to clipboard
    Please Login or Register  to view this content.


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


    Adjust the variable mc from 4 (for testing) to 30, or whatever.

  6. #6
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,769

    Re: Select only the first N instances of a value in a table

    you are welcome - TMS - has also shown how to filter that list - and as i say maybe a way to do in just one filter formula without the helper - But its late for me now - and going to be offline for a week - so unlikely to get back to this

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,936

    Re: Select only the first N instances of a value in a table

    And yet one more way with Power Query

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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: 0
    Last Post: 04-27-2021, 11:10 AM
  2. VLookup 2 instances in a table with 2 instances horizontal and vertical
    By vivek.budhram in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-08-2019, 11:47 AM
  3. Replies: 4
    Last Post: 04-14-2018, 09:54 AM
  4. select multiple text instances to conditionally format a row
    By CHRISCOUCK in forum Outlook Formatting & Functions
    Replies: 8
    Last Post: 08-14-2015, 07:25 AM
  5. Replies: 1
    Last Post: 02-12-2013, 06:02 PM
  6. Replies: 3
    Last Post: 07-18-2012, 11:53 AM
  7. Extracting/look up data from a list and select multiple instances
    By Candice H. in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-29-2005, 12:06 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