Help

Formula for counting number of attachments

4759 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Kenston
4 - Data Explorer
4 - Data Explorer

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 4

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)

Thanks for the catch!

Thomas_de_Beauc
6 - Interface Innovator
6 - Interface Innovator

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