Home > Blockchain >  Apply an IF logic within a QUERY
Apply an IF logic within a QUERY

Time:10-07

Thanks in advance. I have an issue with pulling data using a QUERY within google sheets. I need to pull data from two different columns depending on which column has a later date.

I have been able to pull through the correct values within an IF formula:

""=ARRAYFORMULA(IF(Database!P12:P>Database!AH12:AH,Database!P12:P,Database!AH12:AH))""

However, I need to select specific rows of data based on this QUERY:

""=QUERY(Database!C12:AM,"SELECT P WHERE AC CONTAINS 'PRICE | Time-limited save' AND AG = date '"&text(Database!N2,"yyyy-MM-dd")&"' and lower(Y) contains 'approved'")""

I need to select data from column P unless column AH has a later date.

Thanks

CodePudding user response:

Try

=QUERY({Database!Y12:Y,Database!AC12:AC,Database!AG12:AG,ARRAYFORMULA(IF(Database!P12:P>Database!AH12:AH,Database!P12:P,Database!AH12:AH))},"SELECT Col4 WHERE Col2 CONTAINS 'PRICE | Time-limited save' AND Col3 = date'"&text(Database!N2,"yyyy-MM-dd")&"' and lower(Col1) contains 'approved' ",1)
  • Related