Consulting

Results 1 to 7 of 7

Thread: FILTER and extract a column

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,854
    Location

    FILTER and extract a column

    I'm still trying to learn Tables and some of the new 365 functions

    I have FILTER sort of sorted out, but I want to pull selected column(s) from the FILTERed range into another dynamic range

    Attached is sample table, the results of FILTER based on entered value (Green), and a column number entered (Yellow)

    I'd like to just a dynamic array in the Blue

    Capture.JPG

    Thanks
    Attached Files Attached Files
    Last edited by Aussiebear; 04-15-2025 at 12:13 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,959
    Headers (S1):
    =CHOOSECOLS(Table1[#Headers],1,H2)

    databody (S2):
    =FILTER(CHOOSECOLS(Table1,1,H2),Table1[AAA]=G2,"No "&G2)

    and in one (V1):
    =LET(ColmAFltr,G2,ColmNo,H2,VSTACK(CHOOSECOLS(Table1[#Headers],1,ColmNo),FILTER(CHOOSECOLS(Table1,1,ColmNo),Table1[AAA]=ColmAFltr,"No "& ColmAFltr)))

    full lambda (not needed but for development) (Y1):
    =LAMBDA(ColmAFltr,ColmNo,VSTACK(CHOOSECOLS(Table1[#Headers],1,ColmNo),FILTER(CHOOSECOLS(Table1,1,ColmNo),Table1[AAA]=ColmAFltr,"No "& ColmAFltr)))(G2,H2)

    Put the red part as a name into Name Manager leaving you with (AB1):
    =MyNewTable(G2,H2)
    Attached Files Attached Files
    Last edited by p45cal; 04-15-2025 at 12:53 PM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,453
    Location
    This is challenging Paul. Would the following concept do the job?
    =FILTER(Table1, INDEX(Table1, 0, H2) = G2)
    Sorry but unable to correct the formula. "0" should be the greek symbol theta (Zero with a slash across it.) The intent is to create the filter criteria. It compares the values in the selected column (determined by H2) with the value in G2. Only rows where this comparison is TRUE are included in the filtered result.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,854
    Location
    @p45cal

    1. Thanks

    2. This part I can grasp fairly easily since I look at your other postings (at least a little)

    =FILTER(CHOOSECOLS(Table1,1,H2),Table1[AAA]=$G$2,"No "&G2)
    Capture.JPG

    3. The LAMBDA I only understand at a conceptual level, and I have a personal aversion to very long formulas since I can never get the ('s and )'s and ['s and ]'s right

    4. Not important but I noticed that if there was not a match, the LAMBDA formulas failed ugly

    'Capture1.JPG

    5. Thanks again
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,453
    Location
    Then you might not like this one either.....
    =LET(ColmAFltr,G2, ColmNo,H2, FilterCol, INDEX(Table1[#Headers], 1, 1), FilterColData, INDEX(Table1, 0, 1), FilterCol2, _
    INDEX(Table1[#Headers], 1, ColmNo), FilterCol2Data, INDEX(Table1, 0, ColmNo),  VSTACK(CHOOSECOLS(Table1[#Headers], 1, ColmNo), _
    FILTER(CHOOSECOLS(Table1, 1, ColmNo), FilterColData = ColmAFltr, "No " & ColmAFltr)))
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,854
    Location
    I LOVE it

    Now I don't have to count sheep at night

    I can just count parens and brackets until .... Z-Z-Z-z-z-z
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,959
    Quote Originally Posted by Paul_Hossler View Post
    4. Not important but I noticed that if there was not a match, the LAMBDA formulas failed ugly
    Yes, I wasn't going to clutter things up even more by including IFERRORs and such like sprinkled liberally here and there.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •