HomeGoogle DocsSpreadsheetHow to Use To_text Function in Google Sheets

How to Use To_text Function in Google Sheets [Also the Use in Query]

Published on

I will tell you how useful is To_text function in Google Sheets. Once I landed in a problem in importing data from one of my Google Sheets. That time I realized how useful the To_text function is. What was that problem?

I wanted to import one column from one of my sheets. But the column had dates entered in text format, date format, time values, text string and lots of blank rows in between. I want to import only the rows that contain values.

The solution was using the To_text function with Query and Importrange. Let me begin with the basic tips on how to use To_text function in Google Sheets.

Usage of To_text Function in Google Sheets

In Excel or Google Sheets, you can put an apostrophe (‘) in front of a number or date or any value to make it text without losing its format. The To_text function does the same.

The syntax of Google Sheets To_text Function:

TO_TEXT(value)

Example:

to_text in Google Sheets Usage

See how the To_text formulas in C13, C14…C17 converted to date, currency, time and numbers to text while retaining the format.

You can use Google Sheets To_text function in Array Formula too. In such cases try the formula similar to the one below. Why should one go with numerous formulas when To_text supports array?

=ArrayFormula(to_text(A13:A17))

Use of Google Sheets To_text Function in Query

You must learn the use of To_text in Query as it may be very useful while consolidating rows or importing rows.

The use of Regex in Query Match clause is the best way to filter specific values in a column. But many users are not well conversed in the use of Regex in Query Match Clause.

Similar: Google Sheets Query to Filter Numbers Only From Mixed Data Column

See one example where I’m going to use the To_text function in Query.

To_text in Query

In column A I’ve mixed type of data. So when I use Query, it may put me in a puzzle! It’s like what to put in the “Where” clause to filter only the rows that contain values.

So what I’ve done is, first converted values in column A to text and then used the<>'' operator in the “Where” clause which is “not equal to space” that applicable in filtering text values.

But don’t forget to use the Array Formula while using the To_text function in an Array.

Similarly, You can use the To_Text function in Importrange to import a column with mixed content data.

Use of To_text in Importrange in Google Sheets

Here just refer to the above formula. You only need to change the range A1: A reference within the Importrange formula.

=ArrayFormula(query(to_text(IMPORTRANGE("Blah.. Blah..Blah..","Sheet1!A1:A")),"Select Col1 where Col1<>''"))

Conclusion

In situations like the above, you will realize that all the functions in Google Sheets are there for some purpose. Hope you’ve enjoyed the stay!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across both Excel and Google...

Sum Values by Month and Category in Excel

With the help of EOMONTH, UNIQUE, and SUMIFS functions in Excel, you can efficiently...

Sum Values by Categories in Excel

In Excel, the easiest way to sum values in a range by categories is...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

2 COMMENTS

  1. Do have example for IMPORTHTML using ArrayFormula(Query(to-text?

    I have IMPORTHTML that returns a table where a column in the table is of mixed data-type. My problem starts when I need to use the Query function. Hope you can help.

    • Hi, SooGuan Tan,

      To solve the mixed data type issue in Query, we can use the To_Text function. Since your data is imported using the IMPORTHTML, you may need to extract the particular column contain mixed data using Query or Index that within the Query ‘data’.

      If you share your imported table, I can identify the column and accordingly modify the Query ‘data’.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.