%CALCULATE{$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 function evaluation capability, not just classic spreadsheet functions. The plugin currently has
126 functions.
Example:
|
Raw text:
| *Region:* | *Sales:* |
| Americas | 732 |
| Europe | 611 |
| Asia | 228 |
| Total: | %CALC{$SUM($ABOVE())}% |
|
%CALC{...}% and %CALCULATE{...}% variables. Embedded formulas are evaluated as follows:
$FUNCNAME(parameters)
%CALC{$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )}%
%CALCULATE{$SUM( 3, 5, 7 )}%
%CALCULATE{$SUBSTITUTE('''Good, early morning''', morning, day)}%
%CALCULATE{...}% variable may span multiple lines, which is useful to indent nested functions. In case the variable contains newlines, all white space around functions and function parameters is removed. Sample nested formula: %CALCULATE{ $LISTJOIN( $n, $LISTEACH( | $index | $item |, one, two, three ) ) }%
R1:C1. Table address matrix: R1:C1 | R1:C2 | R1:C3 | R1:C4 |
R2:C1 | R2:C2 | R2:C3 | R2:C4 |
"..", e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
%CALC{$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )}%
%CALC{Total: $SUM($ABOVE()) kg}%
%CALC{...}% in table cells:
%INCLUDE{%CALC{...}%}%) because it does not get evaluated inside-out & left-to-right like ordinary TWiki variables.
%CALCULATE{...}% outside tables:
$LEFT() or $T().
( bold )
( bold italic )
$ABOVE( )
%CALC{$SUM($ABOVE())}% returns the sum of cells above the current cell
$LEFT(), $RIGHT()
$ABS( num )
%CALCULATE{$ABS(-12.5)}% returns 12.5
$SIGN(), $EVEN(), $ISDIGIT(), $ODD()
$GETLIST() to retrieve a list variable.
$ADDLIST( name, list )
%CALCULATE{$SETLIST(nums, 0, 1, 2, 3)}% sets the nums variable to 0, 1, 2, 3 %CALCULATE{$ADDLIST(nums, 4, 5, 6, 7)}% adds 4, 5, 6, 7 to the nums variable %CALCULATE{$GETLIST(nums)}% returns 0, 1, 2, 3, 4, 5, 6, 7
format="$percntCALCULATE{$ADDLIST(topics, $topic)}$percnt" in each search hit, adds the topic name to the topics list variable
$GETLIST(), $SET(), $SETHASH(), $SETLIST()
$AND( list )
%CALCULATE{$AND(1, 0, 1)}% returns 0
$NOT(), $IF(), $OR(), $WHILE(), $XOR()
$AVERAGE( list )
%CALC{$AVERAGE(R2:C5..R$ROW(-1):C5)}% returns the average of column 5, excluding the title row
$LIST(), $MAX(), $MEDIAN(), $MIN(), $STDEV(), $STDEVP(), $VAR(), $VARP()
$BIN2DEC( num )
%CALCULATE{$BIN2DEC(1100100)}% returns 100
$DEC2BIN(), $DEC2HEX(), $DEC2OCT(), $HEX2DEC(), $HEXDECODE(), $HEXENCODE(), $OCT2DEC()
text is flipped, useful to obfuscate text. Bit-XORing text twice will restore the original text.
$BITXOR( text )
%CALCULATE{$BITXOR(A123)}% returns ¾ÎÍÌ
%CALCULATE{$BITXOR($BITXOR(anything))}% returns anything
$HEXDECODE(), $HEXENCODE(), $LEFTSTRING(), $RANDSTRING(), $REPLACE(), $RIGHTSTRING(), $SUBSTITUTE(), $TRANSLATE(), $XOR()
$INT() to truncate a number towards zero; use $FLOOR() to get the largest previous integer
$CEILING( num )
%CALCULATE{$CEILING(5.4)}% returns 6
%CALCULATE{$CEILING(-5.4)}% returns -5
$EVAL(), $FLOOR(), $INT(), $ROUND(), $VALUE()
$CHAR( number )
%CALCULATE{$CHAR(97)}% returns a
$CODE()
$CODE( text )
%CALCULATE{$CODE(abc)}% returns 97
$CHAR()
$COLUMN( offset )
%CALC{$COLUMN()}% returns 2 for the second column
$ROW(), $T()
$COUNTITEMS( list )
%CALC{$COUNTITEMS($ABOVE())}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
$COUNTSTR(), $LIST(), $SETMHASH(), $WHILE()
$COUNTSTR( list, str )
%CALC{$COUNTSTR($ABOVE())}% counts the number of non empty cells above the current cell
%CALC{$COUNTSTR($ABOVE(), DONE)}% counts the number of cells equal to DONE
$COUNTITEMS(), $LIST(), $SETMHASH(), $WHILE()
$DEC2BIN( num, width )
%CALCULATE{$DEC2BIN(100)}% returns 1100100
%CALCULATE{$DEC2BIN(9, 6)}% returns 001001
$BIN2DEC(), $DEC2HEX(), $DEC2OCT(), $HEX2DEC(), $HEXDECODE(), $HEXENCODE(), $OCT2DEC()
$DEC2HEX( num, width )
%CALCULATE{$DEC2HEX(165)}% returns A5
%CALCULATE{$DEC2HEX(100, 4)}% returns 0064
$BIN2DEC(), $DEC2BIN(), $DEC2OCT(), $HEX2DEC(), $HEXDECODE(), $HEXENCODE(), $OCT2DEC()
$DEC2OCT( num, width )
%CALCULATE{$DEC2OCT(58)}% returns 72
%CALCULATE{$DEC2OCT(58, 4)}% returns 0072
$BIN2DEC(), $DEC2BIN(), $DEC2HEX(), $HEX2DEC(), $HEXDECODE(), $HEXENCODE(), $OCT2DEC()
$DEF( list )
%CALC{$DEF(R1:C1..R1:C3)}%
$COUNTSTR(), $LISTIF(), $LIST()
1 if text is empty, or 0 if not
$EMPTY( text )
%CALCULATE{$EMPTY(foo)}% returns 0
%CALCULATE{$EMPTY()}% returns 1
%CALCULATE{$EMPTY($TRIM( ))}% returns 1
$EQUAL(), $EXACT(), $IF(), $ISDIGIT(), $ISLOWER(), $ISUPPER(), $ISWIKIWORD(), $TRIM(), $WHILE()
1 if they are the same ignoring the case, or 0 if not; use $EXACT() for case-sensitive compare
$EQUAL( text1, text2 )
%CALCULATE{$EQUAL(foo, Foo)}% returns 1
$EMPTY(), $EXACT(), $IF(), $ISDIGIT(), $ISLOWER(), $ISUPPER(), $ISWIKIWORD(), $TRIM()
1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
$EVAL( formula )
%CALCULATE{$EVAL( (5 * 3) / 2 + 1.1 )}% returns 8.6
$CEILING(), $EXEC(), $FLOOR(), $INT(), $MOD(), $ROUND(), $VALUE()
$EVEN( num )
%CALCULATE{$EVEN(2)}% returns 1
$ABS(), $ISDIGIT(), $MOD(), $ODD(), $SIGN()
1 if they are exactly the same, or 0 if not; use $EQUAL() for case-insensitive compare
$EXACT( text1, text2 )
%CALCULATE{$EXACT(foo, Foo)}% returns 0
%CALCULATE{$EXACT(foo, $LOWER(Foo))}% returns 1
$EMPTY(), $IF(), $ISDIGIT(), $ISLOWER(), $ISUPPER(), $ISWIKIWORD(), $TRIM()
$EXEC( formula )
%CALCULATE{$SET(msg, $NOEXEC(Hi $GET(name)))}% sets the msg variable with raw formula Hi $GET(name)
%CALCULATE{$SET(name, Tom) $EXEC($GET(msg))}% executes content of msg variable and returns Hi Tom
%CALCULATE{$SET(name, Jerry) $EXEC($GET(msg))}% returns Hi Jerry
$EVAL(), $GET(), $NOEXEC(), $SET()
TopicName or a Web.TopicName. Current web is used if web is not specified.
$EXISTS( topic )
%CALCULATE{$EXISTS(WebHome)}% returns 1
%CALCULATE{$EXISTS(ThisDoesNotExist)}% returns 0
$EQUAL(), $EXACT(), $IF(), $ISWIKIWORD(), $TRIM()
$EXP( num )
%CALCULATE{$EXP(1)}% returns 2.71828182845905
$LN(), $LOG()
text string. The filter is applied multiple times.
expression can be a sequence of characters or a RegularExpression. Use tokens in the expression if needed: $comma for comma, $sp for space. The text may contain commas.
$FILTER( chars, text )
%CALCULATE{$FILTER(f, fluffy)}% returns luy - filter out a character multiple times
%CALCULATE{$FILTER(an Franc, San Francisco)}% returns Sisco - cut a string
%CALCULATE{$FILTER($sp, Cat and Mouse)}% returns CatandMouse - remove all spaces
%CALCULATE{$FILTER([^0-9], Project-ID-1234)}% returns 1234 - filter in digits, e.g. keep only digits
%CALCULATE{$FILTER([^a-zA-Z0-9 ], Stupid mistake*%@^! Fixed)}% returns Stupid mistake Fixed - keep only alphanumeric characters and spaces
%CALCULATE{$FILTER([^a-zA-Z0-9], $PROPER(an EXELLENT idea.))}% returns AnExcellentIdea - turn a string into a WikiWord topic name
$FIND(), $INSERTSTRING(), $LEFTSTRING(), $PROPER(), $REPLACE(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE(), $TRIM()
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.
$FIND( string, text, start )
%CALCULATE{$FIND(f, fluffy)}% returns 1
%CALCULATE{$FIND(f, fluffy, 2)}% returns 4
%CALCULATE{$FIND(@, fluffy, 1)}% returns 0
$FILTER(), $INSERTSTRING(), $LEFTSTRING(), $REPLACE(), $RIGHTSTRING(), $SUBSTITUTE(), $SUBSTRING(), $SEARCH()
$INT() to truncate a number towards zero; use $CEILING() to get the smallest following integer
$FLOOR( num )
%CALCULATE{$FLOOR(5.4)}% returns 5
%CALCULATE{$FLOOR(-5.4)}% returns -6
$CEILING(), $EVAL(), $INT(), $ROUND(), $VALUE()
type: COMMA for comma format, such as 12,345.68
CURRENCY for currency format, such as €12,345.68 (€6,789.00) for -6789
US$ or $ for Dollar, € for Euro, ¥ for Yen, default $
DOLLAR for Dollar format, such as $12,345.68 ($6,789.00) for -6789
KB for Kilo Byte format, such as 1205.63 KB
MB for Mega Byte format, such as 1.18 MB
KBMB for Kilo/Mega/Giga/Tera Byte auto-adjust format
NUMBER for number, such as 12345.7
PERCENT for percent format, such as 12.3%
precision indicates the the number of digits after the dot
$FORMAT( type, prec, number )
%CALCULATE{$FORMAT(COMMA, 2, 12345.6789)}% returns 12,345.68
%CALCULATE{$FORMAT(CURRENCY, 2, 12345.6789)}% returns $12,345.68
%CALCULATE{$FORMAT(DOLLAR, 2, 12345.6789)}% returns $12,345.68
%CALCULATE{$FORMAT(KB, 2, 1234567)}% returns 1205.63 KB
%CALCULATE{$FORMAT(MB, 2, 1234567)}% returns 1.18 MB
%CALCULATE{$FORMAT(KBMB, 2, 1234567)}% returns 1.18 MB
%CALCULATE{$FORMAT(KBMB, 2, 1234567890)}% returns 1.15 GB
%CALCULATE{$FORMAT(NUMBER, 1, 12345.67)}% returns 12345.7
%CALCULATE{$FORMAT(PERCENT, 1, 0.1234567)}% returns 12.3%
$FORMATTIME(), $FORMATTIMEDIFF(), $ROUND()
$FORMATTIME().
$FORMATGMTIME( serial, text )
%CALCULATE{$FORMATGMTIME(1041379200, $day $mon $year)}% returns 01 Jan 2003
$FORMATTIME(), $FORMATTIMEDIFF(), $TIME(), $TIMEADD(), $TIMEDIFF(), $TODAY()
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
$isoweek - ISO 8601 week number, one or two digits, 1..53
$isoweek(format) - formatted ISO 8601 week numberformat: $isoweek($year) - year of ISO 8601 week number, such as 2009 for 2010-01-03
$isoweek($wk) - 2 digit ISO 8601 week number, such as 53 for 2010-01-03
$isoweek($day) - day of ISO 8601 week number, starting with 1 for Monday, such as 7 for 2010-01-03
$isoweek($iso) - full year-week ISO week number, such as 2009-W53 for 2010-01-03
$isoweek($yearW$wk$day) - full year-week-day ISO week number, such as 2009W537 for 2010-01-03
$isoweek($year-W$wk-$day) - full year-week-day ISO week number, such as 2009-W53-7 for 2010-01-03
$isoweek($year-W$wk) - year-week ISO 8601 week number, such as 2009-W53 for 2010-01-03
GMT to text to indicate Greenwich time zone, or use $FORMATGMTIME().
$FORMATTIME( serial, text )
%CALCULATE{$FORMATTIME(0, $year/$month/$day GMT)}% returns 1970/01/01 GMT
$FORMATGMTIME(), $TIME(), $FORMATTIMEDIFF(), $TIMEADD(), $TIMEDIFF(), $TODAY()
time to a human readable format, such as: 12 hours and 3 minutes
unit can be second, minute, hour, day, month, year. Note: An approximation is used for month and year calculations.
precision indicates the number of output units to use
option determines the format: 12 hours and 3 minutes
s - short format, such as: 12 h, 3 min
c - compact format, such as: 12h 3m
$FORMATTIMEDIFF( unit, precision, time, option )
%CALCULATE{$FORMATTIMEDIFF(min, 1, 200)}% returns 3 hours
%CALCULATE{$FORMATTIMEDIFF(min, 2, 200)}% returns 3 hours and 20 minutes
%CALCULATE{$FORMATTIMEDIFF(min, 2, 200, s)}% returns 3 h, 20 min
%CALCULATE{$FORMATTIMEDIFF(min, 1, 1640)}% returns 1 day
%CALCULATE{$FORMATTIMEDIFF(min, 2, 1640)}% returns 1 day and 3 hours
%CALCULATE{$FORMATTIMEDIFF(min, 3, 1640)}% returns 1 day, 3 hours and 20 minutes
$FORMATTIME(), $TIME(), $TIMEADD(), $TIMEDIFF()
$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.
$GET( name )
%CALCULATE{$GET(my_total)}% returns the value of the my_total variable
$EXEC(), $GETHASH(), $GETLIST(), $LIST2HASH(), $HASH2LIST(), $NOEXEC(), $SET(), $SETHASH(), $SETIFEMPTY(), $SETM(), $SETMHASH(), $WHILE(), SetGetPlugin
$SETHASH() or $LIST2HASH() to set a hash. If the key is omitted, a list of all keys of the named hash is returned. If no parameters are specified, a list of all hash names is returned.
$GETHASH( name, key )
%CALCULATE{$SETHASH(age, Jane, 26)}% %CALCULATE{$SETHASH(age, Tim, 27)}% %CALCULATE{$GETHASH(age, Jane)}% returns 26 %CALCULATE{$GETHASH(age)}% returns Jane, Tim %CALCULATE{$GETHASH()}% returns age
$GET(), $GETLIST(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $SET(), $SETHASH(), $SETMHASH()
$SETLIST() or $ADDLIST() to set a variable.
$GETLIST( name )
%CALCULATE{$GETLIST(nums)}% returns the value of the nums variable
$ADDLIST(), $GET(), $GETHASH(), $SETLIST(), SetGetPlugin
$key$comma $value, e.g. key & value in list format; $key indicates the key, $comma a comma, and $value the value. Keep in mind that you will get unexpected results if keys or values contain commas. Use $SETHASH() or $LIST2HASH() to set a hash.
$HASH2LIST( name, format )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27)}% %CALCULATE{$HASH2LIST(age)}% returns Jane, 26, Tim, 27 %CALCULATE{$HASH2LIST(age, $key is $value)}% returns Jane is 26, Tim is 27 %CALCULATE{$HASH2LIST(age, $key)}% returns Jane, Tim %CALCULATE{$HASH2LIST(age, $value)}% returns 26, 27
$GETHASH(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $SET(), $SETHASH(), $SETMHASH()
$HASHCOPY( from, to )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27, Sam, 28)}% %CALCULATE{$HASHCOPY(age, new)}% creates new hash new from hash age %CALCULATE{$HASH2LIST(new, $key: $value)}% returns Jane: 26, Sam: 28, Tim: 27
$GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $SETHASH(), $SETMHASH()
$key indicates the key, $value the value, and $index the index of the sorted key list, starting at 1. If $value is omitted, the item is appended to the formula. This function returns no output.
$HASHEACH( formula, name )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27)}% %CALCULATE{$HASHEACH($INT($value + 2), age)}% adds 2 years to each person %CALCULATE{$HASH2LIST(age, $key is now $value)}% returns Jane is now 28, Tim is now 29
$COUNTITEMS(), $COUNTSTR(), $GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $LISTEACH(), $SETHASH(), $SETMHASH()
$HASHEXISTS( name, key )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27)}% %CALCULATE{$HASHEXISTS(age)}% returns 1 %CALCULATE{$HASHEXISTS(age, Jane)}% returns 1 %CALCULATE{$HASHEXISTS(age, Blake)}% returns 0 %CALCULATE{$HASHEXISTS(height)}% returns 0
$GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHREVERSE(), $LIST2HASH(), $SETHASH(), $SETMHASH()
$HASHREVERSE( name )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27, Sam, 28)}% %CALCULATE{$HASHREVERSE(age)}% reverses the hash and returns nothing %CALCULATE{$HASH2LIST(age, $key: $value)}% returns 26: Jane, 27: Tim, 28: Sam
$GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $LIST2HASH(), $SETHASH(), $SETMHASH()
$HEX2DEC( num )
%CALCULATE{$HEX2DEC(A5)}% returns 165
$BIN2DEC(), $DEC2BIN(), $DEC2HEX(), $DEC2OCT(), $HEXDECODE(), $HEXENCODE(), $OCT2DEC()
$HEXDECODE( hexcode )
%CALCULATE{$HEXDECODE(687474703A2F2F7477696B692E6F72672F)}% returns http://twiki.org/
$BITXOR(), $HEX2DEC(), $HEXENCODE(), $SUBSTITUTE(), $TRANSLATE()
text is encoded into two hexadecimal numbers.
$HEXENCODE( text )
%CALCULATE{$HEXENCODE(http://twiki.org/)}% returns 687474703A2F2F7477696B692E6F72672F
$BITXOR(), $DEC2HEX(), $HEXDECODE(), $SUBSTITUTE(), $TRANSLATE()
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).
$IF( condition, value if true, value if 0 )
%CALC{$IF($T(R1:C5) > 1000, Over Budget, OK)}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{$IF($EXACT($T(R1:C2),), empty, $T(R1:C2))}% returns the content of R1:C2 or empty if empty
%CALC{$SET(val, $IF($T(R1:C2) == 0, zero, $T(R1:C2)))}% sets a variable conditionally
$AND(), $EMPTY(), $EQUAL(), $EXACT(), $ISDIGIT(), $ISLOWER(), $ISUPPER(), $ISWIKIWORD(), $LISTIF(), $NOT(), $OR(), $WHILE()
new string into text string text to the right of start position. Position starts at 1; use a negative start to count from the end of the text
$INSERTSTRING( text, start, new )
%CALCULATE{$INSERTSTRING(abcdefg, 2, XYZ)}% returns abXYZcdefg
%CALCULATE{$INSERTSTRING(abcdefg, -2, XYZ)}% returns abcdeXYZfg
$FILTER(), $FIND(), $LEFTSTRING(), $RANDSTRING(), $REPLACE(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE()
1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
$INT( $VALUE( number ) )
$INT( formula )
%CALCULATE{$INT(10 / 4)}% returns 2
%CALCULATE{$INT($VALUE(09))}% returns 9
$CEILING(), $EVAL(), $FLOOR(), $ROUND(), $VALUE()
$ISDIGIT( text )
%CALCULATE{$ISDIGIT(123)}% returns 1
%CALCULATE{$ISDIGIT(-7)}% returns 0
$ABS(), $EMPTY(), $EVEN(), $EQUAL(), $EXACT(), $IF(), $ISDIGIT(), $MOD(), $ODD(), $SIGN(), $VALUE()
$ISLOWER( text )
%CALCULATE{$ISLOWER(apple)}% returns 1
%CALCULATE{$ISLOWER(apple tree)}% returns 0 (text contains a space character)
%CALCULATE{$ISLOWER(ORANGE)}% returns 0
$EMPTY(), $EQUAL(), $EXACT(), $LOWER(), $IF(), $ISDIGIT(), $ISUPPER(), $ISWIKIWORD(), $UPPER()
$ISUPPER( text )
%CALCULATE{$ISUPPER(apple)}% returns 0
%CALCULATE{$ISUPPER(ORANGE)}% returns 1
%CALCULATE{$ISUPPER(ORANGE GARDEN)}% returns 0 (text contains a space character)
$EMPTY(), $EQUAL(), $EXACT(), $LOWER(), $IF(), $ISDIGIT(), $ISLOWER(), $ISWIKIWORD(), $UPPER()
$ISUPPER() to test for valid topic names
$ISWIKIWORD( text )
%CALCULATE{$ISWIKIWORD(GoldenGate)}% returns 1
%CALCULATE{$ISWIKIWORD(whiteRafting)}% returns 0
$EMPTY(), $EQUAL(), $EXISTS(), $EXACT(), $IF(), $ISDIGIT(), $ISLOWER(), $ISUPPER(), $PROPER(), $PROPERSPACE()
$LEFT( )
%CALC{$SUM($LEFT())}% returns the sum of cells to the left of the current cell
$ABOVE(), $RIGHT()
num of characters from the left end of text; the leftmost character is returned if num is missing
$LEFTSTRING( text, num )
%CALCULATE{$LEFTSTRING(abcdefg)}% returns a
%CALCULATE{$LEFTSTRING(abcdefg, 5)}% returns abcde
$BITXOR(), $FILTER(), $FIND(), $INSERTSTRING(), $RANDSTRING(), $REPLACE(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE()
$LENGTH( text )
%CALCULATE{$LENGTH(abcd)}% returns 4
$LISTSIZE()
$LIST( range )
%CALC{$LIST($LEFT())}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
$AVERAGE(), $COUNTITEMS(), $COUNTSTR(), $DEF(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTJOIN(), $LISTNONEMPTY(), $LISTRAND(), $LISTREVERSE(), $LISTSHUFFLE(), $LISTSIZE(), $LISTSORT(), $LISTTRUNCATE(), $LISTUNIQUE(), $MAX(), $MEDIAN(), $MIN(), $PRODUCT(), $SPLIT(), $SUM(), $SUMDAYS(), $SUMPRODUCT()
$GETHASH() or $HASH2LIST to retrieve hash values.
$LIST2HASH( name, list )
%CALCULATE{$LIST2HASH(age, Jane, 26, Tim, 27)}% sets key Jane of hash named age to 26, and key Tim to 27
$GET(), $GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $SET()
$item indicates the element, $index the index of the list, starting at 1. If $item is omitted, the item is appended to the formula. This function returns no output.
$LISTEACH( formula, list )
$LISTMAP( formula, list )
%CALCULATE{$LISTEACH($index: $EVAL(2 * $item), 3, 5, 7, 11)}% returns 1: 6, 2: 10, 3: 14, 4: 22
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTIF(), $LISTITEM(), $LISTNONEMPTY(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SPLIT(), $SUM(), $WHILE()
$IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1
$LISTIF( condition, list )
%CALCULATE{$LISTIF($item > 12, 14, 7, 25)}% returns 14, 25
%CALCULATE{$LISTIF($NOT($EXACT($item,)), A, B, , E)}% returns non-empty elements A, B, E
%CALCULATE{$LISTIF($index > 2, A, B, C, D)}% returns C, D
$EMPTY(), $EQUAL(), $EXACT(), $IF(), $LIST(), $LISTEACH(), $LISTITEM(), $LISTNONEMPTY(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SUM(), $WHILE()
$LISTITEM( index, list )
%CALCULATE{$LISTITEM(2, Apple, Orange, Apple, Kiwi)}% returns Orange
%CALCULATE{$LISTITEM(-1, Apple, Orange, Apple, Kiwi)}% returns Kiwi
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTNONEMPTY(), $LISTRAND(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SPLIT(), $SUM()
separator string, which may include $comma for comma, $n for newline, $sp for space, and $empty to join a list without a separator.
$LISTJOIN( separator, list )
%CALCULATE{$LISTJOIN($n, Apple, Orange, Apple, Kiwi)}% returns the four items separated by new lines
%CALCULATE{$LISTJOIN($empty, Apple, Orange, Apple, Kiwi)}% returns AppleOrangeAppleKiwi
$LIST(), $LISTNONEMPTY(), $LISTSIZE(), $SPLIT()
$LISTNONEMPTY( list )
%CALCULATE{$LISTNONEMPTY(, Apple, Orange, , Kiwi)}% returns Apple, Orange, Kiwi
$LISTEACH(), $LISTIF(), $LISTITEM(), $LISTSIZE(), $LISTUNIQUE()
$LISTRAND( list )
%CALCULATE{$LISTRAND(Apple, Orange, Apple, Kiwi)}% returns one of the four elements
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTSHUFFLE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $RAND(), $RANDSTRING(), $SUM()
$LISTREVERSE( list )
%CALCULATE{$LISTREVERSE(Apple, Orange, Apple, Kiwi)}% returns Kiwi, Apple, Orange, Apple
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SUM()
$LISTSHUFFLE( list )
%CALCULATE{$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)}% returns the four elements in random order
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTRAND(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $RAND(), $RANDSTRING(), $SUM()
$LISTSIZE( list )
%CALCULATE{$LISTSIZE(Apple, Orange, Apple, Kiwi)}% returns 4
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTJOIN(), $LISTREVERSE(), $LISTSORT(), $LISTTRUNCATE(), $LISTUNIQUE(), $SPLIT(), $SUM()
$LISTSORT( list )
%CALCULATE{$LISTSORT(Apple, Orange, Apple, Kiwi)}% returns Apple, Apple, Kiwi, Orange
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTREVERSE(), $LISTSHUFFLE(), $LISTSIZE(), $LISTUNIQUE(), $SUM()
$LISTTRUNCATE( size, list )
%CALCULATE{$LISTTRUNCATE(2, Apple, Orange, Kiwi)}% returns Apple, Orange
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SUM()
$LISTUNIQUE( list )
%CALCULATE{$LISTUNIQUE(Apple, Orange, Apple, Kiwi)}% returns Apple, Orange, Kiwi
$COUNTITEMS(), $COUNTSTR(), $LIST(), $LISTEACH(), $LISTIF(), $LISTITEM(), $LISTNONEMPTY(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $SUM()
$LN( num )
%CALCULATE{$LN(10)}% returns 2.30258509299405
$EXP(), $LOG()
$LOG( num, base )
%CALCULATE{$LOG(1000)}% returns 3
%CALCULATE{$LOG(16, 2)}% returns 4
$EXP(), $LN()
$LOWER(text)
%CALC{$LOWER( $T(R1:C5) )}% returns the lower case string of the text in cell R1:C5
$ISLOWER(), $PROPER(), $PROPERSPACE(), $TRIM(), $UPPER()
$MAX( list )
%CALC{$MAX($LEFT())}%
$LIST(), $MEDIAN(), $MIN(), $PERCENTILE(), $STDEV(), $STDEVP(), $VAR(), $VARP()
$MEDIAN( list )
%CALCULATE{$MEDIAN(3, 9, 4, 5)}% returns 4.5
$LIST(), $MAX(), $MIN(), $PERCENTILE(), $STDEV(), $STDEVP(), $VAR(), $VARP()
$MIN( list )
%CALCULATE{$MIN(15, 3, 28)}% returns 3
$LIST(), $MAX(), $MEDIAN(), $PERCENTILE(), $STDEV(), $STDEVP(), $VAR(), $VARP()
num by divisor $MOD( num, divisor )
%CALCULATE{$MOD(7, 3)}% returns 1
$EVAL(), $EVEN(), $ISDIGIT(), $ODD(), $SIGN()
$EXEC().
$NOEXEC( formula )
%CALCULATE{$SET(msg, $NOEXEC(Hi $GET(name)))}% sets the msg variable with the formula Hi $GET(name) without executing it
$EVAL(), $EXEC(), $GET(), $SET()
$percnt - changed to percent character '%'
$quot - changed to double quote character '"'
%SEARCH{...}%.
$NOP( text )
%CALCULATE{$NOP(%)SEARCH{...}$NOP(%)}% returns %SEARCH{...}%
%CALCULATE{$NOP($percntSEARCH{...}$percnt)}% returns %SEARCH{...}%
$NOTE()
num is not zero, 1 if zero
$NOT( num )
%CALCULATE{$NOT(0)}% returns 1
$AND(), $EMPTY(), $IF(), $OR(), $WHILE(), $XOR()
$NOTE( comment text )
%CALCULATE{$NOTE(abc)}% returns an empty string
$NOP()
$OCT2DEC( num )
%CALCULATE{$OCT2DEC(54)}% returns 44
$BIN2DEC(), $DEC2BIN(), $DEC2HEX(), $DEC2OCT(), $HEX2DEC(), $HEXDECODE(), $HEXENCODE()
$ODD( num )
%CALCULATE{$ODD(2)}% returns 0
$ABS(), $EVEN(), $ISDIGIT(), $MOD(), $SIGN()
$OR( list )
%CALCULATE{$OR(1, 0, 1)}% returns 1
$AND(), $IF(), $NOT(), $WHILE(), $XOR()
$PERCENTILE( num, list )
%CALCULATE{$PERCENTILE(75, 400, 200, 500, 100, 300)}% returns 450
$LIST(), $MAX(), $MEDIAN(), $MIN(), $STDEV(), $STDEVP(), $VAR(), $VARP()
$PI( )
%CALCULATE{$PI()}% returns 3.14159265358979
$PRODUCT( list )
$MULT( list )
%CALC{$PRODUCT($LEFT())}%
$LIST(), $PRODUCT(), $SUM(), $SUMPRODUCT()
$PROPER( text )
%CALCULATE{$PROPER(a small STEP)}% returns A Small Step
%CALCULATE{$PROPER(f1 (formula-1))}% returns F1 (Formula-1)
$FILTER(), $ISWIKIWORD(), $LOWER(), $PROPERSPACE(), $TRIM(), $UPPER()
][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE plugins setting are excluded
$PROPERSPACE( text )
%CALCULATE{$PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh)}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
$ISWIKIWORD(), $LOWER(), $PROPER(), $TRIM(), $UPPER()
max, or 0 and 1 if max is not specified
$RAND( max )
$EVAL(), $LISTRAND(), $LISTSHUFFLE(), $RANDSTRING()
set of characters; the set may contain sequences like a..z; default is a..zA..Z0..9_. The format defines the string length or the output format; specify a number to indicate the length of the random string; default is 8 characters. Alternatively, specify a format string with x as placeholders for random characters, such xxxx-xxxx-xxxx-xxxx.
$RANDSTRING( set, format )
%CALCULATE{$RANDSTRING()}% returns a random string with 8 characters composed of alphanumeric characters and underscores
%CALCULATE{$RANDSTRING(A..NP..Z1..9, xxxx-xxxx-xxxx-xxxx)}% returns four sets of random strings, separated by dashes, where each set has four characters composed of uppercase letters and numbers, excluding letter O and number 0
$INSERTSTRING(), $SUBSTRING(), $LISTRAND(), $LISTSHUFFLE(), $RAND(), $REPEAT()
$REPEAT( text, num )
%CALCULATE{$REPEAT(/\, 5)}% returns /\/\/\/\/\
$RANDSTRING(), $WHILE()
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
$REPLACE( text, start, num, new )
%CALCULATE{$REPLACE(abcdefghijk, 6, 5, *)}% returns abcde*k
$BITXOR(), $FILTER(), $FIND(), $INSERTSTRING(), $LEFTSTRING(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE()
$RIGHT( )
%CALC{$SUM($RIGHT())}% returns the sum of cells to the right of the current cell
$ABOVE(), $LEFT()
num of characters from the right end of text; the rightmost character is returned if num is missing
$RIGHTSTRING( text, num )
%CALCULATE{$RIGHTSTRING(abcdefg)}% returns g
%CALCULATE{$RIGHTSTRING(abcdefg, 5)}% returns cdefg
$BITXOR(), $FILTER(), $FIND(), $INSERTSTRING(), $LEFTSTRING(), $RANDSTRING(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE()
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
$ROUND( formula, digits )
%CALCULATE{$ROUND(3.15, 1)}% returns 3.2
%CALCULATE{$ROUND(3.149, 1)}% returns 3.1
%CALCULATE{$ROUND(-2.475, 2)}% returns -2.48
%CALCULATE{$ROUND(34.9, -1)}% returns 30
$CEILING(), $EVAL(), $FLOOR(), $INT(), $FORMAT()
$ROW( offset )
%CALC{$ROW(-2)}%
$COLUMN(), $T()
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
$SEARCH( string, text, start )
%CALCULATE{$SEARCH([uy], fluffy)}% returns 3
%CALCULATE{$SEARCH([uy], fluffy, 4)}% returns 6
%CALCULATE{$SEARCH([abc], fluffy,)}% returns 0
$FILTER(), $FIND(), $INSERTSTRING(), $LEFTSTRING(), $REPLACE(), $RIGHTSTRING(), $SUBSTRING()
$NOEXEC() if you want to prevent that. 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 and also across included topics. If the value is omitted, the named variable is deleted.
$SET( name, value )
%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
$EXEC(), $GET(), $GETHASH(), $HASH2LIST(), $LIST2HASH(), $NOEXEC(), $SETHASH(), $SETIFEMPTY(), $SETLIST(), SETM(), $SETMHASH(), $WHILE(), SetGetPlugin
$GETHASH() to retrieve hash values. If the value is omitted, the key is deleted from the hash. If the key is omitted, the named hash is deleted. If no parameters are specified, all hashes are deleted.
$SETHASH( name, key, value )
%CALCULATE{$SETHASH(age, Jane, 26)}% sets key Jane of hash named age to 26
%CALCULATE{$SETHASH(age, Jane,)}% sets key Jane of hash named age to an empty value
%CALCULATE{$SETHASH(age, Jane)}% deletes key Jane of hash named age
%CALCULATE{$SETHASH(age)}% deletes hash named age
%CALCULATE{$SETHASH()}% deletes all hashes
$GET(), $GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $SET(), $SETLIST(), $SETMHASH()
$SETIFEMPTY( name, value )
%CALCULATE{$SETIFEMPTY(result, default)}% sets the result variable to default if the variable is empty or 0; in any case an empty string is returned
$GET(), $SET(), $SETHASH(), $SETMHASH()
$GETLIST() to retrieve a list variable. Use $ADDLIST() to add a list to an existing variable. If no list is specified, the named variable is deleted.
$SETLIST( name, list )
%CALCULATE{$SETLIST(octals, 0, 1, 2, 3, 4, 5, 6, 7)}% sets the octals variable to 0, 1, 2, 3, 4, 5, 6, 7
%CALCULATE{$SETLIST(octals)}% deletes the octals variable
$ADDLIST(), $GETLIST(), $SET(), $SETHASH(), SetGetPlugin
+ (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
$SETM( name, formula )
%CALC{$SETM(total, + $SUM($LEFT()))}% adds the sum of all table cells on the left to the total variable, and returns an empty string
$GET(), $SET(), $SETHASH(), $SETIFEMPTY(), $SETMHASH(), $WHILE()
+ (add), - (subtract), * (multiply), or / (divide) something to the hash variable. This function returns no output. Use $GETHASH() or $HASH2LIST to retrieve the values
$SETMHASH( name, key, formula )
%CALCULATE{$SETHASH(count)}% deletes the count hash %CALCULATE{$SET(people, Anna, Jane, Berta, Charlie, Jane, Tom, Anna, Jane))}% sets the people list %CALCULATE{$LISTJOIN(, $LISTEACH($SETMHASH(count, $item, +1), $GET(people)))}% populates the count hash and returns nothing %CALCULATE{$HASH2LIST(count, $key: $value)}% returns Anna: 2, Berta: 1, Charlie: 1, Jane: 3, Tom: 1
$GET(), $GETHASH(), $HASH2LIST(), $HASHCOPY(), $HASHEACH(), $HASHEXISTS(), $HASHREVERSE(), $LIST2HASH(), $SET(), $SETHASH(), $WHILE()
num is negative, 0 if zero, or 1 if positive
$SIGN( num )
%CALCULATE{$SIGN(-12.5)}% returns -1
$ABS(), $EVAL(), $EVEN(), $INT(), $ISDIGIT(), $NOT(), $ODD()
text into a list using separator as a delimiter. The separator may be a regular expression and may include $comma for comma, $sp for space and $empty to split at each character. Default separator is one or more spaces ($sp$sp*).
$SPLIT( separator, text )
%CALCULATE{$SPLIT(, Apple Orange Kiwi)}% returns Apple, Orange, Kiwi
%CALCULATE{$SPLIT(-, Apple-Orange-Kiwi)}% returns Apple, Orange, Kiwi
%CALCULATE{$SPLIT([-:]$sp*, Apple-Orange: Kiwi)}% returns Apple, Orange, Kiwi (the separator means: Dash or colon, followed by optional spaces
%CALCULATE{$SPLIT($empty, Apple)}% returns A, p, p, l, e
$LIST(), $LISTJOIN(), $LISTSIZE()
$SQRT( num )
%CALCULATE{$SQRT(16)}% returns 4
list is a sample of the population. Use $STDEVP() if your data represents the entire population. The standard deviation is a measure of how widely values are dispersed from the average (mean) value.
$STDEV( list )
%CALC{$STDEV(R2:C5..R$ROW(-1):C5)}% returns the standard deviation of column 5, excluding the title row
%CALCULATE{$STDEV(3.50, 5.00, 7.23, 2.99)}% returns 1.90205152401295
$AVERAGE(), $LIST(), $MAX(), $MEDIAN(), $MIN(), $PERCENTILE(), $STDEVP(), $VAR(), $VARP()
list is the entire population. Use $STDEV() if your data represents a sample of the population. The standard deviation is a measure of how widely values are dispersed from the average (mean) value.
$STDEVP( list )
%CALC{$STDEVP(R2:C5..R$ROW(-1):C5)}% returns the standard deviation of column 5, excluding the title row
%CALCULATE{$STDEVP(3.50, 5.00, 7.23, 2.99)}% returns 1.64722493910213
$AVERAGE(), $LIST(), $MAX(), $MEDIAN(), $MIN(), $MAX(), $MIN(), $PERCENTILE(), $STDEV(), $VAR(), $VARP()
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
$SUBSTITUTE( text, old, new, instance, option )
%CALCULATE{$SUBSTITUTE(Good morning, morning, day)}% returns Good day
%CALCULATE{$SUBSTITUTE(Q2-2012, 2, 3)}% returns Q3-3013
%CALCULATE{$SUBSTITUTE(Q2-2012, 2, 3, 3)}% returns Q2-2013
%CALCULATE{$SUBSTITUTE(abc123def, [0-9], 9, , r)}% returns abc999def
$BITXOR(), $FILTER(), $HEXDECODE(), $HEXENCODE(), $INSERTSTRING(), $LEFTSTRING(), $RANDSTRING(), $REPLACE(), $RIGHTSTRING(), $SUBSTRING(), $TRANSLATE()
num number of characters of text string text, starting at start. Starting position is 1; use a negative start to count from the end of the text. All parameters are required - the text may contain commas.
$SUBSTRING( text, start, num )
%CALCULATE{$SUBSTRING(abcdefghijk, 3, 5)}% returns cdefg
$FILTER(), $FIND(), $INSERTSTRING(), $LEFTSTRING(), $RANDSTRING(), $REPLACE(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $TRANSLATE()
$SUM( list )
%CALC{$SUM(R2:C5..R$ROW(-1):C5)}% in the last row; or simply %CALC{$SUM($ABOVE())}%
$LIST(), $PRODUCT(), $SUMPRODUCT(), $WORKINGDAYS()
h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours
$SUMDAYS( list )
%CALCULATE{$SUMDAYS(2w, 1, 2d, 4h)}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
$SUM(), $TIME(), $FORMATTIME()
$SUMPRODUCT( list, list, list... )
%CALC{$SUMPRODUCT(R2:C1..R4:C1, R2:C5..R4:C5)}% evaluates and returns the result of ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
$LIST(), $PRODUCT(), $SUM()
$T( address )
%CALC{$T(R1:C5)}% returns the text in cell R1:C5
$COLUMN(), $ROW()
31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 31 Dec 2003 - 23:59; 31 Dec 2003 - 23:59:59; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. DOY (Day of Year) formats: DOY2003.365, DOY2003.365.23.59, DOY2003.365.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
$TIME( text )
%CALCULATE{$TIME(2003/10/14 GMT)}% returns 1066089600
$FORMATGMTIME(), $FORMATTIME(), $FORMATTIMEDIFF(), $TIMEADD(), $TIMEDIFF(), $TODAY(), $WORKINGDAYS()
unit is seconds if not specified; unit can be second, minute, hour, day, week, month, year. Note: An approximation is used for month and year calculations
$TIMEADD( serial, value, unit )
%CALCULATE{$TIMEADD($TIME(), 2, week)}% returns the serialized date two weeks from now
$FORMATTIME(), $FORMATGMTIME(), $TIME(), $TIMEDIFF(), $TODAY()
unit is seconds if not specified; unit can be specified as in $TIMEADD().
$ROUND() to round day unit to account for daylight savings time change. Use $FORMAT(), $FORMATTIMEDIFF() or $INT() to format real numbers
$TIMEDIFF( serial_1, serial_2, unit )
%CALCULATE{$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)}% returns 1.5
%CALCULATE{$ROUND($TIMEDIFF($TIME(2012-12-06),$TIME(2012-12-13), day))}% returns 7 (or 6.95833333333333 without the $ROUND())
$FORMAT(), $FORMATGMTIME(), $FORMATTIME(), $FORMATTIMEDIFF(), $INT(), $TIME(), $TIMEADD(), $TODAY(), $WORKINGDAYS()
$TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT
$TODAY( )
%CALCULATE{$TODAY()}% returns the number of seconds since Epoch
$FORMATTIME(), $FORMATGMTIME(), $TIME(), $TIMEADD(), $TIMEDIFF()
from a set to a set, one character by one. The text may contain commas; all three parameters are required. The from and to parameters support tokens $comma for comma, $sp for space, $quot for double quote, $aquot for apostrophe quote, and $n for newline
$TRANSLATE( text, from, to )
%CALCULATE{$TRANSLATE(boom,bm,cl)}% returns cool
%CALCULATE{$TRANSLATE(one, two,$comma,;)}% returns one; two
$BITXOR(), $FILTER(), $HEXDECODE(), $HEXENCODE(), $INSERTSTRING(), $LEFTSTRING(), $REPLACE(), $RIGHTSTRING(), $SUBSTRING(), $SUBSTITUTE()
$TRIM( text )
%CALCULATE{$TRIM( eat spaces )}% returns eat spaces
$EMPTY(), $EQUAL(), $EXACT(), $FILTER(), $ISWIKIWORD(), $PROPER(), $PROPERSPACE()
$UPPER( text )
%CALC{$UPPER($T(R1:C5))}% returns the upper case string of the text in cell R1:C5
$ISLOWER(), $ISUPPER(), $LOWER(), $PROPER(), $PROPERSPACE(), $TRIM()
text. Returns 0 if not found
$VALUE( text )
%CALCULATE{$VALUE(US$1,200)}% returns 1200
%CALCULATE{$VALUE(PrjNotebook1234)}% returns 1234
%CALCULATE{$VALUE(Total: -12.5)}% returns -12.5
$CEILING(), $EVAL(), $FLOOR(), $INT(), $ISDIGIT(), $ROUND()
list is a sample of the population. Use $VARP() if your data represents the entire population.
$VARP( list )
%CALC{$VAR(R2:C5..R$ROW(-1):C5)}% returns the variance of column 5, excluding the title row
%CALCULATE{$VAR(3.50, 5.00, 7.23, 2.99)}% returns 3.6178
$AVERAGE(), $LIST(), $MAX(), $MEDIAN(), $MIN(), $MAX(), $MIN(), $PERCENTILE(), $STDEV(), $STDEVP(), $VARP()
list is the entire population. Use $VAR() if your data represents a sample of the population.
$VARP( list )
%CALC{$VARP(R2:C5..R$ROW(-1):C5)}% returns the variance of column 5, excluding the title row
%CALCULATE{$VARP(3.50, 5.00, 7.23, 2.99)}% returns 2.71335
$AVERAGE(), $LIST(), $MAX(), $MEDIAN(), $MIN(), $MAX(), $MIN(), $PERCENTILE(), $STDEV(), $STDEVP(), $VAR()
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).
condition and do are evaluated in each cycle; a $counter starting at 1 can be used in condition and do.
$WHILE( condition, do something )
%CALCULATE{$WHILE($counter<=10, $counter )}% returns 1 2 3 4 5 6 7 8 9 10
%CALCULATE{$SET(i, 0) $WHILE($GET(i)<10, $SETM(i, +1) $EVAL($GET(i) * $GET(i)), )}% returns 1, 4, 9, 16, 25, 36, 49, 64, 81, 100,
$AND(), $EMPTY(), $EQUAL(), $EXACT(), $GET(), $IF(), $LISTIF(), $NOT(), $OR(), $SET(), $SETHASH(), $SETM(), $SETMHASH(), $REPEAT()
$WORKINGDAYS( serial_1, serial_2 )
%CALCULATE{$WORKINGDAYS($TIME(2012-07-15 GMT), $TIME(2012-08-03 GMT))}% returns 14
$SUMDAYS(), $TIME(), $TIMEDIFF()
$XOR( list )
%CALCULATE{$XOR(0, 0)}% returns 0
%CALCULATE{$XOR(0, 1)}% returns 1
%CALCULATE{$XOR(1, 0)}% returns 1
%CALCULATE{$XOR(1, 1)}% returns 0
%CALCULATE{$XOR(1, 0, 1)}% returns 0
$AND(), $BITXOR(), $IF(), $NOT(), $OR(), $WHILE()
% signs of %CALCULATE{...}% with $percnt. For example, to execute $IF($EXACT($formfield(Tested), Yes), %ICONURL{choice-yes}%, %ICONURL{choice-no}%) in the format="" parameter, write this:
%SEARCH{ .... format="| $topic | $percntCALCULATE{$IF($EXACT($formfield(Tested), Yes), %ICONURL{choice-yes}%, %ICONURL{choice-no}%)}$percnt |" }%
age may have first names as keys and ages as values. In TWiki's case you might do a FormattedSearch and store the result in hashes, then display the result in various formats. For example, you want to show feature requests in multiple tables, organized by status. Adding a search for each status is possible, but it can be slow. The page loads faster if you search only once, and store the status, summary, date and other fields in hashes. Then you use those hashes to render each table by status.
Example:
%CALCULATE{$SETHASH()}% <!-- clear all hashes -->
%SEARCH{
"form.name='FeatureForm'"
type="query"
nonoise="on"
format="$percntCALCULATE{$SETHASH(status, $topic, $formfield(Status))$SETHASH(summary, $topic, '''$summary''')$SETHASH(date, $topic, '''$date''')}$percnt"
}%
---++ Proposed Features
| *Feature* | *Updated* |
%CALCULATE{
$LISTJOIN(
$n,
$LISTEACH(
| [[$item]]: $GETHASH(summary, $item) | $GETHASH(date, $item) |,
$LISTIF(
$EXACT(
$GETHASH(status, $item),
Proposed
),
$GETHASH(status)
)
)
)
}%
---++ Accepted Features
| *Feature* | *Updated* |
%CALCULATE{
$LISTJOIN(
$n,
$LISTEACH(
| [[$item]]: $GETHASH(summary, $item) | $GETHASH(date, $item) |,
$LISTIF(
$EXACT(
$GETHASH(status, $item),
Accepted
),
$GETHASH(status)
)
)
)
}%
First we search all features and store the status, summary and date in hashes, using the topic name as the key. Then we build a table that shows all proposed features, followed by a table showing all accepted features. Reading the CALCULATE formula from inside out:
$GETHASH(status) - returns the list of all keys of the status hash, e.g. all topics found
$LISTIF($EXACT($GETHASH(status, $item), Proposed), ...) - filter the topic list and keeps only those of status Proposed
$LISTEACH(| [[$item]]: $GETHASH(summary, $item) | ... |, ...) - format each topic as a table row
$LISTJOIN($n, ...) - convert the comma-space list into lines separated by newlines
<!--
* Set MYFORMULA = $EVAL($SUBSTITUTE(...etc...))
-->
| A | 1 | %CALC{%MYFORMULA%}% |
| B | 2 | %CALC{%MYFORMULA%}% |
| C | 3 | %CALC{%MYFORMULA%}% |
| Bug#: | Priority: | Subject: | Status: | Days to fix |
|---|---|---|---|---|
| Bug:1234 | High | No arrange ... | Fixed | 1 |
| Bug:1232 | High | Memory Window ... | Fixed | 2 |
| Bug:1231 | Low | File Open ... | Open | 3 |
| Bug:1233 | Medium | Usability issue ... | Assigned | 5 |
| Total: 4 | High: 2 Low: 1 Medium: 1 |
. | Assigned: 1 Fixed: 2 Open: 1 |
Total: 11 |
| Total: %CALC{$ROW(-2)}% \
| %CALC{$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )}% | . \
| %CALC{$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )}% \
| Total: %CALC{$SUM( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )}% |
Above table is created manually. The table can be build dynamically with a formatted search, or by a plugin that pulls data from an external source, such as a bug tracking system.
%<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
"$SUM( $ABOVE() )" to TWiki tables or anywhere in topic text
data/debug.txt) %CALC{}% variable in included topic while including topic: (default: 1) (See note CALC in Included Topics) US$ or $ for Dollar, € for Euro, ¥ for Yen: $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable: SpreadSheetPlugin.zip in your twiki installation directory. Content: | File: | Description: |
|---|---|
data/TWiki/SpreadSheetPlugin.txt | Plugin topic |
data/TWiki/SpreadSheetPluginTestCases.txt | Test cases |
data/TWiki/VarCALC.txt | Documentation of the CALC variable |
data/TWiki/VarCALCULATE.txt | Documentation of the CALCULATE variable |
lib/TWiki/Plugins/SpreadSheetPlugin.pm | Plugin Perl module |
lib/TWiki/Plugins/SpreadSheetPlugin/Calc.pm | Plugin core module |
| Plugin Author: | TWiki:Main.PeterThoeny |
| Copyright: | © 2001-2018 Peter Thoeny, TWiki.org © 2008-2018 TWiki:TWiki.TWikiContributor © 2015 Wave Systems Corp. |
| Sponsor: | Wave Systems Corp. |
| License: | GPL (GNU General Public License |
| Plugin Version: | 2018-07-05 |
| 2018-07-05: | TWikibug:Item7841 |
| 2017-10-21: | TWikibug:Item7826 |
| 2017-10-19: | TWikibug:Item7640 |
| 2016-07-05: | TWikibug:Item7746 |
| 2016-05-10: | TWikibug:Item7703 |
| 2016-01-08: | TWikibug:Item7708 |
| 2015-06-07: | TWikibug:Item7656 |
| 2015-05-18: | TWikibug:Item7656 |
| 2015-02-24: | TWikibug:Item7617 |
| 2015-01-14: | TWikibug:Item7607 |
| 2015-01-09: | TWikibug:Item7604 |
| 2015-01-07: | TWikibug:Item7583 |
| 2014-10-23: | TWikibug:Item7583 |
| 2014-09-23: | TWikibug:Item7553 |
| 2014-09-22: | TWikibug:Item7552 |
| 2014-03-04: | TWikibug:Item7445 |
| 2014-01-22: | TWikibug:Item7419 |
| 2014-01-22: | TWikibug:Item7418 |
| 2013-10-10: | TWikibug:Item7154 |
| 2013-09-14: | TWikibug:Item7299 |
| 2013-08-21: | TWikibug:Item7322 |
| 2013-07-18: | TWikibug:Item7299 |
| 2013-06-20: | TWikibug:Item7154$IF(1>2, true, false) works properly |
| 2013-05-21: | TWikibug:Item7154 |
| 2013-04-09: | TWikibug:Item7221 |
| 2013-04-07: | TWikibug:Item7218 |
| 2013-03-26: | TWikibug:Item7203 |
| 2013-03-25: | TWikibug:Item7199 |
| 2013-03-24: | TWikibug:Item7199 |
| 2013-03-23: | TWikibug:Item7199 |
| 2013-03-21: | TWikibug:Item7199 |
| 2013-03-14: | TWikibug:Item7196 |
| 2013-03-14: | TWikibug:Item7190 |
| 2013-03-11: | TWikibug:Item7184 |
| 2013-01-09: | TWikibug:Item7091 |
| 2012-11-11: | TWikibug:Item7020 |
| 2012-11-05: | TWikibug:Item7023 |
| 2012-11-03: | TWikibug:Item7018 |
| 2012-10-06: | TWikibug:Item6960 |
| 2012-06-30: | TWikibug:Item6898 |
| 2012-06-29: | TWikibug:Item6897 |
| 2012-04-04: | TWikibug:Item6866 |
| 2012-01-13: | TWikibug:Item6804 |
| 2011-09-07: | TWikibug:Item6803 |
| 2011-07-09: | TWikibug:Item6725 |
| 2011-04-25: | TWikibug:Item6690 |
| 2011-04-08: | TWikibug:Item6681 |
| 2011-04-06: | TWikibug:Item6679 |
| 2011-03-25: | TWikibug:Item6669 |
| 2011-03-24: | TWikibug:Item6668 TWikibug:Item6667 |
| 2011-03-22: | TWikibug:Item6666 |
| 2010-08-27: | TWikibug:Item6526 |
| 2010-08-04: | TWikibug:Item6537 |
| 2010-07-17: | TWikibug:Item6525 |
| 2010-05-27: | TWikibug:Item6506 |
| 2010-05-26: | TWikibug:Item6504 |
| 2010-06-25: | TWikibug:Item6493 TWikibug:Item5163 |
| 2010-05-22: | TWikibug:Item6472 |
| 2010-05-15: | TWikibug:Item6433 |
| 2010-02-27: | Doc improvements |
| 2009-11-22: | Enhanced $NOP(): Added $quot replacement for quote character, changed $per replacement with $percnt, contributed by TWiki:Main/HorstEsser |
| 09 May 2009: | Fixed bug in $WORKINGDAYS(): Incorrect number of days if daylight savings time change happens between start date and end date |
| 26 Mar 2009: | Added $INSERTSTRING() |
| 25 Mar 2009: | Added $EMPTY(), $LEFTSTRING(), $RIGHTSTRING(), $SUBSTRING() |
| 24 Mar 2009: | Fixed bug in $REPLACE() if to-be-replaced string is "0"; fixed bug in $SUBSTITUTE() if replace string is empty; improved docs |
| 13 Oct 2007: | Added $FORMATTIMEDIFF() |
| 09 Sep 2007: | Enhanced documentation for $EVAL() and $INT() |
| 02 Jun 2007: | Added VarCALC to have %CALC{}% listed in TWikiVariables |
| 14 Apr 2007: | Fixing bug in $EXISTS() that required full web.topic instead of just topic |
| 11 Mar 2007: | Fixing bug in $VALUE() and $INT(), introduced by version 09 Mar 2007 |
| 09 Mar 2007: | Added $EXP(), $LN(), $LOG(), $PI(), $SQRT(); fixed $ROUND() bug, contributed by TWiki:Main/SergejZnamenskij |
| 23 Jan 2007: | Enhanced documentation |
| 18 Dec 2006: | Added $LISTRAND(), $LISTSHUFFLE(), $LISTTRUNCATE(); fixed spurious newline at end of topic, contributed by TWiki:Main/MichaelDaum |
| 10 Oct 2006: | Enhanced documentation |
| 13 May 2006: | Added $SETIFEMPTY(); fixes in documentation |
| 17 Jun 2005: | Added $NOEXEC(), $EXEC() |
| 25 Mar 2005: | Fixed evaluation bug when using SpeedyCGI accelerator; code refactor to load module only when needed, contributed by TWiki:Main/CrawfordCurrie |
| 24 Oct 2004: | Added $EXISTS(), contributed by TWiki:Main/RodrigoChandia |
| 18 Oct 2004: | Added $LISTJOIN() |
| 26 Sep 2004: | Added $FORMAT(KB), $FORMAT(MB), contributed by TWiki:Main/ArthurClemens |
| 17 Jul 2004: | Added $WORKINGDAYS(), contributed by TWiki:Main/CrawfordCurrie |
| 24 May 2004: | Refactored documentation (no code changes) |
| 03 Apr 2004: | Added $ABS(), $LISTIF(); fixed $VALUE() to remove leading zeros; changed $FIND() and $SEARCH() to return 0 instead of empty string if no match |
| 21 Mar 2004: | Added $LISTITEM(); fixed call to unofficial function |
| 16 Mar 2004: | Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning |
| 08 Mar 2004: | Added $LIST() |
| 06 Mar 2004: | Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented |
| 27 Feb 2004: | Added $COUNTUNIQUE() |
| 24 Oct 2003: | Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow |
| 21 Oct 2003: | Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday |
| 14 Oct 2003: | Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF() |
| 13 Oct 2003: | Added $MULT(), contributed by TWiki:Main/GerritJanBaarda |
| 30 Jul 2003: | Added $TRANSLATE() |
| 19 Jul 2003: | Added $FIND(), $NOP(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), contributed by TWiki:Main/PaulineCheung |
| 19 Apr 2003: | Added $COUNTSTR(), $EXACT(), $IF(), $ROUND(), $TRIM(); added $FORMAT(), contributed by TWiki:Main/JimStraus% modulus operator in $EVAL(), $INT(), and $ROUND(); fixed bug in $DEF() |
| 07 Jun 2002: | Added $DEF(), contributed by TWiki:Main/MartinFuzzey<u>102</u>, suggested by TWiki:Main/GladeDiviney |
| 12 Mar 2002: | Support for multiple functions per nesting level |
| 15 Jan 2002: | Added $CHAR(), $CODE() and $LENGTH() |
| 12 Nov 2001: | Added $RIGHT() |
| 12 Aug 2001: | Fixed bug of disappearing multi-column cells |
| 19 Jul 2001: | Fixed incorrect $SUM() calculation of cell with value 0 |
| 14 Jul 2001: | Changed to plug & play |
| 01 Jun 2001: | Fixed insecure dependencies for $MIN() and $MAX() |
| 16 Apr 2001: | Fixed div by 0 bug in $AVERAGE() |
| 17 Mar 2001: | Initial version with $ABOVE(), $AVERAGE(), $COLUMN(), $COUNTITEMS(), $EVAL(), $INT(), $LEFT(), $LOWER(), $MAX(), $MIN(), $ROW(), $SUM(), $T(), $UPPER() |
| CPAN Dependencies: | none |
| Plugin Benchmarks |
GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95% |
| Other Dependencies: | none |
| Perl Version: | 5.000 and up |
| Plugin Home: | http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin |
| Feedback: | http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev |
| Appraisal: | http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginAppraisal |