Home > Blockchain >  Sort function in Query in Google Sheets
Sort function in Query in Google Sheets

Time:09-01

In google sheets, I want to sort a query function based on the date in my data. The date is in column V. I replaced my function with "Select Q, R, S, T, U, V, W where 1=1 ORDER BY V asc"

to

=QUERY(Q2:Y,"SELECT Q, R, S, T, U, V, W WHERE 1=1 "&IF(A3="All Destinations", ""," AND LOWER(R) = LOWER('"&A3&"') ")&IF(B3="All Items", ""," AND LOWER (S) = LOWER('"&B3&"') ")&IF(C3="All Dates", ""," AND V >= DATE '"&TEXT(C3,"YYY-MM-DD")&"' "),1)

Data is being displayed on the drop-downs based on A3,B3,C3.

I want the data from the query function to organize the data by the date. What can I add to this? Is my syntax incorrect? Apologize in advance if this is an easy solution, I'm new to Google Sheets.

Thank you, kindly.

CodePudding user response:

use:

=QUERY(Q2:Y, 
 "select Q,R,S,T,U,V,W 
  where 1=1 "&
 IF(A3="All Destinations",," and lower(R) = '"&LOWER(A3)&"'")&
 IF(B3="All Items",," and lower(S) = '"&LOWER(B3)&"'")&
 IF(C3="All Dates",," and V >= date '"&TEXT(C3, "YYYY-MM-DD")&"'
  order by V"), 1)

enter image description here

  • Related