Search code examples
google-sheetsgoogle-sheets-formula

Filter GoogleSheet data based on multiple conditions


I have a GoogleSheet structured as follow :

  • sheet1 contains data from column A to Z.
  • sheet2 is using data from sheet1 (I use arrayformula to import data from the columns that I need + added a few columns to input other data or modify the initial data)
  • sheet3 that would filter data from sheet 2 importing data that only matches one of the 3 following conditions : column R contains a number starting with "6" OR containing exactly "380" OR containing the text "SPENDESK" OR "containing the text "AUTOLIQUIDATION"

I understand that the "filter" function could be a great place to start but it seems that the "query" function is the one I should be using here but I struggle with identifying how I can add multiple conditions especially on the same column while still using it as a way to display all the columns from my reference sheet.

Based on this topic I have tried this so far : =FILTER(sheet2!A2:Z5,(sheet2!R>6)+(sheet2!R)+...) =filter('sheet2'!1:500;'sheet2'!R:R isnumber(search("SPENDESK"));'sheet2'!R:R isnumber(search("AUTOLIQUIDATION")))

Thanks !


Solution

  • QUERY utilizes simple statements, starting with the range you are querying, followed by statements (if any).

    QUERY(Sheet2!A:Z) will simple display all results. However adding conditionals will filter that down.

    QUERY(Sheet2!A:Z, "SELECT * WHERE R STARTS WITH '6' OR R = 380 OR R CONTAINS 'SPENDESK' OR R CONTAINS 'AUTOLIQUIDATION'")

    You can do additional options as desired. Take a look at QUERY.

    Keep note of how your cells are formatted, as if they are text (considering you have numbers and text in column R) then the 380 will need to be wrapped in apostrophes to indicate it is a string not a number '380'.