Skip to main content

Formula for counting number of attachments

  • July 9, 2017
  • 4 replies
  • 149 views

Forum|alt.badge.img+1

I have a column of Attachment type. I want to create a formula based on the number of uploaded/attached files. How can I count the number of uploaded/attached files in that column?

4 replies

Forum|alt.badge.img+5
  • Inspiring
  • 1386 replies
  • July 19, 2017

This is a clever trick suggested by @Simon_Brown: Given an Attachment field {Attached}, the formula to count the number of attachments is

IF(
LEN({Attached}=0,0,
LEN({Attached})-LEN(SUBSTITUTE({Attached},",",""))+1)

This works because Airtable casts {Attached} as a comma-separated string of concatenated RECORD_IDs. The formula then compares the length of the string with the length of the same string with commas removed (plus 1, to make sure single attachments get counted).


Forum|alt.badge.img+1
  • Author
  • New Participant
  • 1 reply
  • July 22, 2017

This is a clever trick suggested by @Simon_Brown: Given an Attachment field {Attached}, the formula to count the number of attachments is

IF(
LEN({Attached}=0,0,
LEN({Attached})-LEN(SUBSTITUTE({Attached},",",""))+1)

This works because Airtable casts {Attached} as a comma-separated string of concatenated RECORD_IDs. The formula then compares the length of the string with the length of the same string with commas removed (plus 1, to make sure single attachments get counted).


This workaround works! Thanks!

Just a little of syntax typo (missing closing parenthesis for first LEN):

IF(
LEN({Attached})=0,0,
LEN({Attached})-LEN(SUBSTITUTE({Attached},",",""))+1)

Forum|alt.badge.img+5
  • Inspiring
  • 1386 replies
  • July 23, 2017

This workaround works! Thanks!

Just a little of syntax typo (missing closing parenthesis for first LEN):

IF(
LEN({Attached})=0,0,
LEN({Attached})-LEN(SUBSTITUTE({Attached},",",""))+1)

Thanks for the catch!


Forum|alt.badge.img+8
  • Participating Frequently
  • 14 replies
  • August 3, 2022

This formula gives wrong results when attachments have commas in the filename, here is one that doesn’t have this issue !

IF(Attachments = BLANK(), 0, (LEN(Attachments) - LEN(SUBSTITUTE(Attachments, "https://dl.airtable.com/.attachments/", ""))) / LEN("https://dl.airtable.com/.attachments/"))

Airtable nicely adds the download address to the comma-separated list of attachments of the Formula field, and "https://dl.airtable.com/.attachments/" is indeed much less likely to occur than innocent commas in a filename.

Credit and reference : Count multiple keywords in text - #3 by Karlstens