1 # <a name="TWiki Spreadsheet Plugin"></a><a name=" TWiki Spreadsheet Plugin"></a> TWiki Spreadsheet Plugin
3 This plugin adds spreadsheet capabilities to TWiki topics. Formulae like <code>**%CALC\{"$INT(7/3)"\}%**</code> 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.
7 <td valign="top"><strong><em>Example:</em></strong><p>
9 <table border="1" cellpadding="0" cellspacing="0">
11 <th bgcolor="#99CCCC"><strong> Region: </strong></th>
12 <th bgcolor="#99CCCC"><strong> Sales: </strong></th>
16 <td align="right"> 320 </td>
20 <td align="right"> 580 </td>
24 <td align="right"> 240 </td>
28 <td align="right"> 610 </td>
32 <td align="right"> 220 </td>
36 <td align="right"> 1970 </td>
43 <td valign="top"><strong><em>Interactive example:</em></strong><p>
45 <form action="http://www.dementia.org/twiki//view/%WEB%/%TOPIC%" method="get" name="interactive"> Formula: <code>%CALC{"</code><input name="formula" size="40" type="text" value="$PROPERSPACE(admin)" /><code>"}%</code> <input type="submit" value="Go" /><br /> Result: admin <p>
51 <td colspan="3"> The formula next to "Total" is <code><b>%CALC{"$SUM( $ABOVE() )"}%</b></code>. <br /> (you see the formula instead of the sum in case the plugin is not installed or not enabled.) </td>
57 <li><a href="#Syntax Rules"> Syntax Rules</a></li>
58 <li><a href="#Built-in Functions"> Built-in Functions</a><ul>
59 <li><a href="#ABOVE( ) -- address range of cel"> ABOVE( ) -- address range of cells above the current cell</a></li>
60 <li><a href="#ABS( num ) -- absolute value of"> ABS( num ) -- absolute value of a number</a></li>
61 <li><a href="#AND( list ) -- logical AND of a"> AND( list ) -- logical AND of a list</a></li>
62 <li><a href="#AVERAGE( list ) -- average of a"> AVERAGE( list ) -- average of a list or a range of cells</a></li>
63 <li><a href="#CHAR( number ) -- ASCII characte"> CHAR( number ) -- ASCII character represented by number</a></li>
64 <li><a href="#CODE( text ) -- ASCII numeric va"> CODE( text ) -- ASCII numeric value of character</a></li>
65 <li><a href="#COLUMN( offset ) -- current colu"> COLUMN( offset ) -- current column number</a></li>
66 <li><a href="#COUNTITEMS( list ) -- count indi"> COUNTITEMS( list ) -- count individual items in a list</a></li>
67 <li><a href="#COUNTSTR( list, str ) -- count t"> COUNTSTR( list, str ) -- count the number of cells in a list equal to a given string</a></li>
68 <li><a href="#DEF( list ) -- find first non-em"> DEF( list ) -- find first non-empty list item or cell</a></li>
69 <li><a href="#EMPTY( text ) -- test for empty"> EMPTY( text ) -- test for empty text</a></li>
70 <li><a href="#EVAL( formula ) -- evaluate a si"> EVAL( formula ) -- evaluate a simple mathematical formula</a></li>
71 <li><a href="#EVEN( num ) -- test for even num"> EVEN( num ) -- test for even number</a></li>
72 <li><a href="#EXACT( text1, text2 ) -- compare"> EXACT( text1, text2 ) -- compare two text strings</a></li>
73 <li><a href="#EXEC( formula ) -- execute a spr"> EXEC( formula ) -- execute a spreadsheet formula</a></li>
74 <li><a href="#EXISTS( topic ) -- check if topi"> EXISTS( topic ) -- check if topic exists</a></li>
75 <li><a href="#EXP( num ) -- exponent (e) raise"> EXP( num ) -- exponent (e) raised to the power of a number</a></li>
76 <li><a href="#FIND( string, text, start ) -- f"> FIND( string, text, start ) -- find one string within another string</a></li>
77 <li><a href="#FORMAT( type, precision, number"> FORMAT( type, precision, number ) -- format a number to a certain type and precision</a></li>
78 <li><a href="#FORMATGMTIME( serial, text ) --"> FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string</a></li>
79 <li><a href="#FORMATTIME( serial, text ) -- co"> FORMATTIME( serial, text ) -- convert a serialized date into a date string</a></li>
80 <li><a href="#FORMATTIMEDIFF( unit, precision,"> FORMATTIMEDIFF( unit, precision, time ) -- convert elapsed time to a string</a></li>
81 <li><a href="#GET( name ) -- get the value of"> GET( name ) -- get the value of a previously set variable</a></li>
82 <li><a href="#IF( condition, value if true, va"> IF( condition, value if true, value if 0 ) -- return a value based on a condition</a></li>
83 <li><a href="#INSERTSTRING( text, start, new )"> INSERTSTRING( text, start, new ) -- insert a string into a text string</a></li>
84 <li><a href="#INT( formula ) -- evaluate formu"> INT( formula ) -- evaluate formula and round down to nearest integer</a></li>
85 <li><a href="#LEFT( ) -- address range of cell"> LEFT( ) -- address range of cells to the left of the current cell</a></li>
86 <li><a href="#LEFTSTRING( text, num ) -- extra"> LEFTSTRING( text, num ) -- extract characters at the beginning of a text string</a></li>
87 <li><a href="#LENGTH( text ) -- length of text"> LENGTH( text ) -- length of text in bytes</a></li>
88 <li><a href="#LIST( range ) -- convert content"> LIST( range ) -- convert content of a cell range into a list</a></li>
89 <li><a href="#LISTIF( condition, list ) -- rem"> LISTIF( condition, list ) -- remove elements from a list that do not meet a condition</a></li>
90 <li><a href="#LISTITEM( index, list ) -- get o"> LISTITEM( index, list ) -- get one element of a list</a></li>
91 <li><a href="#LISTJOIN( separator, list ) -- c"> LISTJOIN( separator, list ) -- convert a list into a string</a></li>
92 <li><a href="#LISTMAP( formula, list ) -- eval"> LISTMAP( formula, list ) -- evaluate and update each element of a list</a></li>
93 <li><a href="#LISTRAND( list ) -- get one rand"> LISTRAND( list ) -- get one random element of a list</a></li>
94 <li><a href="#LISTREVERSE( list ) -- opposite"> LISTREVERSE( list ) -- opposite order of a list</a></li>
95 <li><a href="#LISTSIZE( list ) -- number of el"> LISTSIZE( list ) -- number of elements in a list</a></li>
96 <li><a href="#LISTSHUFFLE( list ) -- shuffle e"> LISTSHUFFLE( list ) -- shuffle element of a list in random order</a></li>
97 <li><a href="#LISTSORT( list ) -- sort a list"> LISTSORT( list ) -- sort a list</a></li>
98 <li><a href="#LISTTRUNCATE( size, list ) -- tr"> LISTTRUNCATE( size, list ) -- truncate list to size</a></li>
99 <li><a href="#LISTUNIQUE( list ) -- remove all"> LISTUNIQUE( list ) -- remove all duplicates from a list</a></li>
100 <li><a href="#LN( num ) -- natural logarithm o"> LN( num ) -- natural logarithm of a number</a></li>
101 <li><a href="#LOG( num, base ) -- logarithm of"> LOG( num, base ) -- logarithm of a number to a given base</a></li>
102 <li><a href="#LOWER( text ) -- lower case stri"> LOWER( text ) -- lower case string of a text</a></li>
103 <li><a href="#MAX( list ) - biggest value of a"> MAX( list ) - biggest value of a list or range of cells</a></li>
104 <li><a href="#MEDIAN( list ) -- median of a li"> MEDIAN( list ) -- median of a list or range of cells</a></li>
105 <li><a href="#MIN( list ) -- smallest value of"> MIN( list ) -- smallest value of a list or range of cells</a></li>
106 <li><a href="#MOD( num, divisor ) -- reminder"> MOD( num, divisor ) -- reminder after dividing num by divisor</a></li>
107 <li><a href="#NOEXEC( formula ) -- do not exec"> NOEXEC( formula ) -- do not execute a spreadsheet formula</a></li>
108 <li><a href="#NOP( text ) -- no-operation"> NOP( text ) -- no-operation</a></li>
109 <li><a href="#NOT( num ) -- reverse logic of a"> NOT( num ) -- reverse logic of a number</a></li>
110 <li><a href="#ODD( num ) -- test for odd numbe"> ODD( num ) -- test for odd number</a></li>
111 <li><a href="#OR( list ) -- logical OR of a li"> OR( list ) -- logical OR of a list</a></li>
112 <li><a href="#PERCENTILE( num, list ) -- perce"> PERCENTILE( num, list ) -- percentile of a list or range of cells</a></li>
113 <li><a href="#PI( ) -- mathematical constant P"> PI( ) -- mathematical constant Pi, 3.14159265358979</a></li>
114 <li><a href="#PRODUCT( list ) -- product of a"> PRODUCT( list ) -- product of a list or range of cells</a></li>
115 <li><a href="#PROPER( text ) -- properly capit"> PROPER( text ) -- properly capitalize text</a></li>
116 <li><a href="#PROPERSPACE( text ) -- properly"> PROPERSPACE( text ) -- properly space out WikiWords</a></li>
117 <li><a href="#RAND( max ) -- random number"> RAND( max ) -- random number</a></li>
118 <li><a href="#REPEAT( text, num ) -- repeat te"> REPEAT( text, num ) -- repeat text a number of times</a></li>
119 <li><a href="#REPLACE( text, start, num, new )"> REPLACE( text, start, num, new ) -- replace part of a text string</a></li>
120 <li><a href="#RIGHT( ) -- address range of cel"> RIGHT( ) -- address range of cells to the right of the current cell</a></li>
121 <li><a href="#RIGHTSTRING( text, num ) -- extr"> RIGHTSTRING( text, num ) -- extract characters at the end of a text string</a></li>
122 <li><a href="#ROUND( formula, digits ) -- roun"> ROUND( formula, digits ) -- round a number</a></li>
123 <li><a href="#ROW( offset ) -- current row num"> ROW( offset ) -- current row number</a></li>
124 <li><a href="#SEARCH( string, text, start ) --"> SEARCH( string, text, start ) -- search a string within a text</a></li>
125 <li><a href="#SET( name, value ) -- set a vari"> SET( name, value ) -- set a variable for later use</a></li>
126 <li><a href="#SETIFEMPTY( name, value ) -- set"> SETIFEMPTY( name, value ) -- set a variable only if empty</a></li>
127 <li><a href="#SETM( name, formula ) -- update"> SETM( name, formula ) -- update an existing variable based on a formula</a></li>
128 <li><a href="#SIGN( num ) -- sign of a number"> SIGN( num ) -- sign of a number</a></li>
129 <li><a href="#SQRT( num ) -- square root of a"> SQRT( num ) -- square root of a number</a></li>
130 <li><a href="#SUBSTITUTE( text, old, new, inst"> SUBSTITUTE( text, old, new, instance, option ) -- substitute text</a></li>
131 <li><a href="#SUBSTRING( text, start, num ) --"> SUBSTRING( text, start, num ) -- extract a substring out of a text string</a></li>
132 <li><a href="#SUM( list ) -- sum of a list or"> SUM( list ) -- sum of a list or range of cells</a></li>
133 <li><a href="#SUMDAYS( list ) -- sum the days"> SUMDAYS( list ) -- sum the days in a list or range of cells</a></li>
134 <li><a href="#SUMPRODUCT( list, list ) -- scal"> SUMPRODUCT( list, list ) -- scalar product on ranges of cells</a></li>
135 <li><a href="#T( address ) -- content of a cel"> T( address ) -- content of a cell</a></li>
136 <li><a href="#TRANSLATE( text, from, to ) -- t"> TRANSLATE( text, from, to ) -- translate text from one set of characters to another</a></li>
137 <li><a href="#TIME( text ) -- convert a date s"> TIME( text ) -- convert a date string into a serialized date number</a></li>
138 <li><a href="#TIMEADD( serial, value, unit ) -"> TIMEADD( serial, value, unit ) -- add a value to a serialized date</a></li>
139 <li><a href="#TIMEDIFF( serial_1, serial_2, un"> TIMEDIFF( serial_1, serial_2, unit ) -- time difference between two serialized dates</a></li>
140 <li><a href="#TODAY( ) -- serialized date of t"> TODAY( ) -- serialized date of today at midnight GMT</a></li>
141 <li><a href="#TRIM( text ) -- trim spaces from"> TRIM( text ) -- trim spaces from text</a></li>
142 <li><a href="#UPPER( text ) -- upper case stri"> UPPER( text ) -- upper case string of a text</a></li>
143 <li><a href="#VALUE( text ) -- convert text to"> VALUE( text ) -- convert text to number</a></li>
144 <li><a href="#WORKINGDAYS( serial_1, serial_2"> WORKINGDAYS( serial_1, serial_2 ) -- working days between two serialized dates</a></li>
147 <li><a href="#FAQ"> FAQ</a><ul>
148 <li><a href="#Can I use CALC in a formatted se"> Can I use CALC in a formatted search?</a></li>
149 <li><a href="#How can I easily repeat a formul"> How can I easily repeat a formula in a table?</a></li>
152 <li><a href="#Bug Tracking Example"> Bug Tracking Example</a></li>
153 <li><a href="#Plugin Settings"> Plugin Settings</a></li>
154 <li><a href="#Plugin Installation Instructions"> Plugin Installation Instructions</a></li>
155 <li><a href="#Plugin Info"> Plugin Info</a></li>
159 ## <a name="Syntax Rules"></a> Syntax Rules
161 The action of this plugin is triggered by the <code>**%CALC\{"..."\}%**</code> variable, which gets rendered according to the built-in function(s) found between the quotes.
163 - Built-in function are of format <code>**$FUNCNAME(parameter)**</code>
164 - Functions may be nested, e.g. <code>**%CALC\{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"\}%**</code>
165 - Functions are evaluated from left to right, and from inside to outside if nested
166 - The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
167 - Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. <code>**%CALC\{"$SUM( 3, 5, 7 )"\}%**</code>
168 - A table cell can be addressed as <code>**R1:C1**</code>. Table address matrix: <table border="1" cellpadding="0" cellspacing="0">
170 <td><code><b>R1:C1</b></code></td>
171 <td><code><b>R1:C2</b></code></td>
172 <td><code><b>R1:C3</b></code></td>
173 <td><code><b>R1:C4</b></code></td>
176 <td><code><b>R2:C1</b></code></td>
177 <td><code><b>R2:C2</b></code></td>
178 <td><code><b>R2:C3</b></code></td>
179 <td><code><b>R2:C4</b></code></td>
182 - A table cell range is defined by two cell addresses separated by <code>**".."**</code>, e.g. "row 1 through 20, column 3" is: <code>**R1:C3..R20:C3**</code>
183 - Lists can refer to values and/or table cell ranges, e.g. <code>**%CALC\{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"\}%**</code>
184 - Formulae can only reference cells in the current or preceeding row of the current table; they may not reference cells below the current table row
185 - Formulae can also be placed outside of tables; they can reference cells in the preceeding table
186 - Formulae can be placed in a [[FormattedSearch]], but the CALC needs to be escaped. Learn how to [[use a CALC in a formatted search|Main/WebHome#CalcInFormattedSearch]]
188 ## <a name="Built-in Functions"></a> Built-in Functions
190 Conventions for Syntax:
192 - Required parameters are indicated in <code>**( bold )**</code>
193 - Optional parameters are indicated in <code>**( _bold italic_ )**</code>
195 <a name="FuncABOVE"></a>
197 ### <a name="ABOVE( ) -- address range of cel"></a> ABOVE( ) -- address range of cells above the current cell
199 - Syntax: <code>**$ABOVE( )**</code>
200 - Example: <code>**%CALC\{"$SUM($ABOVE())"\}%**</code> returns the sum of cells above the current cell
201 - Related: <code>[[$LEFT()|Main/WebHome#FuncLEFT]]</code>, <code>[[$RIGHT()|Main/WebHome#FuncRIGHT]]</code>
203 <a name="FuncABS"></a>
205 ### <a name="ABS( num ) -- absolute value of"></a><a name="ABS( num ) -- absolute value of "></a> ABS( num ) -- absolute value of a number
207 - Syntax: <code>**$ABS( num )**</code>
208 - Example: <code>**%CALC\{"$ABS(-12.5)"\}%**</code> returns <code>**12\.5**</code>
209 - Related: <code>[[$SIGN()|Main/WebHome#FuncSIGN]]</code>, <code>[[$EVEN()|Main/WebHome#FuncEVEN]]</code>, <code>[[$ODD()|Main/WebHome#FuncODD]]</code>
211 <a name="FuncAND"></a>
213 ### <a name="AND( list ) -- logical AND of a"></a><a name="AND( list ) -- logical AND of a "></a> AND( list ) -- logical AND of a list
215 - Syntax: <code>**$AND( list )**</code>
216 - Example: <code>**%CALC\{"$AND(1, 0, 1)"\}%**</code> returns <code>****</code>
217 - Related: <code>[[$NOT()|Main/WebHome#FuncNOT]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$OR()|Main/WebHome#FuncOR]]</code>
219 <a name="FuncAVERAGE"></a>
221 ### <a name="AVERAGE( list ) -- average of a"></a><a name="AVERAGE( list ) -- average of a "></a> AVERAGE( list ) -- average of a list or a range of cells
223 - Syntax: <code>**$AVERAGE( list )**</code>
224 - Example: <code>**%CALC\{"$AVERAGE(R2:C5..R$ROW(-1):C5)"\}%**</code> returns the average of column 5, excluding the title row
225 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$MAX()|Main/WebHome#FuncMAX]]</code>, <code>[[$MEDIAN()|Main/WebHome#FuncMEDIAN]]</code>, <code>[[$MIN()|Main/WebHome#FuncMIN]]</code>
227 <a name="FuncCHAR"></a>
229 ### <a name="CHAR( number ) -- ASCII characte"></a> CHAR( number ) -- ASCII character represented by number
231 - Syntax: <code>**$CHAR( number )**</code>
232 - Example: Example: <code>**%CALC\{"$CHAR(97)"\}%**</code> returns <code>**a**</code>
233 - Related: <code>[[$CODE()|Main/WebHome#FuncCODE]]</code>
235 <a name="FuncCODE"></a>
237 ### <a name="CODE( text ) -- ASCII numeric va"></a> CODE( text ) -- ASCII numeric value of character
239 - The ASCII numeric value of the first character in text
240 - Syntax: <code>**$CODE( text )**</code>
241 - Example: <code>**%CALC\{"$CODE(abc)"\}%**</code> returns <code>**97**</code>
242 - Related: <code>[[$CHAR()|Main/WebHome#FuncCHAR]]</code>
244 <a name="FuncCOLUMN"></a>
246 ### <a name="COLUMN( offset ) -- current colu"></a> COLUMN( offset ) -- current column number
248 - The current table column number with an optional offset
249 - Syntax: <code>**$COLUMN( _offset_ )**</code>
250 - Example: <code>**%CALC\{"$COLUMN()"\}%**</code> returns <code>**2**</code> for the second column
251 - Related: <code>[[$ROW()|Main/WebHome#FuncROW]]</code>, <code>[[$T()|Main/WebHome#FuncT]]</code>
253 <a name="FuncCOUNTITEMS"></a>
255 ### <a name="COUNTITEMS( list ) -- count indi"></a> COUNTITEMS( list ) -- count individual items in a list
257 - Syntax: <code>**$COUNTITEMS( list )**</code>
258 - Example: <code>**%CALC\{"$COUNTITEMS($ABOVE())"\}%**</code> returns <code>**Closed: 1, Open: 2**</code> assuming one cell above the current cell contains <code>**Closed**</code> and two cells contain <code>**Open**</code>
259 - Related: <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>
261 <a name="FuncCOUNTSTR"></a>
263 ### <a name="COUNTSTR( list, str ) -- count t"></a> COUNTSTR( list, str ) -- count the number of cells in a list equal to a given string
265 - 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
266 - Syntax: <code>**$COUNTSTR( list, _str_ )**</code>
267 - Example: <code>**%CALC\{"$COUNTSTR($ABOVE())"\}%**</code> counts the number of non empty cells above the current cell
268 - Example: <code>**%CALC\{"$COUNTSTR($ABOVE(), DONE)"\}%**</code> counts the number of cells equal to <code>**DONE**</code>
269 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>
271 <a name="FuncDEF"></a>
273 ### <a name="DEF( list ) -- find first non-em"></a> DEF( list ) -- find first non-empty list item or cell
275 - Returns the first list item or cell reference that is not empty
276 - Syntax: <code>**$DEF( list )**</code>
277 - Example: <code>**%CALC\{"$DEF(R1:C1..R1:C3)"\}%**</code>
278 - Related: <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>
280 <a name="FuncEMPTY"></a>
282 ### <a name="EMPTY( text ) -- test for empty"></a><a name="EMPTY( text ) -- test for empty "></a> EMPTY( text ) -- test for empty text
284 - Returns <code>**1**</code> if `text` is empty, or <code>****</code> if not
285 - Syntax: <code>**$EMPTY( _text_ )**</code>
286 - Example: <code>**%CALC\{"$EMPTY(foo)"\}%**</code> returns <code>****</code>
287 - Example: <code>**%CALC\{"$EMPTY()"\}%**</code> returns <code>**1**</code>
288 - Example: <code>**%CALC\{"$EMPTY($TRIM( ))"\}%**</code> returns <code>**1**</code>
289 - Related: <code>[[$EXACT()|Main/WebHome#FuncEXACT]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>
291 <a name="FuncEVAL"></a>
293 ### <a name="EVAL( formula ) -- evaluate a si"></a> EVAL( formula ) -- evaluate a simple mathematical formula
295 - Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
296 - Numbers may be decimal integers (`1234`), binary integers (`0b1110011`), octal integers (`01234`), hexadecimal integers (`0x1234`) or of exponential notation (`12.34e-56`)
297 - Syntax: <code>**$EVAL( formula )**</code>
298 - Example: <code>**%CALC\{"$EVAL( (5 \* 3) / 2 + 1.1 )"\}%**</code> returns <code>**8\.6**</code>
299 - Related: <code>[[$EXEC()|Main/WebHome#FuncEXEC]]</code>, <code>[[$INT()|Main/WebHome#FuncINT]]</code>, <code>[[$MOD()|Main/WebHome#FuncMOD]]</code>, <code>[[$ROUND()|Main/WebHome#FuncROUND]]</code>, <code>[[$VALUE()|Main/WebHome#FuncVALUE]]</code>
301 <a name="FuncEVEN"></a>
303 ### <a name="EVEN( num ) -- test for even num"></a> EVEN( num ) -- test for even number
305 - Syntax: <code>**$EVEN( num )**</code>
306 - Example: <code>**%CALC\{"$EVEN(2)"\}%**</code> returns <code>**1**</code>
307 - Related: <code>[[$ABS()|Main/WebHome#FuncABS]]</code>, <code>[[$MOD()|Main/WebHome#FuncMOD]]</code>, <code>[[$ODD()|Main/WebHome#FuncODD]]</code>, <code>[[$SIGN()|Main/WebHome#FuncSIGN]]</code>
309 <a name="FuncEXACT"></a>
311 ### <a name="EXACT( text1, text2 ) -- compare"></a> EXACT( text1, text2 ) -- compare two text strings
313 - Compares two text strings and returns <code>**1**</code> if they are exactly the same, or <code>****</code> if not
314 - Syntax: <code>**$EXACT( text1, _text2_ )**</code>
315 - Example: <code>**%CALC\{"$EXACT(foo, Foo)"\}%**</code> returns <code>****</code>
316 - Example: <code>**%CALC\{"$EXACT(foo, $LOWER(Foo))"\}%**</code> returns <code>**1**</code>
317 - Related: <code>[[$EMPTY()|Main/WebHome#FuncEMPTY]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>
319 <a name="FuncEXEC"></a>
321 ### <a name="EXEC( formula ) -- execute a spr"></a> EXEC( formula ) -- execute a spreadsheet formula
323 - Execute a spreadsheet formula, typically retrieved from a variable. This can be used to store a formula in a variable once and execute it many times using different parameters.
324 - Syntax: <code>**$EXEC( formula )**</code>
325 - Example: <code>**%CALC\{"$SET(msg, $NOEXEC(Hi $GET(name)))"\}%**</code> sets the `msg` variable with raw formula `Hi $GET(name)`
326 - Example: <code>**%CALC\{"$SET(name, Tom) $EXEC($GET(msg))"\}%**</code> executes content of `msg` variable and returns `Hi Tom`
327 - Example: <code>**%CALC\{"$SET(name, Jerry) $EXEC($GET(msg))"\}%**</code> returns `Hi Jerry`
328 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$GET()|Main/WebHome#FuncGET]]</code>, <code>[[$NOEXEC()|Main/WebHome#FuncNOEXEC]]</code>, <code>[[$SET()|Main/WebHome#FuncSET]]</code>
330 <a name="FuncEXISTS"></a>
332 ### <a name="EXISTS( topic ) -- check if topi"></a> EXISTS( topic ) -- check if topic exists
334 - Topic can be `TopicName` or a `Web.TopicName`. Current web is used if web is not specified.
335 - Syntax: <code>**$EXISTS( topic )**</code>
336 - Example: <code>**%CALC\{"$EXISTS(WebHome)"\}%**</code> returns <code>**1**</code>
337 - Example: <code>**%CALC\{"$EXISTS(ThisDoesNotExist)"\}%**</code> returns <code>****</code>
338 - Related: <code>[[$EXACT()|Main/WebHome#FuncEXACT]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>
340 <a name="FuncEXP"></a>
342 ### <a name="EXP( num ) -- exponent (e) raise"></a> EXP( num ) -- exponent (e) raised to the power of a number
344 - EXP is the inverse of the LN function
345 - Syntax: <code>**$EXP( num )**</code>
346 - Example: <code>**%CALC\{"$EXP(1)"\}%**</code> returns <code>**2\.71828182845905**</code>
347 - Related: <code>[[$LN()|Main/WebHome#FuncLN]]</code>, <code>[[$LOG()|Main/WebHome#FuncLOG]]</code>
349 <a name="FuncFIND"></a>
351 ### <a name="FIND( string, text, start ) -- f"></a> FIND( string, text, start ) -- find one string within another string
353 - 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.
354 - Syntax: <code>**$FIND( string, text, _start_ )**</code>
355 - Example: <code>**%CALC\{"$FIND(f, fluffy)"\}%**</code> returns <code>**1**</code>
356 - Example: <code>**%CALC\{"$FIND(f, fluffy, 2)"\}%**</code> returns <code>**4**</code>
357 - Example: <code>**%CALC\{"$FIND(@, fluffy, 1)"\}%**</code> returns <code>****</code>
358 - Related: <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>
360 <a name="FuncFORMAT"></a>
362 ### <a name="FORMAT( type, precision, number"></a><a name="FORMAT( type, precision, number "></a> FORMAT( type, precision, number ) -- format a number to a certain type and precision
365 - `COMMA` for comma format, such as `12,345.68`
366 - `DOLLAR` for Dollar format, such as `$12,345.68`
367 - `KB` for Kilo Byte format, such as `1205.63 KB`
368 - `MB` for Mega Byte format, such as `1.18 MB`
369 - `KBMB` for Kilo/Mega/Giga/Tera Byte auto-adjust format
370 - `NUMBER` for number, such as `12345.7`
371 - `PERCENT` for percent format, such as `12.3%`
372 - The `precision` indicates the the number of digits after the dot
373 - Syntax: <code>**$FORMAT( type, prec, number )**</code>
374 - Example: <code>**%CALC\{"$FORMAT(COMMA, 2, 12345.6789)"\}%**</code> returns <code>**12,345.68**</code>
375 - Example: <code>**%CALC\{"$FORMAT(DOLLAR, 2, 12345.67)"\}%**</code> returns <code>**$12,345.68**</code>
376 - Example: <code>**%CALC\{"$FORMAT(KB, 2, 1234567)"\}%**</code> returns <code>**1205\.63 KB**</code>
377 - Example: <code>**%CALC\{"$FORMAT(MB, 2, 1234567)"\}%**</code> returns <code>**1\.18 MB**</code>
378 - Example: <code>**%CALC\{"$FORMAT(KBMB, 2, 1234567)"\}%**</code> returns <code>**1\.18 MB**</code>
379 - Example: <code>**%CALC\{"$FORMAT(KBMB, 2, 1234567890)"\}%**</code> returns <code>**1\.15 GB**</code>
380 - Example: <code>**%CALC\{"$FORMAT(NUMBER, 1, 12345.67)"\}%**</code> returns <code>**12345\.7**</code>
381 - Example: <code>**%CALC\{"$FORMAT(PERCENT, 1, 0.1234567)"\}%**</code> returns <code>**12\.3%**</code>
382 - Related: <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATTIMEDIFF()|Main/WebHome#FuncFORMATTIMEDIFF]]</code>, <code>[[$ROUND()|Main/WebHome#FuncROUND]]</code>
384 <a name="FuncFORMATGMTIME"></a>
386 ### <a name="FORMATGMTIME( serial, text ) --"></a><a name="FORMATGMTIME( serial, text ) -- "></a> FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string
388 - The date string represents the time in Greenwich time zone. Same variable expansion as in `$FORMATTIME()`.
389 - Syntax: <code>**$FORMATGMTIME( serial, text )**</code>
390 - Example: <code>**%CALC\{"$FORMATGMTIME(1041379200, $day $mon $year)"\}%**</code> returns <code>**01 Jan 2003**</code>
391 - Related: <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATTIMEDIFF()|Main/WebHome#FuncFORMATTIMEDIFF]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>, <code>[[$TODAY()|Main/WebHome#FuncTODAY]]</code>
393 <a name="FuncFORMATTIME"></a>
395 ### <a name="FORMATTIME( serial, text ) -- co"></a> FORMATTIME( serial, text ) -- convert a serialized date into a date string
397 - 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.
398 - Syntax: <code>**$FORMATTIME( serial, text )**</code>
399 - Example: <code>**%CALC\{"$FORMATTIME(0, $year/$month/$day GMT)"\}%**</code> returns <code>**1970/01/01 GMT**</code>
400 - Related: <code>[[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$FORMATTIMEDIFF()|Main/WebHome#FuncFORMATTIMEDIFF]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>, <code>[[$TODAY()|Main/WebHome#FuncTODAY]]</code>
402 <a name="FuncFORMATTIMEDIFF"></a>
404 ### <a name="FORMATTIMEDIFF( unit, precision,"></a> FORMATTIMEDIFF( unit, precision, time ) -- convert elapsed time to a string
406 - Convert elapsed `time` to a human readable format, such as: `12 hours and 3 minutes`
407 - The input `unit` can be `second`, `minute`, `hour`, `day`, `month`, `year`. Note: An approximation is used for month and year calculations.
408 - The `precision` indicates the number of output units to use
409 - Syntax: <code>**$FORMATTIMEDIFF( unit, precision, time )**</code>
410 - Example: <code>**%CALC\{"$FORMATTIMEDIFF(min, 1, 200)"\}%**</code> returns <code>**3 hours**</code>
411 - Example: <code>**%CALC\{"$FORMATTIMEDIFF(min, 2, 200)"\}%**</code> returns <code>**3 hours and 20 minutes**</code>
412 - Example: <code>**%CALC\{"$FORMATTIMEDIFF(min, 1, 1640)"\}%**</code> returns <code>**1 day**</code>
413 - Example: <code>**%CALC\{"$FORMATTIMEDIFF(min, 2, 1640)"\}%**</code> returns <code>**1 day and 3 hours**</code>
414 - Example: <code>**%CALC\{"$FORMATTIMEDIFF(min, 3, 1640)"\}%**</code> returns <code>**1 day, 3 hours and 20 minutes**</code>
415 - Related: <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>
417 <a name="FuncGET"></a>
419 ### <a name="GET( name ) -- get the value of"></a><a name="GET( name ) -- get the value of "></a> GET( name ) -- get the value of a previously set variable
421 - 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.
422 - Syntax: <code>**$GET( name )**</code>
423 - Example: <code>**%CALC\{"$GET(my\_total)"\}%**</code> returns the value of the `my_total` variable
424 - Related: <code>[[$EXEC()|Main/WebHome#FuncEXEC]]</code>, <code>[[$NOEXEC()|Main/WebHome#FuncNOEXEC]]</code>, <code>[[$SET()|Main/WebHome#FuncSET]]</code>, <code>[[$SETIFEMPTY()|Main/WebHome#FuncSETIFEMPTY]]</code>, <code>[[$SETM()|Main/WebHome#FuncSETM]]</code>
426 <a name="FuncIF"></a>
428 ### <a name="IF( condition, value if true, va"></a> IF( condition, value if true, value if 0 ) -- return a value based on a condition
430 - The condition can be a number (where <code>****</code> means condition not met), or two numbers with a comparison operator <code>**<**</code> (less than), <code>**<=**</code> (less than or equal), <code>**==**</code> (equal), <code>**!=**</code> (not equal), <code>**>=**</code> (greater than or equal), <code>**>**</code> (greater than).
431 - Syntax: <code>**$IF( condition, value if true, value if 0 )**</code>
432 - Example: <code>**%CALC\{"$IF($T(R1:C5) > 1000, Over Budget, OK)"\}%**</code> returns <code>**Over Budget**</code> if value in R1:C5 is over 1000, <code>**OK**</code> if not
433 - Example: <code>**%CALC\{"$IF($EXACT($T(R1:C2),), empty, $T(R1:C2))"\}%**</code> returns the content of R1:C2 or <code>**empty**</code> if empty
434 - Example: <code>**%CALC\{"$SET(val, $IF($T(R1:C2) == 0, zero, $T(R1:C2)))"\}%**</code> sets a variable conditionally
435 - Related: <code>[[$AND()|Main/WebHome#FuncAND]]</code>, <code>[[$EMPTY()|Main/WebHome#FuncEMPTY]]</code>, <code>[[$EXACT()|Main/WebHome#FuncEXACT]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$NOT()|Main/WebHome#FuncNOT]]</code>, <code>[[$OR()|Main/WebHome#FuncOR]]</code>
437 <a name="FuncINSERTSTRING"></a>
439 ### <a name="INSERTSTRING( text, start, new )"></a> INSERTSTRING( text, start, new ) -- insert a string into a text string
441 - Insert `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
442 - Syntax: <code>**$INSERTSTRING( text, start, new )**</code>
443 - Example: <code>**%CALC\{"$INSERTSTRING(abcdefg, 2, XYZ)"\}%**</code> returns <code>**abXYZcdefg**</code>
444 - Example: <code>**%CALC\{"$INSERTSTRING(abcdefg, -2, XYZ)"\}%**</code> returns <code>**abcdeXYZfg**</code>
445 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
447 <a name="FuncINT"></a>
449 ### <a name="INT( formula ) -- evaluate formu"></a> INT( formula ) -- evaluate formula and round down to nearest integer
451 - Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
452 - Numbers may be decimal integers (`1234`), binary integers (`0b1110011`), octal integers (`01234`), hexadecimal integers (`0x1234`) or of exponential notation (`12.34e-56`)
453 - If you expect a single decimal integer value with leading zeros, use <code>**$INT( $VALUE( number ) )**</code>
454 - Syntax: <code>**$INT( formula )**</code>
455 - Example: <code>**%CALC\{"$INT(10 / 4)"\}%**</code> returns <code>**2**</code>
456 - Example: <code>**%CALC\{"$INT($VALUE(09))"\}%**</code> returns <code>**9**</code>
457 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$ROUND()|Main/WebHome#FuncROUND]]</code>, <code>[[$VALUE()|Main/WebHome#FuncVALUE]]</code>
459 <a name="FuncLEFT"></a>
461 ### <a name="LEFT( ) -- address range of cell"></a> LEFT( ) -- address range of cells to the left of the current cell
463 - Syntax: <code>**$LEFT( )**</code>
464 - Example: <code>**%CALC\{"$SUM($LEFT())"\}%**</code> returns the sum of cells to the left of the current cell
465 - Related: <code>[[$ABOVE()|Main/WebHome#FuncABOVE]]</code>, <code>[[$RIGHT()|Main/WebHome#FuncRIGHT]]</code>
467 <a name="FuncLEFTSTRING"></a>
469 ### <a name="LEFTSTRING( text, num ) -- extra"></a> LEFTSTRING( text, num ) -- extract characters at the beginning of a text string
471 - Retrieve the `num` of characters from the left end of `text`; the leftmost character is returned if `num` is missing
472 - Syntax: <code>**$LEFTSTRING( text, _num_ )**</code>
473 - Example: <code>**%CALC\{"$LEFTSTRING(abcdefg)"\}%**</code> returns <code>**a**</code>
474 - Example: <code>**%CALC\{"$LEFTSTRING(abcdefg, 5)"\}%**</code> returns <code>**abcde**</code>
475 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
477 <a name="FuncLENGTH"></a>
479 ### <a name="LENGTH( text ) -- length of text"></a> LENGTH( text ) -- length of text in bytes
481 - Syntax: <code>**$LENGTH( text )**</code>
482 - Example: <code>**%CALC\{"$LENGTH(abcd)"\}%**</code> returns <code>**4**</code>
483 - Related: <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>
485 <a name="FuncLIST"></a>
487 ### <a name="LIST( range ) -- convert content"></a> LIST( range ) -- convert content of a cell range into a list
489 - Convert the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list
490 - Syntax: <code>**$LIST( range )**</code>
491 - Example: <code>**%CALC\{"$LIST($LEFT())"\}%**</code> returns <code>**Apples, Lemons, Oranges, Kiwis**</code> assuming the cells to the left contain <code>**| Apples | Lemons, Oranges | Kiwis |**</code>
492 - Related: <code>[[$AVERAGE()|Main/WebHome#FuncAVERAGE]]</code>, <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$DEF()|Main/WebHome#FuncDEF]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTJOIN()|Main/WebHome#FuncLISTJOIN]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTRAND()|Main/WebHome#FuncLISTRAND]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSHUFFLE()|Main/WebHome#FuncLISTSHUFFLE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTTRUNCATE()|Main/WebHome#FuncLISTTRUNCATE]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$MAX()|Main/WebHome#FuncMAX]]</code>, <code>[[$MEDIAN()|Main/WebHome#FuncMEDIAN]]</code>, <code>[[$MIN()|Main/WebHome#FuncMIN]]</code>, <code>[[$PRODUCT()|Main/WebHome#FuncPRODUCT]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>, <code>[[$SUMDAYS()|Main/WebHome#FuncSUMDAYS]]</code>, <code>[[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]]</code>
494 <a name="FuncLISTIF"></a>
496 ### <a name="LISTIF( condition, list ) -- rem"></a> LISTIF( condition, list ) -- remove elements from a list that do not meet a condition
498 - In addition to the condition described in <code>[[$IF()|Main/WebHome#FuncIF]]</code>, you can use <code>**$item**</code> to indicate the current element, and <code>**$index**</code> for the list index, starting at 1
499 - Syntax: <code>**$LISTIF( condition, list )**</code>
500 - Example: <code>**%CALC\{"$LISTIF($item > 12, 14, 7, 25)"\}%**</code> returns <code>**14, 25**</code>
501 - Example: <code>**%CALC\{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"\}%**</code> returns non-empty elements <code>**A, B, E**</code>
502 - Example: <code>**%CALC\{"$LISTIF($index > 2, A, B, C, D)"\}%**</code> returns <code>**C, D**</code>
503 - Related: <code>[[$EMPTY()|Main/WebHome#FuncEMPTY]]</code>, <code>[[$EXACT()|Main/WebHome#FuncEXACT]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
505 <a name="FuncLISTITEM"></a>
507 ### <a name="LISTITEM( index, list ) -- get o"></a> LISTITEM( index, list ) -- get one element of a list
509 - Index is 1 to size of list; use a negative number to count from the end of the list
510 - Syntax: <code>**$LISTITEM( index, list )**</code>
511 - Example: <code>**%CALC\{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**Orange**</code>
512 - Example: <code>**%CALC\{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**Kiwi**</code>
513 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTRAND()|Main/WebHome#FuncLISTRAND]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
515 <a name="FuncLISTJOIN"></a>
517 ### <a name="LISTJOIN( separator, list ) -- c"></a> LISTJOIN( separator, list ) -- convert a list into a string
519 - By default, list items are separated by a comma and a space. Use this function to indicate a specific `separator` string, which may include `$comma` for comma, `$n` for newline, and `$sp` for space.
520 - Syntax: <code>**$LISTJOIN( separator, list )**</code>
521 - Example: <code>**%CALC\{"$LISTJOIN($n, Apple, Orange, Apple, Kiwi)"\}%**</code> returns the four items separated by new lines
522 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>
524 <a name="FuncLISTMAP"></a>
526 ### <a name="LISTMAP( formula, list ) -- eval"></a> LISTMAP( formula, list ) -- evaluate and update each element of a list
528 - In the formula you can use <code>**$item**</code> to indicate the element; <code>**$index**</code> to show the index of the list, starting at 1. If <code>**$item**</code> is omitted, the item is appended to the formula.
529 - Syntax: <code>**$LISTMAP( formula, list )**</code>
530 - Example: <code>**%CALC\{"$LISTMAP($index: $EVAL(2 \* $item), 3, 5, 7, 11)"\}%**</code> returns <code>**1: 6, 2: 10, 3: 14, 4: 22**</code>
531 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
533 <a name="FuncLISTRAND"></a>
535 ### <a name="LISTRAND( list ) -- get one rand"></a> LISTRAND( list ) -- get one random element of a list
537 - Syntax: <code>**$LISTRAND( list )**</code>
538 - Example: <code>**%CALC\{"$LISTRAND(Apple, Orange, Apple, Kiwi)"\}%**</code> returns one of the four elements
539 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTSHUFFLE()|Main/WebHome#FuncLISTSHUFFLE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$RAND()|Main/WebHome#FuncRAND]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
541 <a name="FuncLISTREVERSE"></a>
543 ### <a name="LISTREVERSE( list ) -- opposite"></a><a name="LISTREVERSE( list ) -- opposite "></a> LISTREVERSE( list ) -- opposite order of a list
545 - Syntax: <code>**$LISTREVERSE( list )**</code>
546 - Example: <code>**%CALC\{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**Kiwi, Apple, Orange, Apple**</code>
547 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
549 <a name="FuncLISTSIZE"></a>
551 ### <a name="LISTSIZE( list ) -- number of el"></a> LISTSIZE( list ) -- number of elements in a list
553 - Syntax: <code>**$LISTSIZE( list )**</code>
554 - Example: <code>**%CALC\{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**4**</code>
555 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTJOIN()|Main/WebHome#FuncLISTJOIN]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTTRUNCATE()|Main/WebHome#FuncLISTTRUNCATE]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
557 <a name="FuncLISTSHUFFLE"></a>
559 ### <a name="LISTSHUFFLE( list ) -- shuffle e"></a> LISTSHUFFLE( list ) -- shuffle element of a list in random order
561 - Syntax: <code>**$LISTSHUFFLE( list )**</code>
562 - Example: <code>**%CALC\{"$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)"\}%**</code> returns the four elements in random order
563 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTRAND()|Main/WebHome#FuncLISTRAND]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$RAND()|Main/WebHome#FuncRAND]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
565 <a name="FuncLISTSORT"></a>
567 ### <a name="LISTSORT( list ) -- sort a list"></a> LISTSORT( list ) -- sort a list
569 - Sorts a list in ASCII order, or numerically if all elements are numeric
570 - Syntax: <code>**$LISTSORT( list )**</code>
571 - Example: <code>**%CALC\{"$LISTSORT(Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**Apple, Apple, Kiwi, Orange**</code>
572 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSHUFFLE()|Main/WebHome#FuncLISTSHUFFLE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
574 <a name="FuncLISTTRUNCATE"></a>
576 ### <a name="LISTTRUNCATE( size, list ) -- tr"></a> LISTTRUNCATE( size, list ) -- truncate list to size
578 - Specify the desired size of the list; use a negative number to count from the end of the list
579 - Syntax: <code>**$LISTTRUNCATE( size, list )**</code>
580 - Example: <code>**%CALC\{"$LISTTRUNCATE(2, Apple, Orange, Kiwi)"\}%**</code> returns <code>**Apple, Orange**</code>
581 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$LISTUNIQUE()|Main/WebHome#FuncLISTUNIQUE]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
583 <a name="FuncLISTUNIQUE"></a>
585 ### <a name="LISTUNIQUE( list ) -- remove all"></a> LISTUNIQUE( list ) -- remove all duplicates from a list
587 - Syntax: <code>**$LISTUNIQUE( list )**</code>
588 - Example: <code>**%CALC\{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"\}%**</code> returns <code>**Apple, Orange, Kiwi**</code>
589 - Related: <code>[[$COUNTITEMS()|Main/WebHome#FuncCOUNTITEMS]]</code>, <code>[[$COUNTSTR()|Main/WebHome#FuncCOUNTSTR]]</code>, <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$LISTIF()|Main/WebHome#FuncLISTIF]]</code>, <code>[[$LISTITEM()|Main/WebHome#FuncLISTITEM]]</code>, <code>[[$LISTMAP()|Main/WebHome#FuncLISTMAP]]</code>, <code>[[$LISTREVERSE()|Main/WebHome#FuncLISTREVERSE]]</code>, <code>[[$LISTSIZE()|Main/WebHome#FuncLISTSIZE]]</code>, <code>[[$LISTSORT()|Main/WebHome#FuncLISTSORT]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
591 <a name="FuncLN"></a>
593 ### <a name="LN( num ) -- natural logarithm o"></a> LN( num ) -- natural logarithm of a number
595 - LN is the inverse of the EXP function
596 - Syntax: <code>**$LN( num )**</code>
597 - Example: <code>**%CALC\{"$LN(10)"\}%**</code> returns <code>**2\.30258509299405**</code>
598 - Related: <code>[[$EXP()|Main/WebHome#FuncEXP]]</code>, <code>[[$LOG()|Main/WebHome#FuncLOG]]</code>
600 <a name="FuncLOG"></a>
602 ### <a name="LOG( num, base ) -- logarithm of"></a> LOG( num, base ) -- logarithm of a number to a given base
604 - base-10 logarithm of a number (if base is 0 or not specified), else logarithm of a number to the given base
605 - Syntax: <code>**$LOG( num, _base_ )**</code>
606 - Example: <code>**%CALC\{"$LOG(1000)"\}%**</code> returns <code>**3**</code>
607 - Example: <code>**%CALC\{"$LOG(16, 2)"\}%**</code> returns <code>**4**</code>
608 - Related: <code>[[$EXP()|Main/WebHome#FuncEXP]]</code>, <code>[[$LN()|Main/WebHome#FuncLN]]</code>
610 <a name="FuncLOWER"></a>
612 ### <a name="LOWER( text ) -- lower case stri"></a> LOWER( text ) -- lower case string of a text
614 - Syntax: <code>**$LOWER(text)**</code>
615 - Example: <code>**%CALC\{"$LOWER( $T(R1:C5) )"\}%**</code> returns the lower case string of the text in cell <code>**R1:C5**</code>
616 - Related: <code>[[$PROPER()|Main/WebHome#FuncPROPER]]</code>, <code>[[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>, <code>[[$UPPER()|Main/WebHome#FuncUPPER]]</code>
618 <a name="FuncMAX"></a>
620 ### <a name="MAX( list ) - biggest value of a"></a> MAX( list ) - biggest value of a list or range of cells
622 - Syntax: <code>**$MAX( list )**</code>
623 - Example: To find the biggest number to the left of the current cell, write: <code>**%CALC\{"$MAX($LEFT())"\}%**</code>
624 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$MEDIAN()|Main/WebHome#FuncMEDIAN]]</code>, <code>[[$MIN()|Main/WebHome#FuncMIN]]</code>, <code>[[$PERCENTILE()|Main/WebHome#FuncPERCENTILE]]</code>
626 <a name="FuncMEDIAN"></a>
628 ### <a name="MEDIAN( list ) -- median of a li"></a> MEDIAN( list ) -- median of a list or range of cells
630 - Syntax: <code>**$MEDIAN( list )**</code>
631 - Example: <code>**%CALC\{"$MEDIAN(3, 9, 4, 5)"\}%**</code> returns <code>**4\.5**</code>
632 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$MAX()|Main/WebHome#FuncMAX]]</code>, <code>[[$MIN()|Main/WebHome#FuncMIN]]</code>, <code>[[$PERCENTILE()|Main/WebHome#FuncPERCENTILE]]</code>
634 <a name="FuncMIN"></a>
636 ### <a name="MIN( list ) -- smallest value of"></a> MIN( list ) -- smallest value of a list or range of cells
638 - Syntax: <code>**$MIN( list )**</code>
639 - Example: <code>**%CALC\{"$MIN(15, 3, 28)"\}%**</code> returns <code>**3**</code>
640 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$MAX()|Main/WebHome#FuncMAX]]</code>, <code>[[$MEDIAN()|Main/WebHome#FuncMEDIAN]]</code>, <code>[[$PERCENTILE()|Main/WebHome#FuncPERCENTILE]]</code>
642 <a name="FuncMOD"></a>
644 ### <a name="MOD( num, divisor ) -- reminder"></a><a name="MOD( num, divisor ) -- reminder "></a> MOD( num, divisor ) -- reminder after dividing <code>**num**</code> by <code>**divisor**</code>
646 - Syntax: <code>**$MOD( num, divisor )**</code>
647 - Example: <code>**%CALC\{"$MOD(7, 3)"\}%**</code> returns <code>**1**</code>
648 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>
650 <a name="FuncNOEXEC"></a>
652 ### <a name="NOEXEC( formula ) -- do not exec"></a> NOEXEC( formula ) -- do not execute a spreadsheet formula
654 - Prevent a formula from getting executed. This is typically used to store a raw formula in a variable for later use as described in <code>[[$EXEC()|Main/WebHome#FuncEXEC]]</code>.
655 - Syntax: <code>**$NOEXEC( formula )**</code>
656 - Example: <code>**%CALC\{"$SET(msg, $NOEXEC(Hi $GET(name)))"\}%**</code> sets the `msg` variable with the formula `Hi $GET(name)` without executing it
657 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$EXEC()|Main/WebHome#FuncEXEC]]</code>, <code>[[$GET()|Main/WebHome#FuncGET]]</code>, <code>[[$SET()|Main/WebHome#FuncSET]]</code>
659 <a name="FuncNOP"></a>
661 ### <a name="NOP( text ) -- no-operation"></a> NOP( text ) -- no-operation
663 - 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`
664 - Syntax: <code>**$NOP( text )**</code>
666 <a name="FuncNOT"></a>
668 ### <a name="NOT( num ) -- reverse logic of a"></a> NOT( num ) -- reverse logic of a number
670 - Returns 0 if <code>**num**</code> is not zero, 1 if zero
671 - Syntax: <code>**$NOT( num )**</code>
672 - Example: <code>**%CALC\{"$NOT(0)"\}%**</code> returns <code>**1**</code>
673 - Related: <code>[[$AND()|Main/WebHome#FuncAND]]</code>, <code>[[$EMPTY()|Main/WebHome#FuncEMPTY]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$OR()|Main/WebHome#FuncOR]]</code>
675 <a name="FuncODD"></a>
677 ### <a name="ODD( num ) -- test for odd numbe"></a> ODD( num ) -- test for odd number
679 - Syntax: <code>**$ODD( num )**</code>
680 - Example: <code>**%CALC\{"$ODD(2)"\}%**</code> returns <code>****</code>
681 - Related: <code>[[$ABS()|Main/WebHome#FuncABS]]</code>, <code>[[$EVEN()|Main/WebHome#FuncEVEN]]</code>, <code>[[$MOD()|Main/WebHome#FuncMOD]]</code>, <code>[[$SIGN()|Main/WebHome#FuncSIGN]]</code>
683 <a name="FuncOR"></a>
685 ### <a name="OR( list ) -- logical OR of a li"></a> OR( list ) -- logical OR of a list
687 - Syntax: <code>**$OR( list )**</code>
688 - Example: <code>**%CALC\{"$OR(1, 0, 1)"\}%**</code> returns <code>**1**</code>
689 - Related: <code>[[$AND()|Main/WebHome#FuncAND]]</code>, <code>[[$IF()|Main/WebHome#FuncIF]]</code>, <code>[[$NOT()|Main/WebHome#FuncNOT]]</code>
691 <a name="FuncPERCENTILE"></a>
693 ### <a name="PERCENTILE( num, list ) -- perce"></a> PERCENTILE( num, list ) -- percentile of a list or range of cells
695 - Calculates the num-th percentile, useful to establish a threshold of acceptance. num is the percentile value, range 0..100
696 - Syntax: <code>**$PERCENTILE( num, list )**</code>
697 - Example: <code>**%CALC\{"$PERCENTILE(75, 400, 200, 500, 100, 300)"\}%**</code> returns <code>**450**</code>
698 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$MAX()|Main/WebHome#FuncMAX]]</code>, <code>[[$MEDIAN()|Main/WebHome#FuncMEDIAN]]</code>, <code>[[$MIN()|Main/WebHome#FuncMIN]]</code>
700 <a name="FuncPI"></a>
702 ### <a name="PI( ) -- mathematical constant P"></a> PI( ) -- mathematical constant Pi, 3.14159265358979
704 - Syntax: <code>**$PI( )**</code>
705 - Example: <code>**%CALC\{"$PI()"\}%**</code> returns <code>**3\.14159265358979**</code>
707 <a name="FuncPRODUCT"></a>
709 ### <a name="PRODUCT( list ) -- product of a"></a><a name="PRODUCT( list ) -- product of a "></a> PRODUCT( list ) -- product of a list or range of cells
711 - Syntax: <code>**$PRODUCT( list )**</code>
712 - Example: To calculate the product of the cells to the left of the current one use <code>**%CALC\{"$PRODUCT($LEFT())"\}%**</code>
713 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$PRODUCT()|Main/WebHome#FuncPRODUCT]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>, <code>[[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]]</code>
715 <a name="FuncPROPER"></a>
717 ### <a name="PROPER( text ) -- properly capit"></a> PROPER( text ) -- properly capitalize text
719 - Capitalize letters that follow any character other than a letter; convert all other letters to lowercase letters
720 - Syntax: <code>**$PROPER( text )**</code>
721 - Example: <code>**%CALC\{"$PROPER(a small STEP)"\}%**</code> returns <code>**A Small Step**</code>
722 - Example: <code>**%CALC\{"$PROPER(f1 (formula-1))"\}%**</code> returns <code>**F1 (Formula-1)**</code>
723 - Related: <code>[[$LOWER()|Main/WebHome#FuncLOWER]]</code>, <code>[[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>, <code>[[$UPPER()|Main/WebHome#FuncUPPER]]</code>
725 <a name="FuncPROPERSPACE"></a>
727 ### <a name="PROPERSPACE( text ) -- properly"></a><a name="PROPERSPACE( text ) -- properly "></a> PROPERSPACE( text ) -- properly space out WikiWords
729 - Properly spaces out %SYSTEMWEB%.WikiWords preceeded by white space, parenthesis, or <code>**]\[**</code>. Words listed in the DONTSPACE %SYSTEMWEB%.TWikiPreferences variable or DONTSPACE plugins setting are excluded
730 - Syntax: <code>**$PROPERSPACE( text )**</code>
731 - Example: Assuming DONTSPACE contains MacDonald: <code>**%CALC\{"$PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh)"\}%**</code> returns <code>**Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh**</code>
732 - Related: <code>[[$LOWER()|Main/WebHome#FuncLOWER]]</code>, <code>[[$PROPER()|Main/WebHome#FuncPROPER]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>, <code>[[$UPPER()|Main/WebHome#FuncUPPER]]</code>
734 <a name="FuncRAND"></a>
736 ### <a name="RAND( max ) -- random number"></a> RAND( max ) -- random number
738 - Random number, evenly distributed between 0 and <code>**max**</code>, or 0 and 1 if max is not specified
739 - Syntax: <code>**$RAND( max )**</code>
740 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$LISTRAND()|Main/WebHome#FuncLISTRAND]]</code>, <code>[[$LISTSHUFFLE()|Main/WebHome#FuncLISTSHUFFLE]]</code>
742 <a name="FuncREPEAT"></a>
744 ### <a name="REPEAT( text, num ) -- repeat te"></a> REPEAT( text, num ) -- repeat text a number of times
746 - Syntax: <code>**$REPEAT( text, num )**</code>
747 - Example: <code>**%CALC\{"$REPEAT(/\\, 5)"\}%**</code> returns <code>**/\\/\\/\\/\\/\\**</code>
749 <a name="FuncREPLACE"></a>
751 ### <a name="REPLACE( text, start, num, new )"></a> REPLACE( text, start, num, new ) -- replace part of a text string
753 - 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
754 - Syntax: <code>**$REPLACE( text, start, num, new )**</code>
755 - Example: <code>**%CALC\{"$REPLACE(abcdefghijk, 6, 5, \*)"\}%**</code> returns <code>**abcde\*k**</code>
756 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
758 <a name="FuncRIGHT"></a>
760 ### <a name="RIGHT( ) -- address range of cel"></a> RIGHT( ) -- address range of cells to the right of the current cell
762 - Syntax: <code>**$RIGHT( )**</code>
763 - Example: <code>**%CALC\{"$SUM($RIGHT())"\}%**</code> returns the sum of cells to the right of the current cell
764 - Related: <code>[[$ABOVE()|Main/WebHome#FuncABOVE]]</code>, <code>[[$LEFT()|Main/WebHome#FuncLEFT]]</code>
766 <a name="FuncRIGHTSTRING"></a>
768 ### <a name="RIGHTSTRING( text, num ) -- extr"></a> RIGHTSTRING( text, num ) -- extract characters at the end of a text string
770 - Retrieve the `num` of characters from the right end of `text`; the rightmost character is returned if `num` is missing
771 - Syntax: <code>**$RIGHTSTRING( text, _num_ )**</code>
772 - Example: <code>**%CALC\{"$RIGHTSTRING(abcdefg)"\}%**</code> returns <code>**g**</code>
773 - Example: <code>**%CALC\{"$RIGHTSTRING(abcdefg, 5)"\}%**</code> returns <code>**cdefg**</code>
774 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
776 <a name="FuncROUND"></a>
778 ### <a name="ROUND( formula, digits ) -- roun"></a> ROUND( formula, digits ) -- round a number
780 - Evaluates a simple <code>**formula**</code> and rounds the result up or down to the number of digits if <code>**digits**</code> is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative
781 - Syntax: <code>**$ROUND( formula, digits )**</code>
782 - Example: <code>**%CALC\{"$ROUND(3.15, 1)"\}%**</code> returns <code>**3\.2**</code>
783 - Example: <code>**%CALC\{"$ROUND(3.149, 1)"\}%**</code> returns <code>**3\.1**</code>
784 - Example: <code>**%CALC\{"$ROUND(-2.475, 2)"\}%**</code> returns <code>**-2.48**</code>
785 - Example: <code>**%CALC\{"$ROUND(34.9, -1)"\}%**</code> returns <code>**30**</code>
786 - Related: <code>[[$INT()|Main/WebHome#FuncINT]]</code>, <code>[[$FORMAT()|Main/WebHome#FuncFORMAT]]</code>
788 <a name="FuncROW"></a>
790 ### <a name="ROW( offset ) -- current row num"></a> ROW( offset ) -- current row number
792 - The current table row number with an optional offset
793 - Syntax: <code>**$ROW( _offset_ )**</code>
794 - Example: To get the number of rows excluding table heading (first row) and summary row (last row you are in), write: <code>**%CALC\{"$ROW(-2)"\}%**</code>
795 - Related: <code>[[$COLUMN()|Main/WebHome#FuncCOLUMN]]</code>, <code>[[$T()|Main/WebHome#FuncT]]</code>
797 <a name="FuncSEARCH"></a>
799 ### <a name="SEARCH( string, text, start ) --"></a> SEARCH( string, text, start ) -- search a string within a text
801 - 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 %SYSTEMWEB%.RegularExpression search; use `$FIND()` for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
802 - Syntax: <code>**$SEARCH( string, text, _start_ )**</code>
803 - Example: <code>**%CALC\{"$SEARCH([uy], fluffy)"\}%**</code> returns <code>**3**</code>
804 - Example: <code>**%CALC\{"$SEARCH([uy], fluffy, 3)"\}%**</code> returns <code>**6**</code>
805 - Example: <code>**%CALC\{"$SEARCH([abc], fluffy,)"\}%**</code> returns <code>****</code>
806 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>
808 <a name="FuncSET"></a>
810 ### <a name="SET( name, value ) -- set a vari"></a> SET( name, value ) -- set a variable for later use
812 - Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulae are evaluated before the variable assignment; see <code>[[$NOEXEC()|Main/WebHome#FuncNOEXEC]]</code> 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
813 - Syntax: <code>**$SET( name, value )**</code>
814 - Example: <code>**%CALC\{"$SET(my\_total, $SUM($ABOVE()))"\}%**</code> sets the `my_total` variable to the sum of all table cells located above the current cell and returns an empty string
815 - Related: <code>[[$EXEC()|Main/WebHome#FuncEXEC]]</code>, <code>[[$GET()|Main/WebHome#FuncGET]]</code>, <code>[[$NOEXEC()|Main/WebHome#FuncNOEXEC]]</code>, <code>[[$SETIFEMPTY()|Main/WebHome#FuncSETIFEMPTY]]</code>, <code>[[SETM()|Main/WebHome#FuncSETM]]</code>
817 <a name="FuncSETIFEMPTY"></a>
819 ### <a name="SETIFEMPTY( name, value ) -- set"></a> SETIFEMPTY( name, value ) -- set a variable only if empty
821 - Specify the variable name (alphanumeric characters and underscores) and the value.
822 - Syntax: <code>**$SETIFEMPTY( name, value )**</code>
823 - Example: <code>**%CALC\{"$SETIFEMPTY(result, default)"\}%**</code> sets the `result` variable to `default` if the variable is empty or 0; in any case an empty string is returned
824 - Related: <code>[[$GET()|Main/WebHome#FuncGET]]</code>, <code>[[$SET()|Main/WebHome#FuncSET]]</code>
826 <a name="FuncSETM"></a>
828 ### <a name="SETM( name, formula ) -- update"></a><a name="SETM( name, formula ) -- update "></a> SETM( name, formula ) -- update an existing variable based on a formula
830 - Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to <code>**+**</code> (add), <code>**-**</code> (subtract), <code>**\***</code> (multiply), or <code>**/**</code> (divide) something to the variable. This function returns no output. Use `$GET()` to retrieve variables
831 - Syntax: <code>**$SETM( name, formula )**</code>
832 - Example: <code>**%CALC\{"$SETM(total, + $SUM($LEFT()))"\}%**</code> adds the sum of all table cells on the left to the `total` variable, and returns an empty string
833 - Related: <code>[[$GET()|Main/WebHome#FuncGET]]</code>, <code>[[$SET()|Main/WebHome#FuncSET]]</code>, <code>[[$SETIFEMPTY()|Main/WebHome#FuncSETIFEMPTY]]</code>
835 <a name="FuncSIGN"></a>
837 ### <a name="SIGN( num ) -- sign of a number"></a> SIGN( num ) -- sign of a number
839 - Returns -1 if <code>**num**</code> is negative, 0 if zero, or 1 if positive
840 - Syntax: <code>**$SIGN( num )**</code>
841 - Example: <code>**%CALC\{"$SIGN(-12.5)"\}%**</code> returns <code>**-1**</code>
842 - Related: <code>[[$ABS()|Main/WebHome#FuncABS]]</code>, <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$EVEN()|Main/WebHome#FuncEVEN]]</code>, <code>[[$INT()|Main/WebHome#FuncINT]]</code>, <code>[[$NOT()|Main/WebHome#FuncNOT]]</code>, <code>[[$ODD()|Main/WebHome#FuncODD]]</code>
844 <a name="FuncSQRT"></a>
846 ### <a name="SQRT( num ) -- square root of a"></a><a name="SQRT( num ) -- square root of a "></a> SQRT( num ) -- square root of a number
848 - Syntax: <code>**$SQRT( num )**</code>
849 - Example: <code>**%CALC\{"$SQRT(16)"\}%**</code> returns <code>**4**</code>
851 <a name="FuncSUBSTITUTE"></a>
853 ### <a name="SUBSTITUTE( text, old, new, inst"></a> SUBSTITUTE( text, old, new, instance, option ) -- substitute text
855 - 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 %SYSTEMWEB%.RegularExpression search if the `option` is set to <code>**r**</code>
856 - Syntax: <code>**$SUBSTITUTE( text, old, _new_, _instance_, _option_ )**</code>
857 - Example: <code>**%CALC\{"$SUBSTITUTE(Good morning, morning, day)"\}%**</code> returns <code>**Good day**</code>
858 - Example: <code>**%CALC\{"$SUBSTITUTE(Q2-2002, 2, 3)"\}%**</code> returns <code>**Q3-3003**</code>
859 - Example: <code>**%CALC\{"$SUBSTITUTE(Q2-2002,2, 3, 3)"\}%**</code> returns <code>**Q2-2003**</code>
860 - Example: <code>**%CALC\{"$SUBSTITUTE(abc123def, [0-9], 9, , r)"\}%**</code> returns <code>**abc999def**</code>
861 - Related: <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
863 <a name="FuncSUBSTRING"></a>
865 ### <a name="SUBSTRING( text, start, num ) --"></a> SUBSTRING( text, start, num ) -- extract a substring out of a text string
867 - Extract `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
868 - Syntax: <code>**$SUBSTRING( text, start, num )**</code>
869 - Example: <code>**%CALC\{"$SUBSTRING(abcdefghijk, 3, 5)"\}%**</code> returns <code>**cdefg**</code>
870 - Related: <code>[[$FIND()|Main/WebHome#FuncFIND]]</code>, <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SEARCH()|Main/WebHome#FuncSEARCH]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>, <code>[[$TRANSLATE()|Main/WebHome#FuncTRANSLATE]]</code>
872 <a name="FuncSUM"></a>
874 ### <a name="SUM( list ) -- sum of a list or"></a><a name="SUM( list ) -- sum of a list or "></a> SUM( list ) -- sum of a list or range of cells
876 - Syntax: <code>**$SUM( list )**</code>
877 - Example: To sum up column 5 excluding the title row, write <code>**%CALC\{"$SUM(R2:C5..R$ROW(-1):C5)"\}%**</code> in the last row; or simply <code>**%CALC\{"$SUM($ABOVE())"\}%**</code>
878 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$PRODUCT()|Main/WebHome#FuncPRODUCT]]</code>, <code>[[$SUMPRODUCT()|Main/WebHome#FuncSUMPRODUCT]]</code>, <code>[[$WORKINGDAYS()|Main/WebHome#FuncWORKINGDAYS]]</code>
880 <a name="FuncSUMDAYS"></a>
882 ### <a name="SUMDAYS( list ) -- sum the days"></a><a name="SUMDAYS( list ) -- sum the days "></a> SUMDAYS( list ) -- sum the days in a list or range of cells
884 - 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 <code>**h**</code>, <code>**hours**</code>, <code>**d**</code>, <code>**days**</code>, <code>**w**</code>, <code>**weeks**</code> suffix. One week is assumed to have 5 working days, one day 8 hours
885 - Syntax: <code>**$SUMDAYS( list )**</code>
886 - Example: <code>**%CALC\{"$SUMDAYS(2w, 1, 2d, 4h)"\}%**</code> returns <code>**13\.5**</code>, the evaluation of `(2*5 + 1 + 2 + 4/8)`
887 - Related: <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>
889 <a name="FuncSUMPRODUCT"></a>
891 ### <a name="SUMPRODUCT( list, list ) -- scal"></a> SUMPRODUCT( list, list ) -- scalar product on ranges of cells
893 - Syntax: <code>**$SUMPRODUCT( list, list, _list..._ )**</code>
894 - Example: <code>**%CALC\{"$SUMPRODUCT(R2:C1..R4:C1, R2:C5..R4:C5)"\}%**</code> evaluates and returns the result of <code>**($T(R2:C1) \* $T(R2:C5) + $T(R3:C1) \* $T(R3:C5) + $T(R4:C1) \* $T(R4:C5))**</code>
895 - Related: <code>[[$LIST()|Main/WebHome#FuncLIST]]</code>, <code>[[$PRODUCT()|Main/WebHome#FuncPRODUCT]]</code>, <code>[[$SUM()|Main/WebHome#FuncSUM]]</code>
899 ### <a name="T( address ) -- content of a cel"></a> T( address ) -- content of a cell
901 - Syntax: <code>**$T( address )**</code>
902 - Example: <code>**%CALC\{"$T(R1:C5)"\}%**</code> returns the text in cell <code>**R1:C5**</code>
903 - Related: <code>[[$COLUMN()|Main/WebHome#FuncCOLUMN]]</code>, <code>[[$ROW()|Main/WebHome#FuncROW]]</code>
905 <a name="FuncTRANSLATE"></a>
907 ### <a name="TRANSLATE( text, from, to ) -- t"></a> TRANSLATE( text, from, to ) -- translate text from one set of characters to another
909 - 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
910 - Syntax: <code>**$TRANSLATE( text, from, to )**</code>
911 - Example: <code>**%CALC\{"$TRANSLATE(boom,bm,cl)"\}%**</code> returns <code>**cool**</code>
912 - Example: <code>**%CALC\{"$TRANSLATE(one, two,$comma,;)"\}%**</code> returns <code>**one; two**</code>
913 - Related: <code>[[$INSERTSTRING()|Main/WebHome#FuncINSERTSTRING]]</code>, <code>[[$LEFTSTRING()|Main/WebHome#FuncLEFTSTRING]]</code>, <code>[[$REPLACE()|Main/WebHome#FuncREPLACE]]</code>, <code>[[$RIGHTSTRING()|Main/WebHome#FuncRIGHTSTRING]]</code>, <code>[[$SUBSTRING()|Main/WebHome#FuncSUBSTRING]]</code>, <code>[[$SUBSTITUTE()|Main/WebHome#FuncSUBSTITUTE]]</code>
915 <a name="FuncTIME"></a>
917 ### <a name="TIME( text ) -- convert a date s"></a> TIME( text ) -- convert a date string into a serialized date number
919 - 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
920 - Syntax: <code>**$TIME( _text_ )**</code>
921 - Example: <code>**%CALC\{"$TIME(2003/10/14 GMT)"\}%**</code> returns <code>**1066089600**</code>
922 - Related: <code>[[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]]</code>, <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATTIMEDIFF()|Main/WebHome#FuncFORMATTIMEDIFF]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>, <code>[[$TODAY()|Main/WebHome#FuncTODAY]]</code>, <code>[[$WORKINGDAYS()|Main/WebHome#FuncWORKINGDAYS]]</code>
924 <a name="FuncTIMEADD"></a>
926 ### <a name="TIMEADD( serial, value, unit ) -"></a> TIMEADD( serial, value, unit ) -- add a value to a serialized date
928 - 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
929 - Syntax: <code>**$TIMEADD( serial, value, _unit_ )**</code>
930 - Example: <code>**%CALC\{"$TIMEADD($TIME(), 2, week)"\}%**</code> returns the serialized date two weeks from now
931 - Related: <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>, <code>[[$TODAY()|Main/WebHome#FuncTODAY]]</code>
933 <a name="FuncTIMEDIFF"></a>
935 ### <a name="TIMEDIFF( serial_1, serial_2, un"></a> TIMEDIFF( serial\_1, serial\_2, unit ) -- time difference between two serialized dates
937 - 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()`, `$FORMATTIMEDIFF()` or `$INT()` to format real numbers
938 - Syntax: <code>**$TIMEDIFF( serial\_1, serial\_2, _unit_ )**</code>
939 - Example: <code>**%CALC\{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"\}%**</code> returns <code>**1\.5**</code>
940 - Related: <code>[[$FORMAT()|Main/WebHome#FuncFORMAT]]</code>, <code>[[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]]</code>, <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATTIMEDIFF()|Main/WebHome#FuncFORMATTIMEDIFF]]</code>, <code>[[$INT()|Main/WebHome#FuncINT]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TODAY()|Main/WebHome#FuncTODAY]]</code>, <code>[[$WORKINGDAYS()|Main/WebHome#FuncWORKINGDAYS]]</code>
942 <a name="FuncTODAY"></a>
944 ### <a name="TODAY( ) -- serialized date of t"></a> TODAY( ) -- serialized date of today at midnight GMT
946 - 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
947 - Syntax: <code>**$TODAY( )**</code>
948 - Example: <code>**%CALC\{"$TODAY()"\}%**</code> returns the number of seconds since Epoch
949 - Related: <code>[[$FORMATTIME()|Main/WebHome#FuncFORMATTIME]]</code>, <code>[[$FORMATGMTIME()|Main/WebHome#FuncFORMATGMTIME]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEADD()|Main/WebHome#FuncTIMEADD]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>
951 <a name="FuncTRIM"></a>
953 ### <a name="TRIM( text ) -- trim spaces from"></a> TRIM( text ) -- trim spaces from text
955 - Removes all spaces from text except for single spaces between words
956 - Syntax: <code>**$TRIM( text )**</code>
957 - Example: <code>**%CALC\{"$TRIM( eat spaces )"\}%**</code> returns <code>**eat spaces**</code>
958 - Related: <code>[[$EMPTY()|Main/WebHome#FuncEMPTY]]</code>, <code>[[$EXACT()|Main/WebHome#FuncEXACT]]</code>, <code>[[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]]</code>
960 <a name="FuncUPPER"></a>
962 ### <a name="UPPER( text ) -- upper case stri"></a> UPPER( text ) -- upper case string of a text
964 - Syntax: <code>**$UPPER( text )**</code>
965 - Example: <code>**%CALC\{"$UPPER($T(R1:C5))"\}%**</code> returns the upper case string of the text in cell <code>**R1:C5**</code>
966 - Related: <code>[[$LOWER()|Main/WebHome#FuncLOWER]]</code>, <code>[[$PROPER()|Main/WebHome#FuncPROPER]]</code>, <code>[[$PROPERSPACE()|Main/WebHome#FuncPROPERSPACE]]</code>, <code>[[$TRIM()|Main/WebHome#FuncTRIM]]</code>
968 <a name="FuncVALUE"></a>
970 ### <a name="VALUE( text ) -- convert text to"></a> VALUE( text ) -- convert text to number
972 - Extracts a number from <code>**text**</code>. Returns <code>****</code> if not found
973 - Syntax: <code>**$VALUE( text )**</code>
974 - Example: <code>**%CALC\{"$VALUE(US$1,200)"\}%**</code> returns <code>**1200**</code>
975 - Example: <code>**%CALC\{"$VALUE(PrjNotebook1234)"\}%**</code> returns <code>**1234**</code>
976 - Example: <code>**%CALC\{"$VALUE(Total: -12.5)"\}%**</code> returns <code>**-12.5**</code>
977 - Related: <code>[[$EVAL()|Main/WebHome#FuncEVAL]]</code>, <code>[[$INT()|Main/WebHome#FuncINT]]</code>
979 <a name="FuncWORKINGDAYS"></a>
981 ### <a name="WORKINGDAYS( serial_1, serial_2"></a><a name="WORKINGDAYS( serial_1, serial_2 "></a> WORKINGDAYS( serial\_1, serial\_2 ) -- working days between two serialized dates
983 - Working days are Monday through Friday (sorry, Israel!)
984 - Syntax: <code>**$WORKINGDAYS( serial\_1, serial\_2 )**</code>
985 - Example: <code>**%CALC\{"$WORKINGDAYS($TIME(2004/07/15), $TIME(2004/08/03))"\}%**</code> returns <code>**13**</code>
986 - Related: <code>[[$SUMDAYS()|Main/WebHome#FuncSUMDAYS]]</code>, <code>[[$TIME()|Main/WebHome#FuncTIME]]</code>, <code>[[$TIMEDIFF()|Main/WebHome#FuncTIMEDIFF]]</code>
988 ## <a name="FAQ"></a> FAQ
990 <a name="CalcInFormattedSearch"></a>
992 ### <a name="Can I use CALC in a formatted se"></a> Can I use CALC in a formatted search?
994 Specifically, how can I output some conditional text in a %SYSTEMWEB%.FormattedSearch?
996 You need to escape the CALC so that it executes once per search hit. This can be done by escaping the `%` signs of `%CALC{...}%` with `$percnt`. For example, to execute `$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif)` in the `format=""` parameter, write this:
998 `%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%`
1000 ### <a name="How can I easily repeat a formul"></a> How can I easily repeat a formula in a table?
1002 To repeat the same formula in all cells of a table row define the formula once in a preferences setting and use that in the CALC. The preferences setting can be hidden in HTML comments. Example:
1005 * Set MYFORMULA = $EVAL($SUBSTITUTE(...etc...))
1007 | A | 1 | %CALC{%MYFORMULA%}% |
1008 | B | 2 | %CALC{%MYFORMULA%}% |
1009 | C | 3 | %CALC{%MYFORMULA%}% |
1011 ## <a name="Bug Tracking Example"></a> Bug Tracking Example
1013 <table border="1" cellpadding="0" cellspacing="0">
1015 <th bgcolor="#99CCCC"><strong> Bug#: </strong></th>
1016 <th bgcolor="#99CCCC"><strong> Priority: </strong></th>
1017 <th bgcolor="#99CCCC"><strong> Subject: </strong></th>
1018 <th bgcolor="#99CCCC"><strong> Status: </strong></th>
1019 <th bgcolor="#99CCCC"><strong> Days to fix </strong></th>
1024 <td> File Open ... </td>
1026 <td align="right"> 3 </td>
1031 <td> Memory Window ... </td>
1033 <td align="right"> 2 </td>
1038 <td> Usability issue ... </td>
1040 <td align="right"> 5 </td>
1045 <td> No arrange ... </td>
1047 <td align="right"> 1 </td>
1051 <td> High: 2<br /> Low: 1<br /> Medium: 1 </td>
1053 <td> Assigned: 1<br /> Fixed: 2<br /> Open: 1 </td>
1054 <td align="right"> Total: 11 </td>
1058 The last row is defined as:
1060 | Total: %CALC{"$ROW(-2)"}% \
1061 | %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% | . \
1062 | %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% \
1063 | Total: %CALC{"$SUM( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% |
1065 Above table is created manually. Another plugin could build the table dynamically, e.g. by pulling data out of a bug tracking system. The Spreadsheet plugin can be used to display table data statistics.
1067 ## <a name="Plugin Settings"></a> Plugin Settings
1069 Plugin settings are stored as preferences variables. To reference a plugin setting write <code>**%<plugin>\_<setting>%**</code>, i.e. <code>**%SPREADSHEETPLUGIN\_SHORTDESCRIPTION%**</code>
1071 - One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
1072 - Set SHORTDESCRIPTION = Add spreadsheet calculation like `"$SUM( $ABOVE() )"` to TWiki tables and other topic text
1074 - Debug plugin: (See output in `data/debug.txt`)
1077 - Do not handle `%CALC{}%` variable in included topic while including topic: (default: 1)
1078 - Set SKIPINCLUDE = 1
1080 - [[WikiWords|SYSTEMWEB/WikiWord]] to exclude from being spaced out by the <code>**$PROPERSPACE(text)**</code> function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
1081 - Set DONTSPACE = CodeWarrior, MacDonald, McIntosh, RedHat, SuSE
1083 ## <a name="Plugin Installation Instructions"></a> Plugin Installation Instructions
1085 **_Note:_** You do not need to install anything on the browser to use this plugin. Below installation instructions are for the administrator who needs to install this plugin on the TWiki server.
1087 - Download the ZIP file from the %TOPIC% home
1088 - Unzip <code>**SpreadSheetPlugin.zip**</code> in your twiki installation directory. Content: <table border="1" cellpadding="0" cellspacing="0">
1090 <th bgcolor="#99CCCC"><strong> File: </strong></th>
1091 <th bgcolor="#99CCCC"><strong> Description: </strong></th>
1094 <td><code><b>data/TWiki/%TOPIC%.txt</b></code></td>
1095 <td> Plugin topic </td>
1098 <td><code><b>data/TWiki/%TOPIC%.txt,v</b></code></td>
1099 <td> Plugin topic repository </td>
1102 <td><code><b>lib/TWiki/Plugins/%TOPIC%.pm</b></code></td>
1103 <td> Plugin Perl module </td>
1106 - TWiki 4 and up: Visit `configure` in your TWiki installation, and enable the plugin in the \{Plugins\} section.
1107 - Test if the "Total" in the first table in this topic is correct.
1109 ## <a name="Plugin Info"></a> Plugin Info
1111 <table border="1" cellpadding="0" cellspacing="0">
1113 <td align="right"> Plugin Author: </td>
1114 <td> TWiki:Main/PeterThoeny </td>
1117 <td align="right"> Copyright: </td>
1118 <td> © 2001-2009, Peter Thoeny, <a href="http://www.twiki.net/" target="_top">TWIKI.NET</a></td>
1121 <td align="right"> License: </td>
1122 <td> GPL (<a href="http://www.gnu.org/copyleft/gpl.html" target="_top">GNU General Public License</a>) </td>
1125 <td align="right"> Plugin Version: </td>
1126 <td> 26 Mar 2009 (17910) </td>
1129 <td align="right"> Change History: </td>
1133 <td align="right"> 26 Mar 2009: </td>
1134 <td> Added $INSERTSTRING() </td>
1137 <td align="right"> 25 Mar 2009: </td>
1138 <td> Added $EMPTY(), $LEFTSTRING(), $RIGHTSTRING(), $SUBSTRING() </td>
1141 <td align="right"> 24 Mar 2009: </td>
1142 <td> Fixed bug in $REPLACE() if to-be-replaced string is "0"; fixed bug in $SUBSTITUTE() if replace string is empty; improved docs </td>
1145 <td align="right"> 13 Oct 2007: </td>
1146 <td> Added $FORMATTIMEDIFF() </td>
1149 <td align="right"> 09 Sep 2007: </td>
1150 <td> Enhanced documentation for $EVAL() and $INT() </td>
1153 <td align="right"> 02 Jun 2007: </td>
1154 <td> Added [[TWiki/VarCALC]] to have <code>%CALC{}%</code> listed in [[TWiki/TWikiVariables]]</td>
1157 <td align="right"> 14 Apr 2007: </td>
1158 <td> Fixing bug in $EXISTS() that required full <code>web.topic</code> instead of just <code>topic</code></td>
1161 <td align="right"> 11 Mar 2007: </td>
1162 <td> Fixing bug in $VALUE() and $INT(), introduced by version 09 Mar 2007 </td>
1165 <td align="right"> 09 Mar 2007: </td>
1166 <td> Added $EXP(), $LN(), $LOG(), $PI(), $SQRT(); fixed $ROUND() bug, contributed by TWiki:Main/SergejZnamenskij </td>
1169 <td align="right"> 23 Jan 2007: </td>
1170 <td> Enhanced documentation </td>
1173 <td align="right"> 18 Dec 2006: </td>
1174 <td> Added $LISTRAND(), $LISTSHUFFLE(), $LISTTRUNCATE(); fixed spurious newline at end of topic, contributed by TWiki:Main/MichaelDaum </td>
1177 <td align="right"> 10 Oct 2006: </td>
1178 <td> Enhanced documentation </td>
1181 <td align="right"> 13 May 2006: </td>
1182 <td> Added $SETIFEMPTY(); fixes in documentation </td>
1185 <td align="right"> 17 Jun 2005: </td>
1186 <td> Added $NOEXEC(), $EXEC() </td>
1189 <td align="right"> 25 Mar 2005: </td>
1190 <td> Fixed evaluation bug when using SpeedyCGI accelerator; code refactor to load module only when needed, contributed by TWiki:Main/CrawfordCurrie </td>
1193 <td align="right"> 24 Oct 2004: </td>
1194 <td> Added $EXISTS(), contributed by TWiki:Main/RodrigoChandia; added $PERCENTILE() </td>
1197 <td align="right"> 18 Oct 2004: </td>
1198 <td> Added $LISTJOIN() </td>
1201 <td align="right"> 26 Sep 2004: </td>
1202 <td> Added $FORMAT(KB), $FORMAT(MB), contributed by TWiki:Main/ArthurClemens; added $FORMAT(KBMB), $EVEN(), $ODD() </td>
1205 <td align="right"> 17 Jul 2004: </td>
1206 <td> Added $WORKINGDAYS(), contributed by TWiki:Main/CrawfordCurrie </td>
1209 <td align="right"> 24 May 2004: </td>
1210 <td> Refactored documentation (no code changes) </td>
1213 <td align="right"> 03 Apr 2004: </td>
1214 <td> Added $ABS(), $LISTIF(); fixed $VALUE() to remove leading zeros; changed $FIND() and $SEARCH() to return 0 instead of empty string if no match </td>
1217 <td align="right"> 21 Mar 2004: </td>
1218 <td> Added $LISTITEM(); fixed call to unofficial function </td>
1221 <td align="right"> 16 Mar 2004: </td>
1222 <td> 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 </td>
1225 <td align="right"> 08 Mar 2004: </td>
1226 <td> Added $LIST() </td>
1229 <td align="right"> 06 Mar 2004: </td>
1230 <td> 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 </td>
1233 <td align="right"> 27 Feb 2004: </td>
1234 <td> Added $COUNTUNIQUE() </td>
1237 <td align="right"> 24 Oct 2003: </td>
1238 <td> Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit </td>
1241 <td align="right"> 21 Oct 2003: </td>
1242 <td> Added support for lists <code>(1, 2, 3)</code> and lists of table ranges <code>(R1:C1..R1:C5, R3:C1..R3:C5)</code> 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 </td>
1245 <td align="right"> 14 Oct 2003: </td>
1246 <td> Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF() </td>
1249 <td align="right"> 13 Oct 2003: </td>
1250 <td> Added $MULT(), contributed by TWiki:Main/GerritJanBaarda </td>
1253 <td align="right"> 30 Jul 2003: </td>
1254 <td> Added $TRANSLATE() </td>
1257 <td align="right"> 19 Jul 2003: </td>
1258 <td> Added $FIND(), $NOP(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), contributed by TWiki:Main/PaulineCheung </td>
1261 <td align="right"> 19 Apr 2003: </td>
1262 <td> Added $COUNTSTR(), $EXACT(), $IF(), $ROUND(), $TRIM(); added $FORMAT(), contributed by TWiki:Main/JimStraus; support <code>%</code> modulus operator in $EVAL(), $INT(), and $ROUND(); fixed bug in $DEF() </td>
1265 <td align="right"> 07 Jun 2002: </td>
1266 <td> Added $DEF(), contributed by TWiki:Main/MartinFuzzey; allow values with HTML formatting like <code><u>102</u></code>, suggested by TWiki:Main/GladeDiviney; added SKIPINCLUDE setting </td>
1269 <td align="right"> 12 Mar 2002: </td>
1270 <td> Support for multiple functions per nesting level </td>
1273 <td align="right"> 15 Jan 2002: </td>
1274 <td> Added $CHAR(), $CODE() and $LENGTH() </td>
1277 <td align="right"> 12 Nov 2001: </td>
1278 <td> Added $RIGHT() </td>
1281 <td align="right"> 12 Aug 2001: </td>
1282 <td> Fixed bug of disappearing multi-column cells </td>
1285 <td align="right"> 19 Jul 2001: </td>
1286 <td> Fixed incorrect $SUM() calculation of cell with value <code>0</code></td>
1289 <td align="right"> 14 Jul 2001: </td>
1290 <td> Changed to plug & play </td>
1293 <td align="right"> 01 Jun 2001: </td>
1294 <td> Fixed insecure dependencies for $MIN() and $MAX() </td>
1297 <td align="right"> 16 Apr 2001: </td>
1298 <td> Fixed div by 0 bug in $AVERAGE() </td>
1301 <td align="right"> 17 Mar 2001: </td>
1302 <td> Initial version with $ABOVE(), $AVERAGE(), $COLUMN(), $COUNTITEMS(), $EVAL(), $INT(), $LEFT(), $LOWER(), $MAX(), $MIN(), $ROW(), $SUM(), $T(), $UPPER() </td>
1305 <td align="right"> CPAN Dependencies: </td>
1309 <td align="right"> TWiki:Plugins/Benchmark: </td>
1310 <td> %SYSTEMWEB%.GoodStyle 99%, %SYSTEMWEB%.FormattedSearch 99%, %TOPIC% 95% </td>
1313 <td align="right"> Other Dependencies: </td>
1317 <td align="right"> Perl Version: </td>
1318 <td> 5.000 and up </td>
1321 <td align="right"> Plugin Home: </td>
1322 <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%</a></td>
1325 <td align="right"> Feedback: </td>
1326 <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev</a></td>
1329 <td align="right"> Appraisal: </td>
1330 <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Appraisal" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Appraisal</a></td>
1334 **_Related Topics:_** %SYSTEMWEB%.TWikiPreferences, %SYSTEMWEB%.TWikiPlugins, %SYSTEMWEB%.VarCALC
1336 -- TWiki:Main/PeterThoeny - 26 Mar 2009