Feb 03, 2018 10:33 AM
I’ve tried searching the forums, and while I’ve found posts similar to this, I haven’t quite found the formula that works for me.
I have a Job Number that is based off 3 other fields that I want to automatically generate when the other fields are filled manually.
Example
Job #: 72234-0001-001
Order #: 72234
Line Item: 1
Revision Level: 1
The order number typically does not need zeroes, but the line item fields and rev fields do, the zeros also need to adjust in the event there is lets say 10 line items, the center number still needs to be a 4 digits.
This seems doable, but I haven’t found the correct formula to do this. If anyone knows how to pull this off, thank you ahead of time!!
Feb 03, 2018 06:55 PM
IF(LEN({Line Item})=1, “000”&{Line Item}, IF(LEN({Line Item})=2, “00”& {Line Item}, IF(LEN({Line Item})=3, 0&{Line Item}, {Line Item})))
IF(LEN({Revision Level})=1, “000”&{Revision Level}, IF(LEN({Revision Level})=2, “00”& {Revision Level}, {Revision Level}))
Feb 05, 2018 09:40 AM
The rev level part didn’t work for some reason no matter how hard I tried, but the first IF statement worked great! Thank you so much Sam :slightly_smiling_face:
Feb 14, 2018 06:40 PM
Is there a PAD function in airtable? I’m looking for a similar solution to an ID number.
Thanks,
Erica
Feb 15, 2018 04:30 AM
AFAIK, you can’t force a field to a certain length by default. But there is a simpler formula that doesn’t require any IFs:
RIGHT("0000"&{Line Item},4)
RIGHT("000"&{Revision Level},3)
Note: Make sure the prepended string is at least the length of the desired final result, otherwise it’ll throw an error if the value field you want to pad is empty.
If you’re curious, the definition of the function is:
RIGHT(string, howMany)
Extract howMany characters from the end of the string.
Feb 15, 2018 08:17 AM
Thanks so much Andy! That solved my problem perfectly and I’ll be using that formula in Client IDs, invoice numbers and several other places.
Erica
May 23, 2018 01:29 PM
Thanks Andy. That’s a great solution :slightly_smiling_face:
Works in my slightly overcomplicated Client ID formula:
UPPER(LEFT(SUBSTITUTE({Customer Name}, " ", “”),4)) & RIGHT(“000”&{ID},3)
May 23, 2018 03:48 PM
To left-pad {Number}
with enough zeroes to make a string {Digit}
digits long, use
REPT('0',{Digit}-LEN({Number}&''))&{Number}
(’LEN({Number}&'')
’ returns the length of {Number}
cast as a string.)