Skip to main content

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?

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 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)

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!


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


Reply