%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
120 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)}%
R1:C1
. Table address matrix:
|
|||||||||
".."
, 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.
Use %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()
$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()
, $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
$EXACT()
, $IF()
, $ISDIGIT()
, $ISLOWER()
, $ISUPPER()
, $ISWIKIWORD()
, $TRIM()
, $WHILE()
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
$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
$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
DOLLAR
for Dollar format, such as $12,345.68
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(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 number. These variables are expanded in format
: $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()
, $LIST2HASH()
, $HASH2LIST()
, $NOEXEC()
, $SET()
, $SETHASH()
, $SETIFEMPTY()
, $SETM()
, $SETMHASH()
, $WHILE()
, TWiki:Plugins.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()
, $HASH2LIST()
, $HASHCOPY()
, $HASHEACH()
, $HASHEXISTS()
, $HASHREVERSE()
, $LIST2HASH()
, $SET()
, $SETHASH()
, $SETMHASH()
$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, 27)}%
%CALCULATE{$HASHREVERSE(age)}%
reverses the hash and returns nothing %CALCULATE{$HASH2LIST(age, $key: $value)}%
returns 26: Jane, 27: Tim
$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()
, $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()
, $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()
, $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()
, $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()
, $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()
, $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()
, $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 )
%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()
, $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()
, $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()
, $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()
%SEARCH{}%
is evaluated. The percent character '%' can be escaped with $percnt
. The quote character '"' can be escaped with $quot
.
$NOP( text )
num
is not zero, 1 if zero
$NOT( num )
%CALCULATE{$NOT(0)}%
returns 1
$AND()
, $EMPTY()
, $IF()
, $OR()
, $WHILE()
, $XOR()
$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 )
%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()
$REPEAT( text, num )
%CALCULATE{$REPEAT(/\, 5)}%
returns /\/\/\/\/\
$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()
, $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
$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()
, SETM()
, $SETMHASH()
, $WHILE()
, TWiki:Plugins.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()
, $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()
+
(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()
, $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()
, $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()
, $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()
, $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(entityencode))$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%}% |
|
|||||||||||||||||||||||||||||||
| 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) $PROPERSPACE(text)
function. This comma delimited list can be overloaded by a DONTSPACE preferences variable: SpreadSheetPlugin.zip
in your twiki installation directory. Content:
|
|||||||||||||||
|
|||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||