| TWiki Spreadsheet Plugin
This Plugin adds speadsheet capabilities to TWiki topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this Plugin provides general formula evaluation capability, not just classic spreadsheet functions.
Example:
Region: |
Sales: |
Northeast |
320 |
Northwest |
580 |
South |
240 |
Europe |
610 |
Asia |
220 |
Total: |
1970 |
| |
Interactive example:
|
The formula next to "Total" is %CALC{"$SUM( $ABOVE() )"}% . (you see the formula instead of the sum in case the Plugin is not installed or not enabled.)
|
On this page:
- Syntax Rules
- Use CALC or CALCULATE
- Built-in Spreadsheet Plugin Functions
- ABOVE( ) -- address range of cells above the current cell
- ABS( num ) -- absolute value of a number
- ADDLIST( name, list ) -- append a list to a list variable
- AND( list ) -- logical AND of a list
- AVERAGE( list ) -- average of a list or a range of cells
- BIN2DEC( num ) -- convert a binary number to decimal
- BITXOR( text ) -- bit-wise XOR of text
- CEILING( num ) -- return the smallest integer following a number
- CHAR( number ) -- ASCII character represented by number
- CODE( text ) -- ASCII numeric value of character
- COLUMN( offset ) -- current column number
- COUNTITEMS( list ) -- count individual items in a list
- COUNTSTR( list, str ) -- count the number of cells
- DEC2BIN( num, width ) -- convert a decimal number to binary
- DEC2HEX( num, width ) -- convert a decimal number to hexadecimal
- DEC2OCT( num, width ) -- convert a decimal number to octal
- DEF( list ) -- find first non-empty list item or cell
- EMPTY( text ) -- test for empty text
- EQUAL( text1, text2 ) -- compare two text strings, case-insensitive
- EVAL( formula ) -- evaluate a simple mathematical formula
- EVEN( num ) -- test for even number
- EXACT( text1, text2 ) -- compare two text strings, case-sensitive
- EXEC( formula ) -- execute a spreadsheet formula
- EXISTS( topic ) -- check if topic exists
- EXP( num ) -- exponent (e) raised to the power of a number
- FILTER( expression, text ) -- filter out characters from text
- FIND( string, text, start ) -- find one string within another string
- FLOOR( num ) -- return the largest integer preceding a number
- FORMAT( type, precision, number ) -- format a number
- FORMATGMTIME( serial, text ) -- convert a serialized date
- FORMATTIME( serial, text ) -- convert a serialized date
- FORMATTIMEDIFF( unit, precision, time, option ) -- convert elapsed time
- GET( name ) -- get the value of a variable
- GETHASH( name, key ) -- get the value of a previously set hash key
- GETLIST( name ) -- get the list from a list variable
- HASH2LIST( name, format ) -- convert a hash to a list
- HASHCOPY( from, to ) -- copy a hash
- HASHEACH( formula, name ) -- evaluate and update each hash element
- HASHEXISTS( name, key ) -- test if a hash exists
- HASHREVERSE( name ) -- reverse a hash
- HEX2DEC( num ) -- convert a hexadecimal number to decimal
- HEXDECODE( hexcode ) -- convert hexadecimal code to string
- HEXENCODE( text ) -- encode text into hexadecimal code
- IF( condition, then, else ) -- return a value based on a condition
- INSERTSTRING( text, start, new ) -- insert a string into a text string
- INT( formula ) -- evaluate formula and return integer truncated towards 0
- ISDIGIT( text ) -- test for digits
- ISLOWER( text ) -- test for lower case text
- ISUPPER( text ) -- test for upper case text
- ISWIKIWORD( text ) -- test for WikiWord
- LEFT( ) -- address range of cells to the left of the current cell
- LEFTSTRING( text, num ) -- extract characters at the beginning
- LENGTH( text ) -- length of text in bytes
- LIST( range ) -- convert content of a cell range into a list
- LIST2HASH( name, list ) -- create a hash from a list
- LISTEACH( formula, list ) -- evaluate and update each element of a list
- LISTIF( condition, list ) -- remove elements from a list
- LISTITEM( index, list ) -- get one element of a list
- LISTJOIN( separator, list ) -- convert a list into a string
- LISTNONEMPTY( list ) -- remove all empty elements from a list
- LISTRAND( list ) -- get one random element of a list
- LISTREVERSE( list ) -- opposite order of a list
- LISTSHUFFLE( list ) -- shuffle element of a list in random order
- LISTSIZE( list ) -- number of elements in a list
- LISTSORT( list ) -- sort a list
- LISTTRUNCATE( size, list ) -- truncate list to size
- LISTUNIQUE( list ) -- remove all duplicates from a list
- LN( num ) -- natural logarithm of a number
- LOG( num, base ) -- logarithm of a number to a given base
- LOWER( text ) -- lower case string of a text
- MAX( list ) - biggest value of a list or range of cells
- MEDIAN( list ) -- median of a list or range of cells
- MIN( list ) -- smallest value of a list or range of cells
- MOD( num, divisor ) -- reminder after dividing num by divisor
- NOEXEC( formula ) -- do not execute a spreadsheet formula
- NOP( text ) -- no-operation
- NOT( num ) -- reverse logic of a number
- NOTE( text ) -- note, return empty string
- OCT2DEC( num ) -- convert an octal number to decimal
- ODD( num ) -- test for odd number
- OR( list ) -- logical OR of a list
- PERCENTILE( num, list ) -- percentile of a list or range of cells
- PI( ) -- mathematical constant Pi, 3.14159265358979
- PRODUCT( list ) -- product of a list or range of cells
- PROPER( text ) -- properly capitalize text
- PROPERSPACE( text ) -- properly space out WikiWords
- RAND( max ) -- random number
- RANDSTRING( set, format ) -- random string & password generator
- REPEAT( text, num ) -- repeat text a number of times
- REPLACE( text, start, num, new ) -- replace part of a text string
- RIGHT( ) -- address range of cells to the right of the current cell
- RIGHTSTRING( text, num ) -- extract characters at the end
- ROUND( formula, digits ) -- round a number
- ROW( offset ) -- current row number
- SEARCH( string, text, start ) -- search a string within a text
- SET( name, value ) -- set a variable for later use
- SETHASH( name, key, value ) -- set a hash value for later use
- SETIFEMPTY( name, value ) -- set a variable only if empty
- SETLIST( name, list ) -- save a list for later use
- SETM( name, formula ) -- modify an existing variable
- SETMHASH( name, key, formula ) -- modify an existing hash
- SIGN( num ) -- sign of a number
- SPLIT( separator, text ) -- split a string into a list
- SQRT( num ) -- square root of a number
- STDEV( list ) -- standard deviation based on a sample
- STDEVP( list ) -- standard deviation based on the entire population
- SUBSTITUTE( text, old, new, instance, option ) -- substitute text
- SUBSTRING( text, start, num ) -- extract a substring out of a text string
- SUM( list ) -- sum of a list or range of cells
- SUMDAYS( list ) -- sum the days in a list or range of cells
- SUMPRODUCT( list, list ) -- scalar product on ranges of cells
- T( address ) -- content of a cell
- TIME( text ) -- convert a date string into a serialized date number
- TIMEADD( serial, value, unit ) -- add a value to a serialized date
- TIMEDIFF( serial_1, serial_2, unit ) -- time difference
- TODAY( ) -- serialized date of today at midnight GMT
- TRANSLATE( text, from, to ) -- translate text
- TRIM( text ) -- trim spaces from text
- UPPER( text ) -- upper case string of a text
- VALUE( text ) -- convert text to number
- VAR( list ) -- variance based on a sample
- VARP( list ) -- variance based on the entire population
- WHILE( condition, do ) -- do something while a condition is true
- WORKINGDAYS( serial_1, serial_2 ) -- working days
- XOR( list ) -- logical XOR of a list
- FAQ
- CALC in Included Topics
- Bug Tracking Example
- Plugin Settings
- Plugin Installation Instructions
- Plugin Info
Syntax Rules
The action of this Plugin is triggered by the %CALC{"..."}% variable, which gets rendered according to the built-in function(s) found between the quotes.
- Built-in function are of format
$FUNCNAME(parameter)
- Functions may be nested, e.g.
%CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
- Functions are evaluated from left to right, and from inside to outside if nested
- The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
- Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g.
%CALC{"$SUM( 3, 5, 7 )"}%
- A table cell can be addressed as
R1:C1 . Table address matrix: R1:C1 | R1:C2 | R1:C3 | R1:C4 | R2:C1 | R2:C2 | R2:C3 | R2:C4 |
- A table cell range is defined by two cell addresses separated by
".." , e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
- Lists can refer to values and/or table cell ranges, e.g.
%CALC{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"}%
- Formulae can only reference cells in the current or preceeding row of the current table; they may not reference cells below the current table row
- Formulae can also be placed outside of tables; they can reference cells in the preceeding table
Built-in Functions
Conventions for Syntax:
- Required parameters are indicated in
( bold )
- Optional parameters are indicated in
( bold italic )
ABOVE( ) -- address range of cells above the current cell
- Syntax:
$ABOVE( )
- Example:
%CALC{"$SUM($ABOVE())"}% returns the sum of cells above the current cell
- Related:
$LEFT() , $RIGHT()
ABS( num ) -- absolute value of a number
- Syntax:
$ABS( num )
- Example:
%CALC{"$ABS(-12.5)"}% returns 12.5
- Related:
$SIGN()
AND( list ) -- logcial AND of a list
- Syntax:
$AND( list )
- Example:
%CALC{"$AND(1, 0, 1)"}% returns 0
- Related:
$NOT() , $IF() , $OR()
AVERAGE( list ) -- average of a list or a range of cells
- Syntax:
$AVERAGE( list )
- Example:
%CALC{"$AVERAGE(R2:C5..R$ROW(-1):C5)"}% returns the average of column 5, excluding the title row
- Related:
$LIST() , $MAX() , $MEDIAN() , $MIN()
CHAR( number ) -- ASCII character represented by number
- Syntax:
$CHAR( number )
- Example: Example:
%CALC{"$CHAR(97)"}% returns a
- Related:
$CODE()
CODE( text ) -- ASCII numeric value of character
- The ASCII numeric value of the first character in text
- Syntax:
$CODE( text )
- Example:
%CALC{"$CODE(abc)"}% returns 97
- Related:
$CHAR()
COLUMN( offset ) -- current column number
- The current table column number with an optional offset
- Syntax:
$COLUMN( offset )
- Example:
%CALC{"$COLUMN()"}% returns 2 for the second column
- Related:
$ROW() , $T()
COUNTITEMS( list ) -- count individual items in a list
- Syntax:
$COUNTITEMS( list )
- Example:
%CALC{"$COUNTITEMS($ABOVE())"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
- Related:
$COUNTSTR() , $LIST()
COUNTSTR( list, str ) -- count the number of cells in a list equal to a given string
- Count the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list
- Syntax:
$COUNTSTR( list, str )
- Example:
%CALC{"$COUNTSTR($ABOVE())"}% counts the number of non empty cells above the current cell
- Example:
%CALC{"$COUNTSTR($ABOVE(), DONE)"}% counts the number of cells equal to DONE
- Related:
$COUNTITEMS() , $LIST()
DEF( list ) -- find first non-empty list item or cell
- Returns the first list item or cell reference that is not empty
- Syntax:
$DEF( list )
- Example:
%CALC{"$DEF(R1:C1..R1:C3)"}%
- Related:
$COUNTSTR() , $LISTIF() , $LIST()
EVAL( formula ) -- evaluate a simple formula
- Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
- Syntax:
$EVAL( formula )
- Example:
%CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
- Related:
$INT() , $MOD() , $ROUND() , $VALUE()
EXACT( text1, text2 ) -- compare two text strings
- Compares two text strings and returns
1 if they are exactly the same, or 0 if not
- Syntax:
$EXACT( text1, text2 )
- Example:
%CALC{"$EXACT(foo, Foo)"}% returns 0
- Example:
%CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
- Related:
$IF() , $TRIM()
FIND( string, text, start ) -- find one string within another string
- Finds one text
string , within another text , and returns the number of the starting position of string , from the first character of text . This search is case sensitive and is not a regular expression search; use $SEARCH() for regular expression searching. Starting position is 1; a 0 is returned if nothing is matched.
- Syntax:
$FIND( string, text, start )
- Example:
%CALC{"$FIND(f, fluffy)"}% returns 1
- Example:
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
- Example:
%CALC{"$FIND(@, fluffy, 1)"}% returns 0
- Related:
$REPLACE() , $SEARCH()
FORMAT( type, prec, number ) -- format a number to a certain type and precision
- Type can be COMMA for comma format, DOLLAR for Dollar format, NUMBER for number, and PERCENT for percent format
- Syntax:
$FORMAT( type, prec, number )
- Example:
%CALC{"$FORMAT(COMMA, 2, 12345.6789)"}% returns 12,345.68
- Example:
%CALC{"$FORMAT(DOLLAR, 2, 12345.67)"}% returns $12,345.68
- Example:
%CALC{"$FORMAT(NUMBER, 1, 12345.67)"}% returns 12345.7
- Example:
%CALC{"$FORMAT(PERCENT, 1, 0.1234567)"}% returns 12.3%
- Related:
$ROUND()
FORMATTIME( serial, text ) -- convert a serialized date into a date string
- The following variables in
text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone.
- Syntax:
$FORMATTIME( serial, text )
- Example:
%CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
- Related:
$FORMATGMTIME() , $TIME() , $TIMEADD() , $TIMEDIFF() , $TODAY()
FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string
- The date string represents the time in Greenwich time zone. Same variable expansion as in
$FORMATTIME() .
- Syntax:
$FORMATGMTIME( serial, text )
- Example:
%CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
- Related:
$FORMATTIME() , $TIME() , $TIMEADD() , $TIMEDIFF() , $TODAY()
GET( name ) -- get the value of a previously set variable
- Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use
$SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables.
- Syntax:
$GET( name )
- Example:
%CALC{"$GET(my_total)"}% returns the value of the my_total variable
- Related:
$SET() , $SETM()
IF( condition, value if true, value if 0 ) -- return a value based on a condition
- The condition can be a number (where
0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than).
- Syntax:
$IF( condition, value if true, value if 0 )
- Example:
%CALC{"$IF($T(R1:C5) > 1000, Over Budget, OK)"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
- Example:
%CALC{"$IF($EXACT($T(R1:C2),), empty, $T(R1:C2))"}% returns the content of R1:C2 or empty if empty
- Example:
%CALC{"$SET(val, $IF($T(R1:C2) == 0, zero, $T(R1:C2)))"}% sets a variable conditionally
- Related:
$AND() , $EXACT() , $LISTIF() , $NOT() , $OR()
INT( formula ) -- evaluate formula and round down to nearest integer
- Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
- Syntax:
$INT( formula )
- Example:
%CALC{"$INT(10 / 4)"}% returns 2
- Related:
$EVAL() , $ROUND() , $VALUE()
LEFT( ) -- address range of cells to the left of the current cell
- Syntax:
$LEFT( )
- Example:
%CALC{"$SUM($LEFT())"}% returns the sum of cells to the left of the current cell
- Related:
$ABOVE() , $RIGHT()
LENGTH( text ) -- length of text in bytes
- Syntax:
$LENGTH( text )
- Example:
%CALC{"$LENGTH(abcd)"}% returns 4
- Related:
$LISTSIZE()
LIST( range ) -- convert content of a cell range into a list
- Convert the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list
- Syntax:
$LIST( range )
- Example:
%CALC{"$LIST($LEFT())"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
- Related:
$AVERAGE() , $COUNTITEMS() , $COUNTSTR() , $DEF() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $MAX() , $MEDIAN() , $MIN() , $PRODUCT() , $SUM() , $SUMDAYS() , $SUMPRODUCT()
LISTIF( condition, list ) -- remove elements from a list that do not meet a condition
- In addition to the condition described in
$IF() , you can use $item to indicate the current element, and $index for the list index, starting at 1
- Syntax:
$LISTIF( condition, list )
- Example:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
- Example:
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E
- Example:
%CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D
- Related:
$IF() , $LIST() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
LISTITEM( index, list ) -- get one element of a list
- Index is 1 to size of list; use a negative number to count from the end of the list
- Syntax:
$LISTITEM( index, list )
- Example:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
- Example:
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
LISTMAP( formula, list ) -- evaluate and update each element of a list
- In the formula you can use
$item to indicate the element; $index to show the index of the list, starting at 1
- Syntax:
$LISTMAP( formula, list )
- Example:
%CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
LISTREVERSE( list ) -- opposite order of a list
- Syntax:
$LISTREVERSE( list )
- Example:
%CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
LISTSIZE( list ) -- number of elements in a list
- Syntax:
$LISTSIZE( list )
- Example:
%CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
LISTSORT( list ) -- sort a list
- Sorts a list in ASCII order, or numerically if all elements are numeric
- Syntax:
$LISTSORT( list )
- Example:
%CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTUNIQUE() , $SUM()
LISTUNIQUE( list ) -- remove all duplicates from a list
- Syntax:
$LISTUNIQUE( list )
- Example:
%CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $SUM()
LOWER( text ) -- lower case string of a text
MAX( list ) - biggest value of a list or range of cells
- Syntax:
$MAX( list )
- Example: To find the biggest number to the left of the current cell, write:
%CALC{"$MAX($LEFT())"}%
- Related:
$LIST() , $MEDIAN() , $MIN()
MEDIAN( list ) -- median of a list or range of cells
- Syntax:
$MEDIAN( list )
- Example:
%CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
- Related:
$LIST() , $MAX() , $MIN()
MIN( list ) -- smallest value of a list or range of cells
MOD( num, divisor ) -- reminder after dividing num by divisor
- Syntax:
$MOD( num, divisor )
- Example:
%CALC{"$MOD(7, 3)"}% returns 1
- Related:
$EVAL() , $()
NOP( text ) -- no-operation
- Useful to change the order of Plugin execution. For example, it allows preprossing to be done before
%SEARCH{}% is evaluated. The percent character '%' can be escaped with $per
- Syntax:
$NOP( text )
NOT( num ) -- reverse logic of a number
- Returns 0 if
num is not zero, 1 if zero
- Syntax:
$NOT( num )
- Example:
%CALC{"$NOT(0)"}% returns 1
- Related:
$AND() , $IF() , $OR()
OR( list ) -- logcial OR of a list
- Syntax:
$OR( list )
- Example:
%CALC{"$OR(1, 0, 1)"}% returns 1
- Related:
$AND() , $IF() , $NOT()
PRODUCT( list ) -- product of a list or range of cells
- Syntax:
$PRODUCT( list )
- Example: To calculate the product of the cells to the left of the current one use
%CALC{"$PRODUCT($LEFT())"}%
- Related:
$LIST() , $PRODUCT() , $SUM() , $SUMPRODUCT()
PROPER( text ) -- properly capitalize trxt
- Capitalize letters that follow any character other than a letter; convert all other letters to lowercase letters
- Syntax:
$PROPER( text )
- Example:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
- Example:
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula-1)
- Related:
$LOWER() , $PROPERSPACE() , $TRIM() , $UPPER()
PROPERSPACE( text ) -- properly space out WikiWords
- Properly spaces out WikiWords preceeded by white space, parenthesis, or
][ . Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded
- Syntax:
$PROPERSPACE( text )
- Example: Assuming DONTSPACE contains MacDonald:
%CALC{"PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
- Related:
$LOWER() , $PROPER() , $TRIM() , $UPPER()
RAND( max ) -- random number
- Random number, evenly distributed between 0 and
max , or 0 and 1 if max is not specified
- Syntax:
$RAND( max )
- Related:
$EVAL()
REPEAT(text) -- repeat text a number of times
- Syntax:
$REPEAT( text )
- Example:
%CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
REPLACE( text, start, num, new ) -- replace part of a text string
- Replace
num number of characters of text string text , starting at start , with new text new . Starting position is 1; use a negative start to count from the end of the text
- Syntax:
$REPLACE( text, start, num, new )
- Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
- Related:
$FIND() , $SEARCH() , $SUBSTITUTE() , $TRANSLATE()
RIGHT( ) -- address range of cells to the right of the current cell
- Syntax:
$RIGHT( )
- Example:
%CALC{"$SUM($RIGHT())"}% returns the sum of cells to the right of the current cell
- Related:
$ABOVE() , $LEFT()
ROUND( formula, digits ) -- round a number
- Evaluates a simple
formula and rounds the result up or down to the number of digits if digits is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative
- Syntax:
$ROUND( formula, digits )
- Example:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
- Example:
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
- Example:
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
- Example:
%CALC{"$ROUND(34.9, -1)"}% returns 30
- Related:
$INT() , $FORMAT()
ROW( offset ) -- current row number
- The current table row number with an optional offset
- Syntax:
$ROW( offset )
- Example: To get the number of rows excluding table heading (first row) and summary row (last row you are in), write:
%CALC{"$ROW(-2)"}%
- Related:
$COLUMN() , $T()
SEARCH( string, text, start ) -- search a string within a text
- Finds one text
string , within another text , and returns the number of the starting position of string , from the first character of text . This search is a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
- Syntax:
$SEARCH( string, text, start )
- Example:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
- Example:
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
- Example:
%CALC{"$SEARCH([abc], fluffy,)"}% returns 0
- Related:
$FIND() , $REPLACE()
SET( name, value ) -- set a variable for later use
- Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulas are evaluated before the variable assignment. This function returns no output. Use
$GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables
- Syntax:
$SET( name, value )
- Example:
%CALC{"$SET(my_total, $SUM($ABOVE()))"}% sets the my_total variable to the sum of all table cells located above the current cell and returns an empty string
- Related:
$GET() , SETM()
SETM( name, formula ) -- update an existing variable based on a formula
- Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to
+ (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
- Syntax:
$SETM( name, formula )
- Example:
%CALC{"$SETM(total, + $SUM($LEFT()))"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
- Related:
$GET() , $SET()
SIGN( num ) -- sign of a number
- Returns -1 if
num is negative, 0 if zero, or 1 if positive
- Syntax:
$SIGN( num )
- Example:
%CALC{"$SIGN(-12.5)"}% returns -1
- Related:
$ABS() , $EVAL() , $INT() , $NOT()
SUBSTITUTE( text, old, new, instance, option ) -- substitute text
- Substitutes
new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance , only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r
- Syntax:
$SUBSTITUTE( text, old, new, instance, option )
- Example:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
- Example:
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
- Example:
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
- Example:
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
- Related:
$REPLACE() , $TRANSLATE()
SUM( list ) -- sum of a list or range of cells
- Syntax:
$SUM( list )
- Example: To sum up column 5 excluding the title row, write
%CALC{"$SUM(R2:C5..R$ROW(-1):C5)"}% in the last row; or simply %CALC{"$SUM($ABOVE())"}%
|