How to use the AI Function in Google Sheets (with 10 examples)

The AI Function in Google Sheets brings the power of Gemini AI directly into your cells.

It uses Gemini’s large language models (LLMs) to process the text prompts and return helpful responses. It’s akin to using a prompt in the chat window of Gemini, but with the convenience of being accessible in your Sheet.

And it’s as easy to use as any other formula!

Who has access to the AI Function?

The AI Function is available to people on the following Google Workspace plans:

  • Business Standard and Plus
  • Enterprise Standard and Plus
  • Customers with the Gemini Education or Gemini Education Premium add-on
  • Google AI Pro and Ultra

Anyone who previously purchased these legacy add-ons will also have access to the AI function:

  • Gemini Business
  • Gemini Enterprise

Additionally, it’s available to users enrolled in the Google Workspace Labs program.

☠️ Note: If you don’t have access to the function, you can achieve any of these results by copy-pasting data into Gemini (or ChatGPT or Claude) and running the prompt there. And then you can paste the results back into your Sheet. Obviously, it’s not as convenient!

How to use the AI Function

The AI function is simple to use and has the following form:

=AI( "prompt" , [optional range] )

It takes two arguments:

  1. the prompt, which is a description of the action you want the function to perform, enclosed in double quotes, and
  2. an optional range, which is a reference to a single cell or range containing information that provides extra context to the AI function.

The AI function is most useful for working with text. There are four broad actions that it can perform:

  • Sentiment analysis
  • Summarizing text
  • Categorizing text
  • Generating text

Example 1: Sentiment Analysis with the AI Function

AI function to perform sentiment analysis in Google Sheets

Suppose you manage an AirBnb and you have a Google Sheet containing reviews. You can use the AI function to analyze the sentiment of these reviews to identify positive and negative reviews.

Use this prompt:

Categorize sentiment as positive, negative, or neutral

inside the AI function as follows:

=AI( "Categorize sentiment as positive, negative, or neutral" , D6 )

where the cell D6 contains the review.

Alternatively, we can include the reference to cell D6 directly in the prompt argument by concatenation:

=AI( "Categorize sentiment of the review in " & D6 & "as positive, negative, or neutral" )

In this case, we don’t specify the option range argument.

Perhaps the only benefit of this second approach is that it lets you reference non-contiguous ranges, i.e. multiple cells in different parts of your Sheet.

For example, this text generation AI formula references cells in column B and D (i.e. non-adjacent), which wouldn’t be possible with a single range argument:

Using cell references inside the AI function

But if you are using a single cell or range, it’s easier to include it as the second argument of the AI function.

Example 2: Sentiment Analysis as a Rating Chip

An alternative way to show sentiment analysis is to ask the AI function to output a rating between 1 and 5 and then format the cells as Rating chips.

Rating chips based on AI formula

The AI formula is:

=AI( "Rate the feedback in this review between 1 and 5, with 1 being the worst score and 5 being the best score" , D6 )

This gives an output between 1 and 5 (technically, 0 to 5 would also work).

Then highlight the cells with the rating numbers and change them to Rating chips via the menu:

Insert > Smart chips > Rating

Alternatively, if your data is in a Table, you can change the column type to a Rating chip under the column menu:

Edit column type > Smart chips > Rating

Example 3: Summarize Text

Summarize text with the AI Function

With the review text in cell D6, we can use this formula to summarize the text:

=AI( "write a summary of the user's feedback in under 10 words" , D6 )

Example 4: Categorize Text

Categorize text with the AI Function

Suppose we have a list of products that we need to categorize into groups. It’s a hugely time consuming task.

The AI function can dramatically speed that process up.

With the data in column B, we can use a formula like this to categorize the products:

=AI( "categorize the product into one of these consumer electronics categories: Audio,Home Entertainment,Mobile Device,Wearable,Home Appliance,Gaming,Smart Home,Computing,Photography,Kitchen Appliance,Drones,Mobile Accessory" , B7 )

Example 5: Generate Text

Generate marketing copy in Google Sheets with AI formulas

In this example, we use the AI formula to generate marketing copy for products on Instagram. We tell Gemini to add emojis and hashtags in the output.

Note also that because the product name is in column B and the key features are in column D, we need to insert the references into the prompt:

=AI( "Generate a short less than 20-word description for instagram for this product " & B6 & " with these features " & D6 & ". Make it funny, and include emojis and add relevant hashtags" )

This just inserts the value from cells B6 and D6 into the text string prompt before the AI formula runs it.

Example 6: Generate Email Drafts

Generate email drafts with AI functions

We use a longer, ultra-specific prompt to ensure the emails are formatted exactly as we want them.

And the formula references data in the range B6 to G6 (i.e. the whole Table row) for context:

=AI( "Write a professional email to the parent or guardian of this student, summarizing their academic performance and classroom behavior.
The email should be written from me, Ben Collins. I am their teacher.
Start each email with a subject line formatted exactly as:
Subject: Name of Student’s Progress Repor
For example: Subject: John Smith’s Progress Report.
The tone should be warm, supportive, and informative—highlight both strengths and areas for improvement.
Avoid overly technical language, and keep the email clear and easy to understand.",B6:G6)

​This is part of a YouTube tutorial on turning Google Sheets data into Gmail drafts, with the AI Function and Apps Script.

Example 7: Explaining Formulas

At the time of writing (August 2025), the AI function cannot be nested inside other functions, or vice versa.

To combine it with other functions, we have to create helper columns that output intermediate steps.

So before we can explain that complex formula in cell A1, we have to use the FORMULATEXT function to turn it into text:

Formulatext function in Google Sheets

The formula is:

=FORMULATEXT(A1)

Then we can use the AI function to explain that text version of the formula:

Explain formulas with the AI function in Google Sheets

The AI formula is:

=AI("explain what this formula does and how it works",C1)

Example 8: Categorize Stock Tickers

We can use the AI function to categorize stock tickers into industry categories:

Categorize stock tickers with the AI function in Google Sheets

The formula is:

=AI("show me the sector of the stock with this ticker", stockTickers[Ticker])

where the stock tickers are in a Table called “stockTickers”.

Example 9: Parse Addresses to Extract Data

The AI function is a huge help at parsing messy addresses and extracting the component parts:

Parse addresses with the AI function in Google Sheets

The formulas for these columns are:

=AI("show me the street address only from this address",A2)
=AI("show me the town only from this address",A2)
=AI("show me the postcode only from this address",A2)

Example 10: Unpivot Data

For a final example, here it is helping to UNPIVOT data, which is turning wide data into tall data format. It’s notoriously difficult to do with regular formulas.

However, if you can handle complex formulas, the old-school, deterministic method is still more convenient since we can’t nest the AI function inside other functions yet.

But for reference, here’s how we can create an AI formula to unpivot data.

First, we unpivot data with AI:

Unpivot data with the AI function in Google Sheets

The formula is:

=AI("can you unpivot the data",A1:E4)

Then we use regular functions to parse into rows:

Unpivot data with the AI function in Google Sheets

The formula is:

=ArrayFormula(SPLIT(TRANSPOSE(SPLIT(G1,CHAR(10))),"|"))

What the AI Function CANNOT do

1) it cannot perform calculations like regular functions. If you try, you’ll get an error message:

AI Function cannot do calculations.

With all the hype around AI at the moment, it’s tempting to apply it to everything we do.

So it’s good to step back and ask yourself if you really need an AI function. Most spreadsheets tasks that involve data will still be in the domain of regular, deterministic functions, like SUM, AVERAGE, FILTER, etc.

So don’t fall into the trap of trying to apply AI to everything!

2) it cannot be nested inside other functions.

If you try to nest the AI function, for example inside an IF function as shown here, you’ll get an error message:

AI Function error

3) the AI function has limits to how much it can generate in a 24-hour window. If you hit the limit, you won’t be able to click the “Generate” button until 24 hours has passed.

4) if you select multiple cells with AI functions and click to generate outputs, only the first 200 cells will be generated. Once the first batch of 200 is complete, you can generate the next batch of 200 cells, and onwards.

5) if you access Sheets through other cloud storage providers (e.g. Dropbox, Box, etc.) then you can’t generate content with the AI function.

6) The AI function cannot generate other functions, pivot tables, or charts.

AI Function Template

Download the Complete Guide to the AI Function Template

Click on “Use Template” in the top right corner to make your own copy.

There is no Apps Script with this template.

Additional prompt examples in the Google documentation.

11 Incredibly Useful URL Tricks for Google Sheets

Did you know that by changing the URL of a Google Sheet we can change how it behaves?

In this post, we look at 11 incredibly useful URL Tricks for Google Sheets.

For example, we can create a URL that automatically downloads the Sheet as a PDF. Or create a template ready for copying. And much more.

URL Tricks for Google Sheets

Take a look at any Google Sheets URL in the address bar of your browser.

It will take the following form:

https://docs.google.com/spreadsheets/d/ + file ID + / extension

We can change the /extension at the end of the URL to ensure a different action happens when a user uses that URL.

Feel free to click on any of the links below to see how they work. They are all linked to the following template, which you can copy for your own reference (bonus points if you use the correct URL trick to do that).

URL Tricks for Google Sheets

1. Standard Sharing Link Format

This is the default sharing link for Google Sheets. Users with appropriate permissions can view or edit the sheet.

  • Advantages: Provides direct access to the Sheet with full functionality.
  • Limitations: If set to “Anyone with the link can edit,” any users can make changes.
  • Best For: Team collaboration when you want users to view or edit the Sheet.

Extension Format:
/edit?usp=sharing

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/edit?usp=sharing

2. Preview

Opens the spreadsheet in a read-only format without showing the editing toolbar.

  • Advantages: Cleaner presentation without distractions from menus and tools.
  • Limitations: Users cannot edit or copy directly from this view.
  • Best For: Great for sharing data in a presentation format when you don’t want users to make edits.

Extension Format:
/preview

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/preview​

3. HTML View

Converts the sheet into a basic HTML page.

  • Advantages: Loads faster and is accessible without needing Google Sheets’ interface.
  • Limitations: Some formatting and interactive features may not function properly.
  • Best For: Useful for reports since it eliminates sheet controls but allows you to still navigate between tabs.

Extension Format:
/htmlview

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/htmlview

4. Template

Opens a “Use Template” preview, allowing users to see and create their own copy of the file.

  • Advantages: Prevents accidental changes to the original document while ensuring consistency across copies.
  • Limitations: Users must have permission to access the original file.
  • Best For: Ideal for distributing Google Sheets to wider audiences so they can create their own copies.

Extension Format:
/template/preview

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/template/preview​

5. Make a Copy

Prompts users to create their own editable copy of the spreadsheet.

  • Advantages: Ensures the original file remains unchanged and user makes a copy.
  • Limitations: Requires users to be signed into Google to create a copy.
  • Best For: Useful for ensuring users make a copy of a Google Sheet.

Extension Format:
/copy

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/copy​

6. Export as a PDF

Generates a downloadable PDF version of the spreadsheet.

  • Advantages: PDF format ensures consistency across devices and prevents edits.
  • Limitations: Not interactive, not all features will display correctly; updates to the sheet require generating a new PDF.
  • Best For: Perfect for distributing static reports, tables, invoices, or finalized documents.

Extension Format:
/export?format=pdf

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/export?format=pdf​

7. Export as a CSV

Provides a downloadable CSV version of the sheet, exporting only the active tab.

  • Advantages: Downloads your data in a universal format compatible with most data processing tools.
  • Limitations: Loses formatting, formulas, interactive elements, and multiple sheet structures.
  • Best For: Great for exporting data tables for analysis in other software, such as databases or coding environments.

Extension Format:
/export?format=csv

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/export?format=csv​

8. Export as an Excel Document

Downloads the spreadsheet as an Excel (.xlsx) file.

  • Advantages: Retains formulas, formatting, and multiple sheets.
  • Limitations: Some Google Sheets-specific features (like QUERY function or Google Apps Script) may not work in Excel.
  • Best For: Best for sharing Sheets with users who prefer or require Excel.

Extension Format:
/export?format=xlsx

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/export?format=xlsx​

9. Distraction Free Editor

Opens the sheet in a minimalistic mode with no toolbars or menus.

  • Advantages: Reduces clutter and distractions for focused editing.
  • Limitations: Some editing options may not be accessible.
  • Best For: Useful for presenting data cleanly or working in a distraction-free environment.

Extension Format:
/view?rm=minimal

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/view?rm=minimal​

(Because I shared a view-only copy, you won’t be able to do any editing. Share with editor rights if you want to use this feature.)

10. Basic Controls Editor

Opens the sheet in a limited interface with only essential tools.

  • Advantages: Allows basic editing without overwhelming users.
  • Limitations: Lacks full editing capabilities.
  • Best For: Ideal for users who need to make small modifications but don’t require full spreadsheet features.

Extension Format:
/view?rm=demo

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/view?rm=demo​

11. Embed in Iframe

Embeds the spreadsheet in a webpage without extra Google Sheets UI elements.

  • Advantages: Provides a seamless way to display live data in a website or online dashboard.
  • Limitations: Users cannot interact fully unless given editing access.
  • Best For: Great for embedding spreadsheets in blogs, dashboards, or reports where live data needs to be displayed.

Extension Format:
/view?rm=embedded

Example link:
https://docs.google.com/spreadsheets/d/1h8kgPdJx8myJP_C_8WRfs4x6Uqqg2E7s5YdTpJDbcUM/view?rm=embedded​

Can AI Studio teach me how to build a pivot table?

January 2025

Hardly a week passes at the moment without some technology announcement that makes me go “wow!”.

This week it’s Google’s AI Studio that has been impressing me, offering a glimpse into what the future of software education could look like.

What’s different with this tool is that it lets you share your screen and have a verbal conversation with the AI model (in this case Gemini), so it can walk you through a problem.

In my case, I used it to walk me through building a pivot table. And whilst it didn’t get everything correct (yet!), it’s impressive and feels like you’re talking to an assistant, not your computer.

How to use AI Studio to teach you

  • Go to https://aistudio.google.com/
  • Sign in with your Google account. It’s free to use. When you log in, the homepage looks like this:
Google AI Studio homepage
  • Click on the “Stream Realtime” in the left menu (shown by the red arrow).
  • Share your screen and have a conversation with AI Studio! For example, you could say:

    “I want you to walk me through building a pivot table that summarizes the total sales price by property type.”

    (And say it out loud, don’t type it in.)
  • Because the Pivot Table once existed under the data menu, AI Studio initially guided me there first (the only serious mistake it made). I said “I don’t see the pivot table option under the data menu, is it under one of the other menus?”

    So, don’t hesitate to interject if you can see it making a mistake.
  • Once you have a basic pivot table, you could ask for help sorting the data or adding another category.
  • Another great use case is asking it to explain lines of code to you. For example, share your screen showing a code block and try something like this “can you explain what the code on lines 52 – 56 does?”

It’s early days, so it’s far from perfect. It does make mistakes so you can’t rely on it blindly. You still need to cultivate your own knowledge.

But it’s a glimpse into what’s around the corner when we have infinitely patient AI assistants at our beck and call. And I think that’s a bright future, where we can be dramatically more efficient, focused on insights and outcomes, not code syntax or formula issues.

What do you think?

Multiple Selections in Drop Downs in Google Sheets

The drop down menu feature in Google Sheets is useful for efficient data entry. It can also be used to create dynamic spreadsheets, for example, dashboards that change based on choices a user makes.

At the end of July 2024, Google announced multiple selections in drop downs (scheduled to roll out in late-August/early-September). This is great news that will give us even more flexibility in our spreadsheets.

In this post, we’re going to take a look at this new drop down feature:

Multiple Dropdowns in Google Sheets

How to Enable Multiple Selections in Drop Downs

To enable multiple selections, create a regular dropdown and then check the box that says “Allow multiple selections”:

Allow Multiple Selections in Google Sheets dropdown

Boom! 💥 That’s it.

Working with Drop Down Multiple Selections in Formulas

If you select multiple options from a drop down menu, the output is a comma separated list:

Multiple Selections in Drop Downs in Google Sheets

To work with them in formulas, we use the SPLIT function to separate the choices into their separate parts.

Note the space after the comma. We need to be mindful of this in our formulas. Split out the comma-separated lists with this formula, which accounts for the space too:

=SPLIT(B2,", ",FALSE)

It looks like this in our Sheet:

Split formula for multiple Dropdowns

We can use a BYROW function to expand this SPLIT formula to work with a range of multi dropdowns. This single formula in cell C2 splits out all the cells in the range B2:B6 and outputs all the data in C2:E6 range:

=BYROW(B2:B6,LAMBDA(r,SPLIT(r,", ",FALSE)))

In our Sheet:

BYROW and SPLIT with multiple dropdowns

Finally, we could wrap this with a TOCOL function and a QUERY function to count our choices:

=QUERY(TOCOL(BYROW(B2:B6,LAMBDA(r,SPLIT(r,", ",FALSE)))),
"select Col1, count(Col1) where Col1<>'' group by Col1 order by count(Col1) desc label Col1 'Option', count(Col1) 'Count'",0)

In our Sheet:

Multiple Selections in Drop Downs with QUERY

GETPIVOTDATA Function in Google Sheets: How To Extract Data From Pivot Tables

The GETPIVOTDATA function is used to extract data from a pivot table.

Pivot tables are one of the most powerful and useful features in spreadsheets. We use them to summarize our data, by grouping, sorting and filtering it.

But pivot tables are dynamic elements. That means they can change size and shape when data is added or removed from the underlying dataset (e.g. when a new category is added). This makes it tricky to extract data consistently.

When a pivot table changes size, a regular cell reference (e.g. A12 or F34) might not point to the correct value in the pivot table anymore. However, the GETPIVOTDATA function will still extract the correct data.

The downside of GETPIVOTDATA is that it’s fiendishly difficult to use. It’s something of a dark art to identify the correct rows and columns inside the function.

In this post, we’re going to learn how this function works.

👇 Feel free to grab the template from the bottom of this article to follow along.
Continue reading GETPIVOTDATA Function in Google Sheets: How To Extract Data From Pivot Tables