Files
nocodb/packages/noco-docs/versioned_docs/version-0.109.7/030.setup-and-usages/090.formulas.md
Pranav C 33ee9bfa62 feat: Improved UI (#6222)
* feat: Improved ui (#6156)

* refactor: revert

Signed-off-by: Pranav C <pranavxc@gmail.com>

feat: shared base

Signed-off-by: Pranav C <pranavxc@gmail.com>

fix: remove duplicate import statement

Signed-off-by: Pranav C <pranavxc@gmail.com>

fix: disable starred & license menu

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: fix airtable wait issue

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: enable mysql in ci

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: fix checkbox order for sqlite

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: disable quick tests

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: fix dbType env variable for CI

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: workspace API access error fix

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: enable SQLite CI CD

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: use DB_TYPE env variable

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: enable SQLite UT

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: isHub cleanup

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: add check for EE Timezone spec

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

chore: cleanup

Signed-off-by: Pranav C <pranavxc@gmail.com>

chore: cleanup

Signed-off-by: Pranav C <pranavxc@gmail.com>

test: EE check fix

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

chore: test correction

Signed-off-by: Pranav C <pranavxc@gmail.com>

chore: sync latest changes

Signed-off-by: Pranav C <pranavxc@gmail.com>

test: set EE=false

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

test: set NC Edition to community in workflow file

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

chore: update sdk build command

Signed-off-by: Pranav C <pranavxc@gmail.com>

refactor: i18n and other changes

Signed-off-by: Pranav C <pranavxc@gmail.com>

feat: new ui

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: sync tests

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: lint

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: shared view/base related bugs

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: checkbox verification sort order fix

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: fix sqlite reset

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: enable selfhosted runners

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* docs: table ops (draft)

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* Docs: screenshots for table-operations.md

* refactor: introduce missing buttons

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: get all fields

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: UT fix- new data API response

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: EE is false

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: webhook lookup as string in CE

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* fix: include created_at and updated_at

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: fix UT newDataAPI response for PG

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* fix: separate api for webhook related plugins

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: msyql filter corrections

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: mysql group by test corrections

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: fix datatype for rating field in groupby spec for pg

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: kanban datatype correction

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: column edit for mysql- rating field

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: misc fixes

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: enable 4 workers

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: enable 2 workers per shard only

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* docs: table CRUD

* Rename table-operations.md to table-crud.md

* Create column-crud.md

* docs: row CRUD

* Rename row.md to row-crud.md

* docs: project crud

* docs: toolbar (skeleton)

* refactor: single page UI and bug fixes

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: sync tests playwright

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: add missing dependency

Signed-off-by: Pranav C <pranavxc@gmail.com>

* feat: single page ui, test corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: tests

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: project rename test correction

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: remove only

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: remove wrong import statement

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: delete option not visible in project context menu

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: move ws access within isEE()

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: fix groupby

* test: groupby fix

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* docs: signup & landing page

* docs: project crud

* docs: project-crud misc

* docs: toolbar fields

* docs: toolbar / filters

* docs: toolbar / group by

* docs: toolbar / sort

* docs: toolbar / row height

* docs: filters additional options

* docs: file re-order

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* docs: add links to column types

* docs: code snippets

* docs: links

* docs: lookup

* docs: rollup

* docs: formula

* docs: primary key

* docs: display value

* docs: development setup

* docs: swagger

* fix(nc-gui): encodeURIComponent for row id

- closes: #6202

* docs: language

* docs: expanded record

* docs: import airtable

* docs: airtable

* docs: webhook

* docs: revert file rename

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* docs: account settings

* docs: audit

* docs: meta management

* docs: project settings

* docs: shared base

* docs: shared view

* docs: meta sync

* docs: team-auth

* docs: views

* docs: fix URL

* docs: URL corrections

* fix:  shared base, view related bugs

Signed-off-by: Pranav C <pranavxc@gmail.com>

* test: EE check for WSaccess

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* test: exclude EE tests

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>

* fix: missing project delete

closes #6215

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: merge existing project meta  if found

closes #6216

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: merge existing project meta  if found

closes #6216

Signed-off-by: Pranav C <pranavxc@gmail.com>

---------

Signed-off-by: Pranav C <pranavxc@gmail.com>
Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
Co-authored-by: Raju Udava <86527202+dstala@users.noreply.github.com>
Co-authored-by: DarkPhoenix2704 <anbarasun123@gmail.com>
Co-authored-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* refactor: docs and other bug fixes

Signed-off-by: Pranav C <pranavxc@gmail.com>

* feat: populate default project on super admin signup

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: include created project details in signup response if avail, missing Dockerfile

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: use custom function for resolving ts path aliases

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: add missing generate script

Signed-off-by: Pranav C <pranavxc@gmail.com>

* chore: webpack build correction - ts path resolve

Signed-off-by: Pranav C <pranavxc@gmail.com>

---------

Signed-off-by: Pranav C <pranavxc@gmail.com>
Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
Co-authored-by: mertmit <mertmit99@gmail.com>
Co-authored-by: Raju Udava <86527202+dstala@users.noreply.github.com>
Co-authored-by: DarkPhoenix2704 <anbarasun123@gmail.com>
Co-authored-by: Wing-Kam Wong <wingkwong.code@gmail.com>
2023-08-24 02:58:19 +05:30

11 KiB

title, description
title description
Formulas NocoDB Formulas Syntaxes and Functions

Adding formula column

image

1. Click on '+' (Add column)

2. Populate column Name

3. Select column Type as 'Formula'

4. Insert required formula

  • You can use explicit numerical values/ strings as needed, e.g. 123 (numeric) or "123" (string).
  • You can reference column names in equation with {}, e.g. {column_name}, if the column name conflicts with literals
  • Table below lists supported formula & associated syntax
  • Nested formula (formula equation referring to another formula column) is supported

5. Click on 'Save'

Editing formula column

Unlike other column types, formula cells cannot be modified by double-clicking since the value is generated based on the formula. Instead, the vaule can be changed by updating the formula in the column setting.

image

Available Formula Features

Numeric Functions

Name Syntax Sample Output
ABS ABS(value) ABS({Column}) Absolute value of the input parameter
ADD ADD(value1,[value2,...]) ADD({Column1}, {Column2}) Sum of input parameters
AVG AVG(value1,[value2,...]) AVG({Column1}, {Column2}) Average of input parameters
CEILING CEILING(value) CEILING({Column}) Rounded next largest integer value of input parameter
EXP EXP(value) EXP({Column}) Exponential value of input parameter (e^x)
FLOOR FLOOR(value) FLOOR({Column}) Rounded largest integer less than or equal to input parameter
INT INT(value) INT({Column}) Integer value of input parameter
LOG LOG([base], value) LOG(10, {Column}) Logarithm of input parameter to the base (default = e) specified
MAX MAX(value1,[value2,...]) MAX({Column1}, {Column2}, {Column3}) Maximum value amongst input parameters
MIN MIN(value1,[value2,...]) MIN({Column1}, {Column2}, {Column3}) Minimum value amongst input parameters
MOD MOD(value1, value2) MOD({Column}, 2) Remainder after integer division of input parameters
POWER POWER(base, exponent) POWER({Column}, 3) base to the exponent power, as in base ^ exponent
ROUND ROUND(value, precision) ROUND({Column}, 3) Round input value to decimal place specified by precision (Nearest integer if precision not provided)
SQRT SQRT(value) SQRT({Column}) Square root of the input parameter

Numeric Operators

Operator Sample Description
+ {Column1} + {Column2} + 2 Addition of numeric values
- {Column1} - {Column2} Subtraction of numeric values
* {Column1} * {Column2} Multiplication of numeric values
/ {Column1} / {Column2} Division of numeric values

:::tip

To change the order of arithmetic operation, you can use round bracket parantheses ().
Example: ({Column1} + ({Column2} * {Column3}) / (3 - Column4 ))

:::

String Functions

Name Syntax Sample Output
CONCAT CONCAT(str1, [str2,...]) CONCAT({Column1}, ' ', {Column2}) Concatenated string of input parameters
LEFT LEFT(str1, n) LEFT({Column}, 3) n characters from the beginning of input parameter
LEN LEN(str) LEN({Column}) Input parameter character length
LOWER LOWER(str) LOWER({Column}) Lower case converted string of input parameter
MID MID(str, position, [count]) MID({Column}, 3, 2) Alias for SUBSTR
REPEAT REPEAT(str, count) REPEAT({Column}, 2) Specified copies of the input parameter string concatenated together
REPLACE REPLACE(str, srchStr, rplcStr) REPLACE({Column}, 'int', 'num') String, after replacing all occurrences of srchStr with rplcStr
RIGHT RIGHT(str, n) RIGHT({Column}, 3) n characters from the end of input parameter
SEARCH SEARCH(str, srchStr) SEARCH({Column}, 'str') Index of srchStr specified if found, 0 otherwise
SUBSTR SUBTR(str, position, [count]) SUBSTR({Column}, 3, 2) Substring of length 'count' of input string, from the postition specified
TRIM TRIM(str) TRIM({Column}) Remove trailing and leading whitespaces from input parameter
UPPER UPPER(str) UPPER({Column}) Upper case converted string of input parameter
URL URL(str) URL({Column}) Convert to a hyperlink if it is a valid URL

Date Functions

Name Syntax Sample Output Remark
NOW NOW() NOW() 2022-05-19 17:20:43 Returns the current time and day
IF(NOW() < {DATE_COL}, "true", "false") IF(NOW() < date, "true", "false") If current date is less than {DATE_COL}, it returns true. Otherwise, it returns false. DateTime columns and negative values are supported.
DATEADD DATEADD(date | datetime, value, ["day" | "week" | "month" | "year"]) DATEADD(date, 1, 'day') Supposing {DATE_COL} is 2022-03-14. The result is 2022-03-15. DateTime columns and negative values are supported. Example: DATEADD(DATE_TIME_COL, -1, 'day')
DATEADD(date, 1, 'week') Supposing {DATE_COL} is 2022-03-14 03:14. The result is 2022-03-21 03:14. DateTime columns and negative values are supported. Example: DATEADD(DATE_TIME_COL, -1, 'week')
DATEADD(date, 1, 'month') Supposing {DATE_COL} is 2022-03-14 03:14. The result is 2022-04-14 03:14. DateTime columns and negative values are supported. Example: DATEADD(DATE_TIME_COL, -1, 'month')
DATEADD(date, 1, 'year') Supposing {DATE_COL} is 2022-03-14 03:14. The result is 2023-03-14 03:14. DateTime columns and negative values are supported. Example: DATEADD(DATE_TIME_COL, -1, 'year')
IF(NOW() < DATEADD(date,10,'day'), "true", "false") If the current date is less than {DATE_COL} plus 10 days, it returns true. Otherwise, it returns false. DateTime columns and negative values are supported.
IF(NOW() < DATEADD(date,10,'day'), "true", "false") If the current date is less than {DATE_COL} plus 10 days, it returns true. Otherwise, it returns false. DateTime columns and negative values are supported.
DATETIME_DIFF DATETIME_DIFF(date, date, ["milliseconds" | "ms" | "seconds" | "s" | "minutes" | "m" | "hours" | "h" | "days" | "d" | "weeks" | "w" | "months" | "M" | "quarters" | "Q" | "years" | "y"]) DATETIME_DIFF("2022/10/14", "2022/10/15", "second") Supposing {DATE_COL_1} is 2017-08-25 and {DATE_COL_2} is 2011-08-25. The result is 86400. Compares two dates and returns the difference in the unit specified. Positive integers indicate the second date being in the past compared to the first and vice versa for negative ones.
WEEKDAY(NOW(), "sunday") If today is Monday, it returns 1 Get the week day of NOW() with the first day set as sunday
WEEKDAY WEEKDAY(date, [startDayOfWeek]) WEEKDAY(NOW()) If today is Monday, it returns 0 Returns the day of the week as an integer between 0 and 6 inclusive starting from Monday by default. You can optionally change the start day of the week by specifying in the second argument
WEEKDAY(NOW(), "sunday") If today is Monday, it returns 1 Get the week day of NOW() with the first day set as sunday

Logical Operators

Operator Sample Description
< {Column1} < {Column2} Less than
> {Column1} > {Column2} Greater than
<= {Column1} <= {Column2} Less than or equal to
>= {Column1} >= {Column2} Greater than or equal to
== {Column1} == {Column2} Equal to
!= {Column1} != {Column2} Not equal to

Conditional Expressions

Name Syntax Sample Output
IF IF(expr, successCase, elseCase) IF({Column} > 1, Value1, Value2) successCase if expr evaluates to TRUE, elseCase otherwise
SWITCH SWITCH(expr, [pattern, value, ..., default]) SWITCH({Column}, 1, 'One', 2, 'Two', '--') Switch case value based on expr output
AND AND(expr1, [expr2,...]) AND({Column} > 2, {Column} < 10) TRUE if all expr evaluate to TRUE
OR OR(expr1, [expr2,...]) OR({Column} > 2, {Column} < 10) TRUE if at least one expr evaluates to TRUE

Logical operators, along with Numerical operators can be used to build conditional expressions.

Examples:

IF({marksSecured} > 80, "GradeA", "GradeB")  
SWITCH({quarterNumber},  
    1, 'Jan-Mar',
    2, 'Apr-Jun',
    3, 'Jul-Sep',
    4, 'Oct-Dec',
    'INVALID'
)