Please share a calculation function you’re using that can be useful for others and easy to set up.
We have a calculation field that take the first initial of their first name and the first 3 initials of their last name to create a unique referral tag that gets sent to them via email so that we can track when people come through to complete our forms via their link. Hope that makes sense!
We are starting to use Calculations to translate forms (including the text of each question). See example below:
https://fw401dau.paperform.co/
Really cool form there, Rafael!
to validate personal ID (CPF) and documents of Brazilian companies (CNPJ).
In all cases i use “Phone Number” with custom format. Custom format to CPF is xxx.xxx.xxx-xx and CNPJ is xx.xxx.xxx/xxxx-xx
“a” is the Phone Number formated field.
CPF:
a = {{ 649r8 }};
b = MATCH(ARGS2ARRAY(“111.111.111-11”, “222.222.222-22”, “333.333.333-33”, “444.444.444-44”, “555.555.555-55”, “666.666.666-66”, “777.777.777-77”, “888.888.888-88”, “999.999.999-99”, “000.000.000-00”), a); // returns 2 “333.333.333-33”;
c = (b == 0);
dv1 = SLICE(a, 13,15);
p1a = (SLICE(a, 1, 2) * 10 + SLICE(a, 2, 3) * 9 + SLICE(a, 3, 4) * 8 + SLICE(a, 5, 6) * 7 + SLICE(a, 6, 7) * 6 + SLICE(a, 7, 8) * 5 + SLICE(a, 9, 10) * 4 + SLICE(a, 10, 11) * 3 + SLICE(a, 11, 12) * 2) % 11;
result1 = IF(p1a < 2, 0, 11 - p1a);
p1b = (SLICE(a, 1, 2) * 11 + SLICE(a, 2, 3) * 10 + SLICE(a, 3, 4) * 9 + SLICE(a, 5, 6) * 8 + SLICE(a, 6, 7) * 7 + SLICE(a, 7, 8) * 6 + SLICE(a, 9, 10) * 5 + SLICE(a, 10, 11) * 4 + SLICE(a, 11, 12) * 3 + result1 * 2) % 11;
result2 = IF(p1b < 2, 0, 11 - p1b);
dv2 = result1 || result2;
IF(c == true, IF(dv1 == dv2, “CPF válido”, ERROR(“CPF inválido”)), ERROR(“CPF inválido”)) // IF(dv1 == dv2, “CPF válido”, ERROR(“CPF inválido”))
CPNJ:
a = {{ aa4s9 }};
b = MATCH(ARGS2ARRAY(“11.111.111/1111-11”, “22.222.222/2222-22”, “33.333.333/3333-33”, “44.444.444/4444-44”, “55.555.555/5555-55”, “66.666.666/6666-66”, “77.777.777/7777-77”, “88.888.888/8888-88”, “99.999.999/9999-99”, “00.000.000/0000-00”), a);
c = (b == 0);
dv1 = SLICE(a, 17,19);
p1a = (SLICE(a, 1, 2) * 5 + SLICE(a, 2, 3) * 4 + SLICE(a, 4, 5) * 3 + SLICE(a, 5, 6) * 2 + SLICE(a, 6, 7) * 9 + SLICE(a, 8, 9) * 8 + SLICE(a, 9, 10) * 7 + SLICE(a, 10, 11) * 6 + SLICE(a, 12, 13) * 5 + SLICE(a, 13, 14) * 4 + SLICE(a, 14, 15) * 3 + SLICE(a, 15, 16) * 2) % 11;
result1 = IF(p1a < 2, 0, 11 - p1a);
p1b = (SLICE(a, 1, 2) * 6 + SLICE(a, 2, 3) * 5 + SLICE(a, 4, 5) * 4 + SLICE(a, 5, 6) * 3 + SLICE(a, 6, 7) * 2 + SLICE(a, 8, 9) * 9 + SLICE(a, 9, 10) * 8 + SLICE(a, 10, 11) * 7 + SLICE(a, 12, 13) * 6 + SLICE(a, 13, 14) * 5 + SLICE(a, 14, 15) * 4 + SLICE(a, 15, 16) * 3 + result1 * 2) % 11;
result2 = IF(p1b < 2, 0, 11 - p1b);
dv2 = result1 || result2; // CNPJ
IF(c == true, IF(dv1 == dv2, “CNPJ válido”, ERROR(“CNPJ inválido”)), ERROR(“CNPJ inválido”))
Translate months in dates:
data = DATEFORMAT(NOW(), "DD MMMM YYYY");
dia = DATEFORMAT(NOW(), "DD");
mes = SWITCH(DATEFORMAT(NOW(), "MMMM"),
"January", "Janeiro",
"February", "Fevereiro"
"March", "Março",
"April", "Abril",
"May", "Maio",
"June", "Junho",
"July", "Julho",
"August", "Agosto",
"September", "Setembro",
"October", "Outubro",
"November","Novembro",
"December", "Dezembro"
);
ano = DATEFORMAT(NOW(), "YYYY");
FORMAT("{} de {} de {}", dia, LOWER(mes), ano)