The TASK_FORMULA function generaties Google Sheets formulas using AI language models. It allows you to describe the formula you need in natural language, and the AI will create an appropriate formula based on all of your spreadsheet data, placing the working formula directly in a specified cell.
=TASK_FORMULA(header, range, cell_address, prompt, [model], [additional_sheets])
Parameter | Data Type | Required | Description |
---|---|---|---|
header | string | No | Column header for the task template. This appears in the first row of the output. |
range | string | Yes | The range in the active sheet to use as context for the formula (e.g., "A1:B10"). |
cell_address | string | Yes | The cell address where the generated formula will be placed (e.g., "C1"). Use "current" to place in the current cell. |
prompt | string | Yes | Instructions describing the formula to generate (e.g., "Create a formula that sums column A."). |
model | string | No | The name of the language model to use in the format 'provider/model_name' (e.g., "Gemini/gemini-1.5-pro"). If not specified, your default model is used. |
additional_sheets | string | No | Additional sheets and their ranges to include as context, separated by semicolons (e.g., "Sheet2(A1:B5);Sheet3"). |
You can specify where the generated formula should be placed using these approaches:
When your formula needs to reference data across multiple sheets:
additional_sheets
parameter to include data from other sheets=TASK_FORMULA("Sum", "A1:A10", "B1", "Create a formula that sums all values in column A.")
=SUM(A1:A10)
.
=TASK_FORMULA("Weighted Average", "A1:B10", "C1", "Create a formula that calculates the weighted average where column A has the values and column B has the weights.", "Gemini/gemini-1.5-pro")
=SUMPRODUCT(A1:A10,B1:B10)/SUM(B1:B10)
.
=TASK_FORMULA("Multi-sheet", "A1:B5", "C1", "Create a formula that sums values from this sheet and Sheet2.", "Anthropic/claude-3-5-sonnet", "Sheet2(A1:A5)")
=SUM(A1:B5) + SUM(Sheet2!A1:A5)
.
=TASK_FORMULA("Conditional", "A1:C10", "D1", "Create a formula that returns 'High' if A1 > 100 and B1 > 50, 'Medium' if A1 > 50, and 'Low' otherwise.")
=IF(AND(A1>100,B1>50),"High",IF(A1>50,"Medium","Low"))
.
Cause: The function output was modified manually or corrupted.
Solution: Recreate the function with =TASK_FORMULA().
Cause: The prompt parameter is empty or not provided.
Solution: Ensure you include a clear prompt describing the formula you need.
Cause: The JSON has been modified and no longer contains "TASK_FORMULA" as the function name.
Solution: Recreate the function with =TASK_FORMULA().
Cause: The specified range doesn't exist or is in incorrect format.
Solution: Check that your range uses valid A1 notation (e.g., "A1:B10").
Cause: An additional sheet referenced doesn't exist in the spreadsheet.
Solution: Verify that all sheet names in additional_sheets parameter exist and are spelled correctly.
Cause: The language model misunderstood the requirements or created a syntax error.
Solution: Try a more specific prompt or manually adjust the generated formula.
Cause: The function wasn't executed with the Run button or there was a processing error.
Solution: Select the cell with TASK_FORMULA and click Run in the Sheet Workflows sidebar.
After entering the TASK_FORMULA function in a cell, select that cell and click the "Run" button in the Sheet Workflows sidebar. The function itself only creates the task definition; you must click Run to generate and apply the formula.
Yes, TASK_FORMULA can generate array formulas if your prompt specifies this need. The AI will add the necessary ARRAYFORMULA() wrapper when appropriate.
Yes, when executed, the formula will be placed in the target cell, replacing any existing content. Be careful when choosing the target cell.
Yes, use the additional_sheets parameter to include data from other sheets in the context provided to the AI. Format as "Sheet2(A1:B5);Sheet3" to include specific ranges.
Most language models (Claude, GPT-4, Gemini, etc.) can generate formulas. More capable models like "Anthropic/claude-3-5-sonnet" or "OpenAI/gpt-4" tend to produce more complex and accurate formulas.
No, TASK_FORMULA generates standard Google Sheets formulas only. It cannot create custom JavaScript functions.
After the formula is generated, you can edit it directly in the target cell just like any other formula. The AI-generated formula is just a starting point.
The function generates one formula at a time. To apply similar formulas to multiple cells, either copy the generated formula or create multiple TASK_FORMULA calls targeting different cells.
The complexity depends on the AI model used and how well you describe your needs. More advanced models can create very complex nested formulas with multiple functions and conditions.
Make sure your range and cell_address parameters are correct. If you want to use relative references in the generated formula, mention this in your prompt.
1 week ago