Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-formulagoogle-query-language

Query Multiple Columns with using "Where" and "AND"


I have multiple sheets in data google sheet, let's both named is sheet 1 and sheet 2. In sheet 1, I have three columns as below:

enter image description here

And in sheet 2, I have three columns in below:

enter image description here

If I want to filter sheet 1 based column ID Primary, example the ID Primary is 54f94c2f. If i paste the ID Primary to column ID Primary (sheet 2), then on sheet 2 it will output the column as follows:

enter image description here

I have created formula for column 2 of sheet 2 (B2) and it is worked. The formula is:

=QUERY('Sheet1'!A:C; "SELECT C WHERE A = '"&A2&"'"; 0)

And the only for column 3 of sheet 3 (C2) is not worked. The formula is:

=QUERY('Sheet1'!A:C; "SELECT C WHERE A = '"&A2&"' AND C <> '"&B2&"'"; 0)

The question is how the formula on Cell C2, column 3 of sheet 3 fix it?


Solution

  • Try this to populate all unique dates(for a ID Primary):

    =torow(unique(filter(Sheet1!C:C,Sheet1!A:A=E2)),1)
    
    • Change the above formula ranges to fit your sheet design accordingly
    • use array_constrain() & restrict to just 2 dates if that's how you need it or so!

    enter image description here