Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jul 09, 2017 04:39 AM
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?
Jul 19, 2017 11:38 AM
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_ID
s. 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).
Jul 22, 2017 03:41 AM
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)
Jul 23, 2017 02:14 AM
Thanks for the catch!
Aug 03, 2022 11:13 AM
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