0

I'm using this formula: =QUERY(A1:M;"SELECT D")

COLUMN D contains rows with numbers and others with text strings, but the QUERY is only returning the numbers and the text strings are showing as blanks.

I need both data types returned.

0

2 Answers 2

0

I believe your format may need to be changed.

Try this: =query(table!A1:M, "select D")

This is assuming that "table" is the name of the sheet with data.

If table is a named range, then you either need to use that or A1:M as query only accepts a single range to search.

3
  • Welcome to Web Applications SE. The question has some problems. While the formula in this answer fixes some, this does not answer the core of the question. Look at How to Answer for the essential guidance about how to answer here. By the way, Google Sheets, as well as other spreadsheet apps, might use commas or semicolons as the function parameter separator, but not all users are aware of this, so if you will be using a separator different than the one used on the question, please mention it. Commented Oct 6, 2023 at 15:35
  • OP's own formula is working because they are getting numbers returned but not text. Google Sheets uses ; instead of , in many EU locales to separate arguments. This is why you see that difference. The inclusion of "Table" may be a poorly chosen way of highlighting the data source to us by the OP or something else (typo?) but doesn't seem related to the core problem.
    – Blindspots
    Commented Oct 6, 2023 at 20:05
  • It looks like the OP edited the post. The suggestion I offered wasn't actually about the "," or the ";" The original formula the presented had the parenthesis in the wrong place and no "!" in the data source. I believe what they posted was =(query(table A1:M); "SELECT D")
    – Ryan Hunt
    Commented Oct 7, 2023 at 17:13
0

FILTER & LEN

=FILTER(D:D; LEN(D:D)) 

Explanation

  • FILTER column D where the value has a LEN (character length) greater than zero
  • FILTER allows more flexibility because it doesn't change the data types.

QUERY w/ ARRAYFORMULA

=ARRAYFORMULA(
   QUERY(TO_TEXT(D:D)))

# equivalent formula
=QUERY(
   ARRAYFORMULA(TO_TEXT(D:D)))

Explanation

  • The QUERY function recognizes only a single data type per column.
  • If there are multiple data types (eg. text and numbers) only one will be recognized.
  • The solution uses TO_TEXT to change all numbers to text strings in an ARRAYFORMULA.
  • This approach (unlike FILTER) runs the risk of problems if results are used in future calculations.

QUERY w/ ARRAYFORMULA, LET, IFERROR

=ARRAYFORMULA(
   LET(q, QUERY(TO_TEXT(D:D)),
       IFERROR(1/(1/q),q)))

Explanation

  • The LET function stores the result of the QUERY w/ ARRAYFORMULA formula in the named variable q
  • When performing math on a text string Sheets will "try" to interpret it as a number and this is used to try to coerce the text strings in q to numbers.
  • Dividing 1 by the inverse of a non-zero number n will return n. If n is anything other than a non-zero number, Sheets returns an error.
  • In this way within the ARRAYFORMULA all q that can be are coerced to non-zero numbers.
  • IFERROR returns the original text string from q if q couldn't be coerced to a non-zero number and instead triggered an error.

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