Formulas

Adding a formula column

  1. Head on over to the Add Column "+" button

  2. Select Formula from the menu and watch the setup column pop up

3. Insert fields to your column. Below the formula box, you'll see a list of the columns in your table. Drag or double click on any fields to insert them into your formula.

Types of formulas

Operators. Run simple calculations likea + b, a * b, a / b, a != b

Functions. Run more complex formulas by adding some custom code (see more below)

Primitives. Run formulas combining different types of data

  • Numbers: 5, 42, -1, 3.14, etc.

  • Strings: "foo", 'Clay', they need to be in " or '

  • Booleans: true, false

  • Lists: [ "do", "ray", "me" ]

Javascript operators we support:

  • +, - (in their unary and binary forms, i.e. 5-3 and -3 or +3)

  • ~ - bitwise negation

  • ! - logical negation

  • *, / - multiplication, division

  • ||, && - logical OR, logical AND

  • |, &, ^ - bitwise OR, bitwise AND, bitwise XOR

  • = - equality test

  • != - inequality test

  • <, >, <=, >= - comparison operators

  • <<, >> - bit shift operators

  • % - modulo

Add some code

Clay formulas can support:

  • Lodash_ will refer to lodash, so _.chunk( [ 10, 20, 30, 40 ], 2 ) will result in [ [ 10, 20 ], [ 30, 40 ] ]

  • Lambda functions → the syntax for lambda function is: (arg1, arg2, ...) => { expression }. The extra {} are necessary. The above is equal to Javascript's (arg1, arg2, ...)=> expression and (arg1, arg2, ...)=> { return expression }.

  • Javascript Object functions → Eg. strings do have .length property, and methods like .split() or .substring(). Arrays have .length, .concat, .indexOf, .map, .filter etc.