google-apps-scriptgoogle-sheets-formula

How can I automatically form a new google sheet from an old one which I need to filter and to modify one column of?


I have a google sheet with large list of current and former people in one of my music groups, and I want to form an automatically updated sheet from it for the member website to show only the current members and only the phone numbers which are not bracketed to indicate privacy. I also want to reorder the columns (put instrument column first) and sort them by instrument, last name and first name.

Here is a sample of what the original data looks like: https://docs.google.com/spreadsheets/d/1jzBPxUMkRIhvGAqEJO4O57vx0D_rl_ZO7LgM5R9mhAs/edit?usp=sharing

and here is what I would want to have automatically generated for the members to see in the member website: https://docs.google.com/spreadsheets/d/1f1VT07pOOshSndBR4TO9ekq6N2Q2dRE6B64e6QE6koI/edit?usp=sharing

I can easily filter for the current members, with something like this:

=query(importrange("1jzBPxUMkRIhvGAqEJO4O57vx0D_rl_ZO7LgM5R9mhAs","A:I"),"Select Col5,Col2,Col3,Col4,Col6,Col7,Col8,Col9 WHERE Col1='y' ORDER BY Col5,Col6 DESC,Col2,Col3",1) 

but I have been unsuccessful at hiding the bracketed phone numbers in an automatically updated sheet. I tried both REGEXEPLACE and the IF statement.

Here is one attempt at using the IF statement. It generates a "Formula parse error":

=query(importrange("1jzBPxUMkRIhvGAqEJO4O57vx0D_rl_ZO7LgM5R9mhAs",ArrayFormula({A:F,if(G:G CONTAINS "(","",G),H:H})),"Select Col5,Col2,Col3,Col4,Col6,Col7,Col8,Col9 WHERE Col1='y' ORDER BY Col5,Col6 DESC,Col2,Col3",1)

My REGEXREPLACE attempts, for example,

=query(importrange("1jzBPxUMkRIhvGAqEJO4O57vx0D_rl_ZO7LgM5R9mhAs",{A:G, ARRAYFORMULA(REGEXREPLACE(H:I, ".*[(].*", ""))}),"Select Col5,Col2,Col3,Col6,Col7,Col8,Col9 WHERE Col1='y' ORDER BY Col5",1)

all generated circular dependency errors...

Can anybody tell me how to fix these attempts to get what I want? Maybe a macro or an app? Again I want what is viewable on the member website to be automatically updated from the bigger sheet which contains some information (both full rows and occasionally some columns for which the rest of the row is visible) that the members will not see. I'm hoping that this is possible!


Solution

  • only the phone numbers which are not bracketed to indicate privacy

    Use an array formula, like this:

    =let( 
      data, query( 
        importrange("1jzBPxUMkRIhvGAqEJO4O57vx0D_rl_ZO7LgM5R9mhAs", "A1:I"), 
        "select Col5, Col2, Col3, Col4, Col6, Col7, Col8, Col9 
         where Col1 = 'y' 
         order by Col5, Col6 desc, Col2, Col3", 
        1 
      ), 
      arrayformula(regexreplace(to_text(data), "\([^)]*\)", "")) 
    )
    

    The regex deletes text that is between parentheses, including the brackets.

    See arrayformula(), to_text() and regexreplace().