How to use AI to generate formulas in Baserow

Banner image showing How to use AI to generate formulas in Baserow

Baserow combines the simplicity of a spreadsheet with the power of a database, making it great for organizing and managing data. One of its key features is the ability to use formulas to manipulate data, perform calculations, automate tasks within your tables, and create dynamic fields. Baserow formulas work similarly to Excel or Google Sheets formulas, but are tailored for database-like applications. Here are some common use cases:

  • Calculating totals or differences
  • Concatenating text fields
  • Creating conditional logic

Writing complex formulas can sometimes be challenging, especially if you’re not familiar with Baserow’s formula syntax. This is where AI comes in.

With the integration of AI, you can now automate and enhance your workflows by generating complex formulas effortlessly.

Familiarize yourself with the formula field type and the most commonly used functions. Understanding Baserow’s formula functions can help you craft better prompts for complex calculations.

Why you might need AI to generate formulas

There are a few reasons why using AI to generate formulas might be helpful:

  • Saves time: If you’re not familiar with complex formulas, AI can quickly create them for you, allowing you to focus on analyzing the results.
  • Reduces errors: AI can help avoid mistakes that can happen when writing formulas manually.
  • Expands your capabilities: AI can help you with formulas you might not know how to write yourself, opening up more possibilities for data analysis. Imagine you have a lot of data, and you want to perform a specific calculation on it, but you’re not sure what formula to use. An AI formula generator can help.

Baserow AI frees you up to focus on the big picture. It’s not just about speed, it’s about working strategically.

What we’ll do

In this article, we’ll walk you through how to write prompts that help AI understand your needs and generate accurate formulas. We’ll cover the following steps:

  1. Understand your requirements
  2. Break down the problem
  3. Set up your Baserow database
  4. Write clear and specific prompts
  5. Use advanced formula prompts
  6. Refine and test the prompt

Prerequisites

To complete this tutorial, you’ll need the following:

Let’s dive in!

Use AI to generate formulas in Baserow

AI can assist in generating formulas by understanding natural language instructions and converting them into Baserow’s formula syntax. Here’s how you can effectively use AI for this purpose:

1. Understand your requirements

Before writing prompts, clearly define what you want to achieve with the formula. What problem are you trying to solve? What calculation do you need to make? By identifying the specific problem you’re trying to solve or the calculation you need, you can create precise and effective prompts.

For example, let’s say you want to find the total amount of money made from sales. You’d need to multiply the number of items sold (quantity) by the price of each item (unit price).

2. Break down the problem

Once you know what you want to achieve, it’s helpful to break it down into smaller steps. This makes it easier to write clear and simple formulas that work exactly as you need them to.

Let’s break the example above into smaller pieces like this:

  1. Identify the data: First, you need to identify the fields in your table that contain the quantity and unit price for each item.
  2. Write the formula: Once you know where your data is, you can write a formula that multiplies the quantity field by the unit price field. This will give you the total sales for each item.

3. Set up your Baserow database

Log in to your existing Baserow account or create a new account if you don’t have one already.

Once you log in, you can access the dashboard to add workspaces and databases. You can work with an existing workspace, database, or table, set up a new workspace from scratch, or choose a template from our template library.

Add the necessary tables and fields to the database.

In the table, create the fields that contain the quantity and unit price for each item:

Set up your Baserow database

Now, we’ve successfully identified the data we are working with. Now we can add a formula field in the table and click Generate using AI:

Generate using AI in Baserow

4. Write clear and specific prompts

Choose the AI type and model, then frame your instructions effectively to get the most accurate and useful responses.

When you write instructions for AI, called prompts, be specific about the tasks you want them to complete. Think of a prompt like a clear question or instruction you give to the AI. The better you explain what you want, the better the AI can understand and complete your task.

The trick is to tell the AI what actions to take, using short and clear sentences. Use plain language, just like you would when talking to someone who might not be familiar with technical terms.

For example, instead of:

“Write a formula”

Try:

“Create a calculation that multiplies the number of items sold (Quantity) by their price per item (Unit price) and tells me the total sales amount.”

The second prompt tells the AI exactly what to do, step-by-step.

The clearer your instructions are, the better the AI will understand what you need and the more helpful its response will be. This way, you’ll get the results you’re looking for.

We recommend the use of GPT-4-turbo-preview, as it works best with high-parameter models.

Write clear and specific prompts in Baserow

Once you’ve written the prompt, the AI will use it to build a formula. The formula will be inputted into your formula editor and see if it works the way you want.

Generated formula:

multiply(field('Quantity'), field('Unit price ($)'))

5. Use advanced formula prompts

You can also advanced formula prompts to calculate totals or perform other operations based on fields containing quantity and unit price for each item. For example:

Discount application prompt:

“Design a formula to apply a discount to the total cost, considering the quantity and unit price fields.”

Generated formula:

round(multiply(field('Quantity'), field('Unit price ($)')) * 0.9, 2)

This calculates a discounted price by multiplying the quantity by the unit price, applying a 10% discount, and rounding the result to two decimal places.

Customized pricing prompt:

“Design a formula to implement customized pricing rules based on specific conditions, using the quantity and unit price fields.”

Generated formula:

if(field('Quantity') > 100, multiply(field('Quantity'), field('Unit price ($)') * 0.9), if(field('Quantity') > 50, multiply(field('Quantity'), field('Unit price ($)') * 0.95), multiply(field('Quantity'), field('Unit price ($)'))))

This formula calculates a discounted price based on quantity. If you buy more than 100 items, you get a 10% discount, if you buy more than 50 items you get a 5% discount, and if you buy less than 50 items, you get no discount.

6. Refine and test the prompt

By giving the AI clear prompts, it can automatically create formulas for you. This means less time spent writing formulas yourself, and more time analyzing your data.

If the formula the AI generates isn’t exactly what you need, you can simply refine your instructions to be more specific. For example, you can provide examples of your data to help the AI understand what it’s working with. You can also show the AI what the final results should look like.

By making adjustments and then trying again, you can get the AI to create the perfect formula for your needs.

Summary

Creating formulas in Baserow can sometimes be challenging, especially for those who aren’t familiar with coding or complex spreadsheet functions. You can save time and reduce errors by using AI to generate formulas in Baserow. These formulas can be used to do things like calculations and data analysis in your table.

Ready to try Baserow AI? We’ve explained what it can do, and now it’s your turn to see how it can help you. We’re always looking for ways to improve Baserow with new AI features, so don’t hesitate to share your thoughts and ideas!

Try Baserow AI

Other useful resources

The following articles may also be helpful:

If you need any help with Baserow AI or simply want to showcase how you’re using it, drop us a line in the Baserow community.