# List of functions in Envision

Home » Resources » Here

This page lists the functions supported by Envision. The primary purpose of functions is to extend the capabilities of Envision whenever the basic language syntax would not be sufficient.

## Function syntax

The general syntax for functions is:
x = fun(arg1, arg2, arg3)

With fun replaced by the name of the function, and the argN, the comma-delimited list of arguments passed to the function. All functions operate on vectors.

## Mathematical functions

• abs(number): similar to the ABS function in Excel.
• ceiling(number): similar to the CEILING function in Excel.
• exp(number): similar to the EXP function in Excel.
• floor(number): similar to the FLOOR function in Excel.
• log(number, base): similar to the LOG function in Excel. The base argument is optional, when it is omitted, it is assumed to be 10.
• max(num1, num2, num3, ..., numN): similar to the MAX function in Excel.
• min(num1, num2, num3, ..., numN): similar to the MIN function in Excel.
• norminv(number): similar to the NORMINV function in Excel with a mean at 0 and a standard deviation at 1.
• pow(number, exponent): similar to the POWER function in Excel. Envision also support the power operator number ^ exponent which performs the same calculation.
• round(number, digits): similar to the ROUND function in Excel. Second argument is optional, and represents the number of digits that intended to be kept.
• sqrt(number): similar to the SQRT function in Excel.

## Text functions

• concat(text1, text2, ..., textN): concatenate text values from text1 to textN.
• contains(text, pattern): Returns true if the text contains an occurrence of the pattern.
• endswith(text, pattern): Returns true if the text ends with an occurrence of the pattern.
• indexof(text, pattern): Returns the index of the first occurrence of the pattern within the text, or -1, if not such occurrence is found.
• lowercase(text): Returns the lowercase variant of the text.
• parsedate(text, format): Converts the text into a date using the specified format. The format is optional. When the format is omitted, the date is parsed based on the date format auto-detection behavior of Envision. When the format is provided, the date is parsed against the format expectation. See custom date format string for the detail for the format syntax. If a date cannot be parsed, the date 2001-01-01 is returned instead.
• parsenumber(text): Converts the text into a number. The parser leverages the number format auto-detection behavior of Envision. If the number cannot be parsed, zero is returned instead.
• parsetime(text, format): Converts a time of the day into a fraction between 0 and 1, representing a fractional day. The format is optional. When the format is not specified, the default value yyyy-MM-dd HH:mm:ss is used. Envision is using the .NET Custom Time Format.
• replace(text, pattern, replacement): Returns the text where all occurrences of the pattern have been replaced by the replacement. This function is similar to the SUBSTITUTE function of Excel, omitting the instance_num argument.
• startswith(text, pattern): Return true if the text starts with an occurrence of the pattern.
• strlen(text): Returns the length of the text argument.
• substr(text, start, count): The start position is defined by start. If negative, it's an offset from the end of the string, otherwise it's an offset from the start of the string. The length of the returned substring is defined by count, treated as 0 if count < 0. If the segment start or length place it partially or completely outside the string, e.g. substr("A", 2, 1), then the segment is clipped to fit. Function substr(text, start) is defined as substr(text, start, <infinity>).
• uppercase(text): Returns the uppercase variant of the text.

## Calendar functions

• "\{myDate:yyyy-MM-dd}": custom date formatting through string interpolation. The date format is specified by the token found after the semi-colon. More details about date format strings.
• chineseYear(date): Returns the current year in the Chinese calendar.
• chineseYearEnd(date): Returns the last day of the current Chinese Year.
• chineseYearStart(date): Returns the first day of the current Chinese year.
• date(y, m, d): Returns a date built from the year, month and day passed as arguments. The arguments y, m and d are expected to be numbers.
• monday(date): Returns the first Monday that precedes the date (inclusive).
• month(date): Returns the index of the month associated to the date, counting the number of months since January 1st 2001.
• monthnum(date): Returns the applicable month (1-12) for the date passed as argument.
• today(timezone): Return the current wall-time date with the time-zone passed as argument and expressed as the difference in hours to UTC.
• year(date): Returns the applicable year for the date passed as argument. Similar to the YEAR function in Excel.
• yearStart(date): Returns the first day of the year for the current year.
• yearEnd(date): Returns the last day of the year for the current year.
• weeknum(date): Similar to the WEEKNUM (System 2) function in Excel.

## Ranking functions

• argfirst(ordering, group): Returns true for one first value of the group according to the ordered values (the ordering). The group is optional. When the group is provided, the function returns true once per group. An overload argfirst(ordering, group) where condition is also provided for convenience. When the where option is used, it may result in groups where no true value is present, because the condition was false for the entire group.
• arglast(ordering, group): Same as argfirst(), but returning true for the one last value.
• cumsum(number, rank, group): Returns the cumulative sum of the numbers according to the increasing ranks. The group is optional. When the group is specified, it is used to perform a local cumulative sum for each group.
• fifo(V, T.D, T.Q): Helper for FIFO inventory analysis. Returns the unsold inventory quantity as a vector of T. The vector V contains the total stock. The table T contains the purchase orders. T.D contains the dates, and T.Q contains the purchase quantities. The function computes the unsold quantities by playing the purchase orders backward in time. See also FIFO inventory method.
• rank(number, group): Returns the ranks of the numbers with no tie. Similar to the RANK.EQ function in Excel, except that all numbers get a distinct rank (tie-breaks are arbitrary). The group is optional. When the group is provided, it is used to perform local ranks for each group.
• rankd(number): Returns the ranks of the numbers; identical numbers get identical ranks. Similar to the RANK.EQ function in Excel.

## Graph functions

• canonical(A, B): returns the canonical representative for each A value. From a practical perspective, this function is used to deal with code replacement (ex: SKU code replacement). For example, canonical(OldSku, NewSku) would return the latest SKUs available for each item, recursively performing the replacements. See also nonCanonical().
• nonCanonical(A, B): returns true whenever a canonical representative cannot be computed for the A. This happens when circular paths or branching paths get detected.
• connected(A, B, group) : considers the undirected graph described by all edges (A,B), then returns for each node A the name of the smallest node in A's connected component. Here, "smallest" means having the smallest name, in terms of string comparison. The group is optional. When the group is specified, the dataset is first partitioned against the specified groups.

## Distribution functions

See the algebra of distributions.

## Table creation functions

See creating tables for more details.

• extend.range(N): Create N lines for each line from the table passed as argument where N is expected to be an integer.
• extend.distrib(distribution, gap, multiplier, reach): Extends a distribution into a table.
• extend.billOfMaterials(...): Translates a demand history for items into the demand history for the parts.

• forex(value, Origin, Destination, date): Returns the amount expressed in the currency Origin into the equivalent amount in the currency Destination according to the historical rates at the specified date. The currencies should be encoded with their canonical three-letter codes. Lokad supports about 30 currencies leveraging the data provided by the European Central Bank. Rates are updated on a daily basis. See also isCurrency() to test the validity of your currency code.
• hash(value): Returns a pseudo-injective hash value between 0 and 2^24-1. This function is typically used randomly shuffle a dataset by hashing the content of a column, and then sorting against the hashed values.
• isCurrency(currencyCode): returns true if the text entry passed as argument is a currency code recognized by the forex() function.
• moqsolv(...): an advance numeric solver for the general MOQ problem (minimal order quantities).
• priopack(R, V, S, C, J[, B]): a simple variant of the bin packing algorithm intended to be used with purchase prioritization list. Unlike the classic bin packing algorithm, not only, we seek to optimize the bin capacities, but the ordering of the units should also preserved as much as possible. R contains the ranks of the lines to be packed. V is the volume of each line. S is the equivalence class of the suppliers, with bin packing computed per supplier. C is the max volume capacity, its value is homogeneous to V, and it is assumed to be a constant value across the equivalent class C. J is the jumping threshold, its values is homogeneous to V, it is typically expected to a small multiple of the C value. B is an optional argument interpreted as the barrier; when this value is provided, the bin-packing process is not allowed to reorder lines that below to the same equivalence class as defined by B.
• stockrwd(Id, G.Proba, G.Min, G.Max, M, S, C, A): the stock reward function. This function is used to build prioritized ordering policy out of the probabilistic forecasts produced by Lokad.