1

I'm getting a '#Value!' error when I try to sort data returned by a QUERY statement. This is the basic statement:
=query('Raw Data'!A:G,"Select A, C, D, sum(G) where B='instagram' and (D='Female Followers Age' or D='Male Followers Age') and A <> '#N/A' group by D, C, A label A 'Handle', C 'Country', D 'Segment', sum(G) 'Share'",0)

Adding an ORDER BY statement to the end of it to sort on column A generates a #Value! error. I saw some responses on forums suggesting column numbers should be used in place of letters with the order by clause. However, I have tried replacing order by A with order by 1, but it generates the same error.

=query('Raw Data'!A:G,"Select A, C, D, sum(G) where B='instagram' and (D='Female Followers Age' or D='Male Followers Age') and A <> '#N/A' group by D, C, A label A 'Handle', C 'Country', D 'Segment', sum(G) 'Share' order by A",0)

1 Answer 1

2

In a query statement, the clauses must be given in the order specified in the query language help page. The order by clause must come after group by and before label, like this:

=query( 
  'Raw Data'!A:G, 
  "select A, C, D, sum(G) 
   where B = 'instagram' 
   and (D = 'Female Followers Age' or D = 'Male Followers Age') 
   and A <> '#N/A' 
   group by D, C, A 
   order by A 
   label A 'Handle', C 'Country', D 'Segment', sum(G) 'Share' ", 
  0 
)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.