Skip to content
Kuovonne's Guide to Airtable
  • Pages
    • Kuovonne's Guide to Airtable
      • Fields
        • Overview of fields types
          • Editable Field Types
          • Computed Field Types
          • Field Types by Formula Data Type
          • Field Types in Scripting
        • Specific field types
          • Formula fields
            • Demystifying Formulas (DareTable 2022)
          • Rollup fields
          • Select fields
          • Attachment fields
            • Uploading Attachments
            • Attachment Size
            • Attachment URLS
            • Thumbnails
        • Converting Field Types
        • Naming fields
        • Metadata fields
          • Simple Metadata Fields
          • Data Validation
          • Additional Dependencies
          • Original Record URL (Thumbprint) Field
          • Column Divider Fields
          • DareTable 2023 Presentation
        • Field dependencies
      • Formulas
        • Formula Field Reference
        • Writing Formulas
          • Using AI to Write Formulas
          • General tips for writing formulas
          • Testing for Blank Values
          • Drafting Formulas in Parts
          • Function versus Operator
          • Typing Special Characters
          • Commenting Formulas
          • Formulas to avoid
        • Formatting Formulas
          • Basic Rules
          • Nested IF formulas
          • SWITCH Formulas
          • Operators
        • Specific Formulas
          • Ranges of Numbers Values
          • Comma Separated List of Fields Values with Optional Fields
          • Earliest / latest date across columns
          • List Fields Values (one per line) with Optional Fields
          • Rounding a date to the half year
          • Url of Interface Page for a record
          • Removing varying items from a list
        • Data Type Conversion in Formulas
          • Text to Numbers
          • Numbers to Text
          • Data type conversions with Dates
        • Troubleshooting Formulas
          • Formulas that won't save
          • Hiding or showing #ERROR!
          • Troubleshooting date/time/duration formulas
          • Troubleshooting numeric formulas
          • Troubleshooting formulas with lookups
          • Troubleshooting text formulas
      • Automations
        • Triggering automations
          • Triggering automations for typed values
          • Triggering automations on existing records
        • Sending Emails
          • Ways to send emails
          • Using links in emails
          • Emailing Attachments
        • Accessing updated record values
        • Third party automations
        • Managing automation runs
      • Templates
        • Templates for record values
        • Templates using field values
      • Controlling Access
        • Sharing a base
        • Access control considerations
        • Techniques for limited access
          • Airtable interface
          • Share link access
          • Synced table
          • Prefilled forms + Automations
          • 3rd party portal
          • 3rd party webhook
        • Preventing base duplication
      • Specific Solutions
        • Most recent form submission for ermail
        • Email digest of a person’s records
        • Sum of Multiple Select choices
        • Link to multiple records based on select choices
        • Dropping Lowest Score (top 4 of 5)
        • Identify the position of a record in a linked record field (top 4 of 6)
        • Sequential Numbering of Records
        • Ending a list of rollup items with ", and"
        • Table ID in a formula
        • Latest/earliest date across several fields
        • Associating People with Records
        • First Tuesday of the Previous Month
      • Miscellaneous
        • Web API Calls for External Integrations
        • Getting paid to work with Airtable
        • Hiring a consultant
        • Airtable Communities
        • Making major changes to a base
      • Suggestion for this guide

Ending a list of rollup items with ", and"

Thank Kuovonne for creating this content!

Inspiration

When rolling up items in linked records, it is very common to combine linked items into a comma separated list. However, if you are including the list in a larger paragraph, you may want to include the word and before the last item in the list.
If there is only one item in the list, there should be no comma and no and.
If there are two items in the list, there should be no commas, and the two items should be joined with the word and.
If there are three or more items in the list, there should be a comma after every item, except between the last two items, where there should be the word and.
image.png
If you are a fan of the Oxford comma, you may want a comma before the and, but that formula is more complex and not covered here.

Building a comma separated list

Start by creating a comma separated list of linked values using a rollup field with a simple formula function:
ARRAYJOIN(values, ", ")
ok
Make sure you are using a rollup field, not a lookup field. The commas you see in a lookup field do not really exist.

Failings of traditional text functions

The next step is to remove the last comma and replace it with the word and. Trying to do this with regular text functions like FIND(), SEARCH(), REPLACE(), or SUBSTITUTE() is difficult because ...
you need to look from the end of the text string, not the start
you need to leave any commas before the last one in place
there could be any number of commas

Using RegEx (regular expression)

Regular expressions are very good at the type of search and replace we need.

Identifying the last item in a new formula field

Let’s start by creating a new formula field using REGEX_MATCH() to find the last item.
Each item in the list is composed of one or more characters that are not commas. Use the ^ control character in front of a comma , to indicate any character that is not a comma. Place this combination inside square brackets []. Then use the + control character to indicates one or more matches.
REGEX_MATCH(
{Comma Separated Rollup Field},
"[^,]+"
)
As is, this regular expression will give us the first item in the list. In order to get the last item in the list, use the $ control character to indicate that our item must be followed by the end of the line.
REGEX_MATCH(
{Comma Separated Rollup Field},
"[^,]+$"
)
Include the preceding comma and space in the pattern.
REGEX_MATCH(
{Comma Separated Rollup Field},
", [^,]+$"
)

Performing the replacement

Because we want to replace text, not just find it, swap out REGEX_MATCH() with REGEX_REPLACE(). Start with a placeholder empty text string for the replacement value.
REGEX_REPLACE(
{Comma Separated Rollup Field},
", [^,]+$",
""
)
Because we want to replace only the comma and space, and not the last item, use grouping parenthesis () to indicate these two different groups of characters.
REGEX_REPLACE(
{Comma Separated Rollup Field},
"(, )([^,]+)$",
""
)
Now we move to the replacement text string. Let’s start by using $2 to keep the the second group in the matched text, which is the last item in the list. We can ignore the first capture group $1 because we don’t want that comma.
REGEX_REPLACE(
{Comma Separated Rollup Field},
"(, )([^,]+)$",
"$2"
)
We also want to include the word and with spaces around it before the last item in the list.
REGEX_REPLACE(
{Comma Separated Rollup Field},
"(, )([^,]+)$",
" and $2"
)

Combining the helper formula with the initial rollup formula

REGEX_REPLACE(
ARRAYJOIN(values, ", "),
"(, )([^,]+)$",
" and $2"
)
Thank Kuovonne for creating this content!

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.