From 03b393ca9e36f11c47d20625e2e6367bb7ae55a7 Mon Sep 17 00:00:00 2001 From: PeterThoeny Date: Tue, 25 May 2004 06:34:39 +0000 Subject: [PATCH 1/1] none --- TWiki/SpreadSheetPlugin.mdwn | 922 ++++++++++++++++++++++++++++++------------- 1 file changed, 653 insertions(+), 269 deletions(-) diff --git a/TWiki/SpreadSheetPlugin.mdwn b/TWiki/SpreadSheetPlugin.mdwn index b02a370..c9baf67 100644 --- a/TWiki/SpreadSheetPlugin.mdwn +++ b/TWiki/SpreadSheetPlugin.mdwn @@ -1,4 +1,4 @@ -# TWiki Spreadsheet Plugin +# TWiki Spreadsheet Plugin This Plugin adds speadsheet capabilities to %WIKITOOLNAME% 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. @@ -42,22 +42,92 @@ This Plugin adds speadsheet capabilities to %WIKITOOLNAME% topics. Formulae like       Interactive example:

-
Formula: %CALC{""}%  
Result:     admin

-

-

+ Formula: %CALC{""}%  
Result:     admin

- -

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.)

-

-

- + 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.) +
+ +
+ ## 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. @@ -88,264 +158,574 @@ The action of this Plugin is triggered by the **%CALC\{"..."\}%** v ## Built-in Functions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function Description
"$ABOVE()" The address range of cells above the current cell
"$ABS(num)" The absolute value of a number. Example: %CALC{"$ABS(-12.5)"}% returns 12.5
"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
"$COUNTSTR(list, str)" Counts 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. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_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. Examples: %BR% %CALC{"$FIND(f, fluffy)"}% returns 1 %BR% %CALC{"$FIND(f, fluffy, 2)"}% returns 4 %BR% %CALC{"$FIND(@, fluffy, 1)"}% returns 0
"$FORMAT(type, prec, number)" Formats a number to a certain type and precision. Types with examples:
  - %CALC{"$FORMAT( COMMA, 2, 12345.6789 )"}% returns 12,345.68
  - %CALC{"$FORMAT( DOLLAR, 2, 12345.67 )"}% returns $12,345.68
  - %CALC{"$FORMAT( NUMBER, 1, 12345.67 )"}% returns 12345.7
  - %CALC{"$FORMAT( PERCENT, 1, 0.1234567 )"}% returns 12.3%
"$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. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
"$FORMATGMTIME(serial, text)" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
"$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. See also $SET(). Example: %CALC{"$GET(my_total)"}% returns the value of the my_total variable
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. 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). Examples:%BR% %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK)"}% returns Over Budget if value in R1:C5 is over 1000, OK if not%BR% %CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2))"}% returns the content of R1:C2 or empty if empty%BR% %CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2)))"}% sets a variable conditionally
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT(10 / 4)"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
"$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. Examples: %BR% %CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25 %BR% %CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E %BR% %CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D
"$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. Examples:%BR% %CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange %BR% %CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$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. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
"$LISTUNIQUE(list)" Removes all duplicates from a list. Example: %CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi
"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
"$MIN(list)" The smallest value of a list or range of cells. Example: %CALC{"$MIN(15, 3, 28)"}% returns 3
"$MOD(num, divisor)" The reminder after dividing num by divisor. Example: %CALC{"$MOD(7, 3)"}% returns 1
"$NOP(text)" A no-operation. Allows one to defy the order of Plugin execution. For example, it will allow preprossing to be done before %SEARCH{}% is evaluated. Use $per to escape '%'.
"$NOT(num)" The reverse logic of a number. Returns 0 if num is not zero, 1 if zero. Example: %CALC{"$NOT(0)"}% returns 1
"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:%BR% %CALC{"PROPER(a small STEP)"}% returns A Small Step %BR% %CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out [[TWiki/WikiWords]] preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE [[TWiki/TWikiPreferences]] variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example: %BR% %CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" 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. Examples: %BR% %CALC{"$ROUND(3.15, 1)"}% returns 3.2 %BR% %CALC{"$ROUND(3.149, 1)"}% returns 3.1 %BR% %CALC{"$ROUND(-2.475, 2)"}% returns -2.48 %BR% %CALC{"$ROUND(34.9, -1)"}% returns 30
"$ROW(offset)" The current row number with an 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)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a [[TWiki/RegularExpression]] search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched. Examples: %BR% %CALC{"$SEARCH([uy], fluffy)"}% returns 3 %BR% %CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6 %BR% %CALC{"$SEARCH([abc], fluffy,)"}% returns 0
"$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. See also $GET(). 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
"$SETM(name, formula)" Updates 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. 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
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
"$SUBSTITUTE(text, old, new, instance, option)" 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 [[TWiki/RegularExpression]] search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples: %BR% %CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day %BR% %CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003 %BR% %CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003 %BR% %CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. 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() )"}%
"$SUMDAYS(list)" The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours. Example: %CALC{"$SUMDAYS( 2w, 1, 2d, 4h )"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
"$SUMPRODUCT(list, list, ...)" The scalar product on ranges of cells. Example: %CALC{"$SUM( R2:C1..R4:C1, R2:C5..R4:C5 )"}% evaluates and returns ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
"$T(address)" The content of a cell. Example: %CALC{"$T(R1:C5)"}% returns the text in cell R1:C5
"$TRANSLATE(text, from, to)" Translate text from a set of characters to another set, one character by one. The text may contain commas; the last two comma separated parameters are required. For from and to parameters, you can write $comma to escape comma, $sp to escape space. See also $REPLACE(), $SUBSTITUTE(). Examples: %BR% %CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool %BR% %CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
"$TIME(text)" Converts a date string into a serialized date number (seconds since the Epoch, e.g. midnight, 01 Jan 1970). Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 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. Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TIME( 2003/10/14 GMT )"}% returns 1066089600
"$TIMEADD( serial, value, unit )" Add a value to a serialized date. The 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. See also $TIME(), $TIMEDIFF(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEADD( $TIME(), 2, week )"}% returns the serialized date two weeks from now
"$TIMEDIFF( serial_1, serial_2, unit )" Time difference between two serialized dates. The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers. See also $TIME(), $TIMEADD(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEDIFF( $TIME(), $EVAL($TIME()+90), minute )"}% returns 1.5
"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:%BR% %CALC{"$VALUE(US$1,200)"}% returns 1200 %BR% %CALC{"$VALUE(PrjNotebook1234)"}% returns 1234 %BR% %CALC{"$VALUE(Total: -12.5)"}% returns -12.5
+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()|Main/WebHome#FuncLEFT]], [[$RIGHT()|Main/WebHome#FuncRIGHT]] + + + +### ABS( num ) -- absolute value of a number + +- Syntax: **$ABS( num )** +- Example: **%CALC\{"$ABS(-12.5)"\}%** returns **12\.5** +- Related: [[$SIGN()|Main/WebHome#FuncSIGN]] + + + +### AND( list ) -- logcial AND of a list + +- Syntax: **$AND( list )** +- Example: **%CALC\{"$AND(1, 0, 1)"\}%** returns **** +- Related: [[$NOT()|Main/WebHome#FuncNOT]], [[$IF()|Main/WebHome#FuncIF]], [[$OR()|Main/WebHome#FuncOR]] + + + +### 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()|Main/WebHome#FuncLIST]], [[$MAX()|Main/WebHome#FuncMAX]], [[$MEDIAN()|Main/WebHome#FuncMEDIAN]], [[$MIN()|Main/WebHome#FuncMIN]] + + + +### CHAR( number ) -- ASCII character represented by number + +- Syntax: **$CHAR( number )** +- Example: Example: **%CALC\{"$CHAR(97)"\}%** returns **a** +- Related: [[$CODE()|Main/WebHome#FuncCODE]] + + + +### 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()|Main/WebHome#FuncCHAR]] + + + +### 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()|Main/WebHome#FuncROW]], [[$T()|Main/WebHome#FuncT]] + + + +### 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()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]] + + + +### 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()|Main/WebHome#FuncCOUNTITEMS]], [[$LIST()|Main/WebHome#FuncLIST]] + + + +### 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()|Main/WebHome#FuncCOUNTSTR]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LIST()|Main/WebHome#FuncLIST]] + + + +### 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()|Main/WebHome#FuncINT]], [[$MOD()|Main/WebHome#FuncMOD]], [[$ROUND()|Main/WebHome#FuncROUND]], [[$VALUE()|Main/WebHome#FuncVALUE]] + + + +### EXACT( text1, text2 ) -- compare two text strings + +- Compares two text strings and returns **1** if they are exactly the same, or **** if not +- Syntax: **$EXACT( text1, _text2_ )** +- Example: **%CALC\{"$EXACT(foo, Foo)"\}%** returns **** +- Example: **%CALC\{"$EXACT(foo, $LOWER(Foo))"\}%** returns **1** +- Related: [[$IF()|Main/WebHome#FuncIF]], [[$TRIM()|Main/WebHome#FuncTRIM]] + + + +### 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 **** +- Related: [[$REPLACE()|Main/WebHome#FuncREPLACE]], [[$SEARCH()|Main/WebHome#FuncSEARCH]] + + + +### 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()|Main/WebHome#FuncROUND]] + + + +### 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()|Main/WebHome#FuncFORMATGMTIME]], [[$TIME()|Main/WebHome#FuncTIME]], [[$TIMEADD()|Main/WebHome#FuncTIMEADD]], [[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]], [[$TODAY()|Main/WebHome#FuncTODAY]] + + + +### 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()|Main/WebHome#FuncFORMATTIME]], [[$TIME()|Main/WebHome#FuncTIME]], [[$TIMEADD()|Main/WebHome#FuncTIMEADD]], [[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]], [[$TODAY()|Main/WebHome#FuncTODAY]] + + + +### 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()|Main/WebHome#FuncSET]], [[$SETM()|Main/WebHome#FuncSETM]] + + + +### IF( condition, value if true, value if 0 ) -- return a value based on a condition + +- The condition can be a number (where **** 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()|Main/WebHome#FuncAND]], [[$EXACT()|Main/WebHome#FuncEXACT]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$NOT()|Main/WebHome#FuncNOT]], [[$OR()|Main/WebHome#FuncOR]] + + + +### 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()|Main/WebHome#FuncEVAL]], [[$ROUND()|Main/WebHome#FuncROUND]], [[$VALUE()|Main/WebHome#FuncVALUE]] + + + +### 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()|Main/WebHome#FuncABOVE]], [[$RIGHT()|Main/WebHome#FuncRIGHT]] + + + +### LENGTH( text ) -- length of text in bytes + +- Syntax: **$LENGTH( text )** +- Example: **%CALC\{"$LENGTH(abcd)"\}%** returns **4** +- Related: [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]] + + + +### 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()|Main/WebHome#FuncAVERAGE]], [[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$DEF()|Main/WebHome#FuncDEF]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$MAX()|Main/WebHome#FuncMAX]], [[$MEDIAN()|Main/WebHome#FuncMEDIAN]], [[$MIN()|Main/WebHome#FuncMIN]], [[$PRODUCT()|Main/WebHome#FuncPRODUCT]], [[$SUM()|Main/WebHome#FuncSUM]], [[$SUMDAYS()|Main/WebHome#FuncSUMDAYS]], [[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]] + + + +### LISTIF( condition, list ) -- remove elements from a list that do not meet a condition + +- In addition to the condition described in [[$IF()|Main/WebHome#FuncIF]], 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()|Main/WebHome#FuncIF]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### 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()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### 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()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### LISTREVERSE( list ) -- opposite order of a list + +- Syntax: **$LISTREVERSE( list )** +- Example: **%CALC\{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"\}%** returns **Kiwi, Apple, Orange, Apple** +- Related: [[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### LISTSIZE( list ) -- number of elements in a list + +- Syntax: **$LISTSIZE( list )** +- Example: **%CALC\{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"\}%** returns **4** +- Related: [[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### 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()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### LISTUNIQUE( list ) -- remove all duplicates from a list + +- Syntax: **$LISTUNIQUE( list )** +- Example: **%CALC\{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"\}%** returns **Apple, Orange, Kiwi** +- Related: [[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]], [[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]], [[$LIST()|Main/WebHome#FuncLIST]], [[$LISTIF()|Main/WebHome#FuncLISTIF]], [[$LISTITEM()|Main/WebHome#FuncLISTITEM]], [[$LISTMAP()|Main/WebHome#FuncLISTMAP]], [[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]], [[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]], [[$LISTSORT()|Main/WebHome#FuncLISTSORT]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### LOWER( text ) -- lower case string of a text + +- Syntax: **$LOWER(text)** +- Example: **%CALC\{"$LOWER( $T(R1:C5) )"\}%** returns the lower case string of the text in cell **R1:C5** +- Related: [[$PROPER()|Main/WebHome#FuncPROPER]], [[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]], [[$TRIM()|Main/WebHome#FuncTRIM]], [[$UPPER()|Main/WebHome#FuncUPPER]] + + + +### 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()|Main/WebHome#FuncLIST]], [[$MEDIAN()|Main/WebHome#FuncMEDIAN]], [[$MIN()|Main/WebHome#FuncMIN]] + + + +### 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()|Main/WebHome#FuncLIST]], [[$MAX()|Main/WebHome#FuncMAX]], [[$MIN()|Main/WebHome#FuncMIN]] + + + +### MIN( list ) -- smallest value of a list or range of cells + +- Syntax: **$MIN( list )** +- Example: **%CALC\{"$MIN(15, 3, 28)"\}%** returns **3** +- Related: [[$LIST()|Main/WebHome#FuncLIST]], [[$MAX()|Main/WebHome#FuncMAX]], [[$MEDIAN()|Main/WebHome#FuncMEDIAN]] + + + +### MOD( num, divisor ) -- reminder after dividing **num** by **divisor** + +- Syntax: **$MOD( num, divisor )** +- Example: **%CALC\{"$MOD(7, 3)"\}%** returns **1** +- Related: [[$EVAL()|Main/WebHome#FuncEVAL]], [[$()|Main/WebHome#Func]] + + + +### 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()|Main/WebHome#FuncAND]], [[$IF()|Main/WebHome#FuncIF]], [[$OR()|Main/WebHome#FuncOR]] + + + +### OR( list ) -- logcial OR of a list + +- Syntax: **$OR( list )** +- Example: **%CALC\{"$OR(1, 0, 1)"\}%** returns **1** +- Related: [[$AND()|Main/WebHome#FuncAND]], [[$IF()|Main/WebHome#FuncIF]], [[$NOT()|Main/WebHome#FuncNOT]] + + + +### 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()|Main/WebHome#FuncLIST]], [[$PRODUCT()|Main/WebHome#FuncPRODUCT]], [[$SUM()|Main/WebHome#FuncSUM]], [[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]] + + + +### 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()|Main/WebHome#FuncLOWER]], [[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]], [[$TRIM()|Main/WebHome#FuncTRIM]], [[$UPPER()|Main/WebHome#FuncUPPER]] + + + +### 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()|Main/WebHome#FuncLOWER]], [[$PROPER()|Main/WebHome#FuncPROPER]], [[$TRIM()|Main/WebHome#FuncTRIM]], [[$UPPER()|Main/WebHome#FuncUPPER]] + + + +### 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()|Main/WebHome#FuncEVAL]] + + + +### 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()|Main/WebHome#FuncFIND]], [[$SEARCH()|Main/WebHome#FuncSEARCH]], [[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]], [[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]] + + + +### 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()|Main/WebHome#FuncABOVE]], [[$LEFT()|Main/WebHome#FuncLEFT]] + + + +### 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()|Main/WebHome#FuncINT]], [[$FORMAT()|Main/WebHome#FuncFORMAT]] + + + +### 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()|Main/WebHome#FuncCOLUMN]], [[$T()|Main/WebHome#FuncT]] + + + +### 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 **** +- Related: [[$FIND()|Main/WebHome#FuncFIND]], [[$REPLACE()|Main/WebHome#FuncREPLACE]] + + + +### 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()|Main/WebHome#FuncGET]], [[SETM()|Main/WebHome#FuncSETM]] + + + +### 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()|Main/WebHome#FuncGET]], [[$SET()|Main/WebHome#FuncSET]] + + + +### 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()|Main/WebHome#FuncABS]], [[$EVAL()|Main/WebHome#FuncEVAL]], [[$INT()|Main/WebHome#FuncINT]], [[$NOT()|Main/WebHome#FuncNOT]] + + + +### 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()|Main/WebHome#FuncREPLACE]], [[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]] + + + +### 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())"\}%** +- Related: [[$LIST()|Main/WebHome#FuncLIST]], [[$PRODUCT()|Main/WebHome#FuncPRODUCT]], [[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]] + + + +### SUMDAYS( list ) -- sum the days in a list or range of cells + +- The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a **h**, **hours**, **d**, **days**, **w**, **weeks** suffix. One week is assumed to have 5 working days, one day 8 hours +- Syntax: **$SUMDAYS( list )** +- Example: **%CALC\{"$SUMDAYS(2w, 1, 2d, 4h)"\}%** returns **13\.5**, the evaluation of `(2*5 + 1 + 2 + 4/8)` +- Related: [[$SUM()|Main/WebHome#FuncSUM]], [[$TIME()|Main/WebHome#FuncTIME]], [[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]] + + + +### SUMPRODUCT( list, list ) -- scalar product on ranges of cells + +- Syntax: **$SUMPRODUCT( list, list, _list..._ )** +- Example: **%CALC\{"$SUM(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))** +- Related: [[$LIST()|Main/WebHome#FuncLIST]], [[$PRODUCT()|Main/WebHome#FuncPRODUCT]], [[$SUM()|Main/WebHome#FuncSUM]] + + + +### T( address ) -- content of a cell + +- Syntax: **$T( address )** +- Example: **%CALC\{"$T(R1:C5)"\}%** returns the text in cell **R1:C5** +- Related: [[$COLUMN()|Main/WebHome#FuncCOLUMN]], [[$ROW()|Main/WebHome#FuncROW]] + + + +### TRANSLATE( text, from, to ) -- translate text from one set of characters to another + +- The translation is done `from` a set `to` a set, one character by one. The `text` may contain commas; all three parameters are required. In the `from` and `to` parameters you can write `$comma` to escape comma, `$sp` to escape space +- Syntax: **$TRANSLATE( text, from, to )** +- Example: **%CALC\{"$TRANSLATE(boom,bm,cl)"\}%** returns **cool** +- Example: **%CALC\{"$TRANSLATE(one, two,$comma,;)"\}%** returns **one; two** +- Related: [[$REPLACE()|Main/WebHome#FuncREPLACE]], [[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]] + + + +### TIME( text ) -- convert a date string into a serialized date number + +- Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: `31 Dec 2009`; `31 Dec 2009 GMT`; `31 Dec 09`; `31-Dec-2009`; `31/Dec/2009`; `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`. Date is assumed to be server time; add `GMT` to indicate Greenwich time zone +- Syntax: **$TIME( _text_ )** +- Example: **%CALC\{"$TIME(2003/10/14 GMT)"\}%** returns **1066089600** +- Related: [[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]], [[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]], [[$TIMEADD()|Main/WebHome#FuncTIMEADD]], [[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]], [[$TODAY()|Main/WebHome#FuncTODAY]] + + + +### TIMEADD( serial, value, unit ) -- add a value to a serialized date + +- The 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 +- Syntax: **$TIMEADD( serial, value, _unit_ )** +- Example: **%CALC\{"$TIMEADD($TIME(), 2, week)"\}%** +- Related: [[$()|Main/WebHome#Func]], [[$()|Main/WebHome#Func]] returns the serialized date two weeks from now +- Related: [[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]], [[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]], [[$TIME()|Main/WebHome#FuncTIME]], [[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]], [[$TODAY()|Main/WebHome#FuncTODAY]] + + + +### TIMEDIFF( serial\_1, serial\_2, unit ) -- time difference between two serialized dates + +- The unit is seconds if not specified; unit can be specified as in `$TIMEADD()`. Note: An approximation is used for month and year calculations. Use `$FORMAT()` or `$INT()` to format real numbers +- Syntax: **$TIMEDIFF( serial\_1, serial\_2, _unit_ )** +- Example: **%CALC\{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"\}%** returns **1\.5** +- Related: [[$FORMAT()|Main/WebHome#FuncFORMAT]], [[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]], [[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]], [[$INT()|Main/WebHome#FuncINT]], [[$TIME()|Main/WebHome#FuncTIME]], [[$TIMEADD()|Main/WebHome#FuncTIMEADD]], [[$TODAY()|Main/WebHome#FuncTODAY]] + + + +### TODAY( ) -- serialized date of today at midnight GMT + +- In contrast, the related `$TIME()` returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT +- Syntax: **$TODAY( )** +- Example: **%CALC\{"$TODAY()"\}%** returns the number of seconds since Epoch +- Related: [[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]], [[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]], [[$TIME()|Main/WebHome#FuncTIME]], [[$TIMEADD()|Main/WebHome#FuncTIMEADD]], [[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]] + + + +### TRIM( text ) -- trim spaces from text + +- Removes all spaces from text except for single spaces between words +- Syntax: **$TRIM( text )** +- Example: **%CALC\{"$TRIM( eat  spaces  )"\}%** returns **eat spaces** +- Related: [[$EXACT()|Main/WebHome#FuncEXACT]], [[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]] + + + +### UPPER( text ) -- upper case string of a text + +- Syntax: **$UPPER( text )** +- Example: **%CALC\{"$UPPER($T(R1:C5))"\}%** returns the upper case string of the text in cell **R1:C5** +- Related: [[$LOWER()|Main/WebHome#FuncLOWER]], [[$PROPER()|Main/WebHome#FuncPROPER]], [[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]], [[$TRIM()|Main/WebHome#FuncTRIM]] + + + +### VALUE( text ) -- convert text to number + +- Extracts a number from **text**. Returns **** if not found +- Syntax: **$VALUE( text )** +- Example: **%CALC\{"$VALUE(US$1,200)"\}%** returns **1200** +- Example: **%CALC\{"$VALUE(PrjNotebook1234)"\}%** returns **1234** +- Example: **%CALC\{"$VALUE(Total: -12.5)"\}%** returns **-12.5** +- Related: [[$EVAL()|Main/WebHome#FuncEVAL]], [[$INT()|Main/WebHome#FuncINT]] ## Bug Tracking Example @@ -453,13 +833,17 @@ Plugin settings are stored as preferences variables. To reference a plugin setti Plugin Version: - 03 Apr 2004 + 24 May 2004 Change History:   + 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 @@ -579,4 +963,4 @@ Plugin settings are stored as preferences variables. To reference a plugin setti **_Related Topics:_** [[TWikiPreferences]], [[TWikiPlugins]] --- TWiki:Main/PeterThoeny - 03 Apr 2004 +-- TWiki:Main/PeterThoeny - 24 May 2004 \` -- 1.9.4