0

I'm trying to create another formula for my project.

I'm using VLOOKUP to search for a variable, and return values related to that variable on a single Cell.

Here is what I'm working With

Sheet A

A         |       B
Users       Total Number
User 1           
User 2
User 3           1,2,4,7
Sheet B

A         |       B
Users       Total Number
User 1           2
User 2           4
User 3           1
User 3           2
User 3           4
User 3           7

I want to collect the numbers that are related per User on a single cell. Here's my current formula used:

=ARRAYFORMULA({"Client Payments"; JOIN(",", VLOOKUP(B2, 'Package Payments'!B2:E, 2, FALSE))})

I thought this code would reiterate itself and produce the result on Sheet A, User 3's Row. Also, I want to avoid using query as I want to repeat the code all-throughout the sheet.

Any recommendations are welcomed.

2 Answers 2

0

Use filter(), like this:

=textjoin( ", ", true, filter('Package Payments'!C$2:C, 'Package Payments'!B$2:B = B2) )

Alternatively, try this pattern to get a multi-column table that shows all numbers for all usernames:

=filter( 
  query( 
    { 
      'Package Payments'!B2:C, 
      countifs('Package Payments'!B2:B, 'Package Payments'!B2:B, row('Package Payments'!B2:B), "<=" & row('Package Payments'!B2:B)) 
    }, 
    "select Col1, max(Col2) 
     where Col1 is not null 
     group by Col1 
     pivot Col3", 
    0 
  ), 
  sequence(counta(unique('Package Payments'!B2:B)) + 1) > 1 
)

To place those results in your sample spreadsheet, looking results up by client name, put this formula in cell 'Package Clients'!J1:

=arrayformula( 
  { 
    "Package Payments"; 
    transpose( 
      query( 
        transpose( 
          iferror( 
            vlookup( 
              B2:B, 
              filter( 
                query( 
                  { 
                    'Package Payments'!B2:C, 
                    countifs('Package Payments'!B2:B, 'Package Payments'!B2:B, row('Package Payments'!B2:B), "<=" & row('Package Payments'!B2:B)) 
                  }, 
                  "select Col1, max(Col2) 
                   where Col1 is not null 
                   group by Col1 
                   pivot Col3", 
                  0 
               ), 
                sequence(counta(unique('Package Payments'!B2:B)) + 1) > 1 
              ), 
              sequence(1, 99, 2), 
              false 
            )  
          ) 
        ), 
        "", 
        9^9  
      ) 
    ) 
  } 
)
4
  • Hi there! I tried the first code you sent: — =textjoin( ", ", true, filter('Package Payments'!C$2:C, 'Package Payments'!B$2:B = B2) ) — It works, but it's only fetching values from a single user. I tried extending the search for the variable by using : 'Package Payments'!B$2:B = B2:B However, it is not working, it is only displaying one value. I want it to display values related to the proeperty. I appreciate you giving the alternative formula. However, I wanted to collate the results to a single row.
    – revilio.
    Feb 26, 2022 at 7:58
  • The second formula gets all the results for a username in the same row. If that is not what you wanted, consider sharing a publicly editable sample spreadsheet with realistic-looking data, and showing your hand-entered expected results there. Feb 26, 2022 at 9:08
  • Hi Bud! Thanks, here's a link for the Google Sheet File: docs.google.com/spreadsheets/d/… If you'll check on the Package Payment Tab. There are two columns there labelled. Package Payments, and Client Payments. I want Package Payments to have the same Result as Client Payments.
    – revilio.
    Feb 28, 2022 at 0:08
  • Edited the answer. Your sample spreadsheet has more than 30,000 blank rows on most tabs. Delete those superfluous blank rows before applying the array formula. Feb 28, 2022 at 6:58
0

Here is my proposed solution: enter image description here

Formula Used (Improved - to include open range as well):

=ArrayFormula({UNIQUE(FILTER(A1:A,A1:A<>"")),transpose(regexreplace(trim(query(transpose(REGEXEXTRACT(query(A1:A&"~"&B1:B,,3^6),REGEXREPLACE(query(A1:A&"~"&B1:B,,3^6),"("&UNIQUE(FILTER(A1:A,A1:A<>""))&"~)(\d+)","$1($2)"))),,4^6))," ",","))})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.