### CONCAT Function Examples Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The CONCAT function joins two or more values into a single text string. Examples demonstrate appending text, creating hyperlinks, and combining text with numerical sums. ```Klipfolio Formula CONCAT(@Units, " Units") ``` ```Klipfolio Formula CONCAT("https://en.wikipedia.org/wiki/", @Country) ``` ```Klipfolio Formula CONCAT( "Total for 2018: ", NUMBERFORMAT(SUM(@Units))," Units sold" ) ``` -------------------------------- ### JOIN Function Example Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The JOIN function concatenates a list of values using a specified 'glue' separator. If no glue is provided, a comma is used by default. ```Klipfolio Formula JOIN ( `@Product,"*" ) ``` -------------------------------- ### DATE_STARTOF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns the date at the start of a given unit (week, month, quarter, year). Supports Unix time values, relative values, and specifying the first day of the week or month of the year. ```APIDOC DATE_STARTOF ( values, unit, [relative value], [first], [timezone] ) Parameters: - values: A list of 1 or more values in Unix time format. - unit: The unit to return the values in. Options include week, month, quarter, year. - relative value: [optional] Number of units to add or subtract. - first: [optional] The starting point for the unit parameter, when the unit parameter is set to week or year. Options include Sunday (default), Monday, ..., Saturday for week; January (default), February, ..., December for year. - timezone: [optional] The time zone. Example: DATE_STARTOF(DATE(@Date,"yyyy-MM-dd HH:mm:ss"),week ,-2 ,Monday ) ``` -------------------------------- ### DATERANGE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Generates a list of dates between and including a start and end date. An optional format parameter can be used if dates are not in the default format or Unix time. ```APIDOC DATERANGE ( start, end, [format] ) Parameters: - start: A list of 1 or more values in Unix time format. - end: The last date in the range. - format: [optional] Required if start and end dates are in a format other than the default or in Unix time. Default input is M/d/yyyy, default output is MM/dd/yyyy. Example: DATERANGE("05/01/2018","05/04/2018","MM/dd/yyyy") Result: 05/01/2018, 05/02/2018, 05/03/2018, 05/04/2018 ``` -------------------------------- ### SLICE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns a subset of values from a list based on start and end positions. If parameters are omitted, the first row is removed. Negative values for start and end slice from the end of the list. ```Klipfolio SLICE ( values, [start] , [end]) ``` ```Klipfolio SLICE ( @Product ) ``` ```Klipfolio SLICE( @Product, 1, 6 ) ``` -------------------------------- ### INDEXOF Function Example Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The INDEXOF function finds the position of a specified occurrence of a search text within a given text. It is case-sensitive and returns null if the text is not found. ```Klipfolio Formula INDEXOF(@Sales Rep, "Car",2) ``` -------------------------------- ### Date and Time Functions Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Functions for converting and manipulating dates and times. DATEVALUE converts Unix time to a readable format, NOW gets the current Unix time, TIME converts durations to seconds, TODAY gets today's Unix time, and YESTERDAY gets yesterday's Unix time. ```APIDOC DATEVALUE ( dates, [format], [timezone] ) dates: A list of 1 or more values in Unix time format. format: [optional] The format you want to convert your dates to. timezone: [optional] The time zone. Example: DATEVALUE(1542690000, "yyyy/MM/dd") Result: 2018/11/20 NOW ( [timezone] ) timezone: [optional] The time zone. Example: DATEVALUE( NOW(), "dd-MM-yyyy") Result: 20-11-2018 Example: DATEVALUE( NOW(), "h:mm:ss" ) Result: 9:39:57 TIME ( values, format ) values: A list of 1 or more date/time durations. format: The format of the date/time duration. Supported formats include: hh:mm:ss, hh:mm, dd:hh:mm:ss, dd:hh:mm, dd:hh, d, h, m, s, ss, dd, mm, hh, ss, mmss, ddhhmmss. Example: TIME("1:47:67:800", "d:h:m:s") Result: 260,420 seconds Example: TIME(ARRAY("01:08","02:16"), "dd:hh") Result: 115200, 230400 seconds. TODAY ( [timezone] ) timezone: [optional] The time zone. Example: DATE_STARTOF(TODAY(), week) Result: 1542517200 (Unix time for November 18, 2018) YESTERDAY ( [timezone] ) timezone: [optional] The time zone. Example: DATERANGE(DATE("11/10/2018","MM/dd/yyyy"),YESTERDAY()) Result: Ten dates in Unix time format (yesterday was November 19, 2018) ``` -------------------------------- ### CONTAINS Function Examples Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The CONTAINS function checks if a 'haystack' value contains a 'needle' value (case-sensitive). Examples show boolean results and usage within a SELECT statement. ```Klipfolio Formula CONTAINS(@Customer Type, "Customer") ``` ```Klipfolio Formula SELECT(@Price Base, CONTAINS(@Country, "Mexico")) ``` -------------------------------- ### SUBSTRING Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Extracts a portion (substring) of a text string. It requires the text, a starting position, and an optional ending position. ```Klipfolio SUBSTRING ( text , from , [to] ) ``` -------------------------------- ### COUNTRY_CLEAN Function Examples Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The COUNTRY_CLEAN function standardizes country names to either full names or ISO 3166-1 alpha codes. It handles variations and returns 'INVALID COUNTRY' for unrecognized values. ```Klipfolio Formula COUNTRY_CLEAN(ARRAY("Canada,MX,Canada,CAN,CA,US,United States,USA")) ``` ```Klipfolio Formula COUNTRY_CLEAN(ARRAY("Canada,MX,Canada,CAN,CA,US,United States,USA"),ISO Alpha-2) ``` ```Klipfolio Formula COUNTRY_CLEAN(ARRAY("Canada,MX,Canada,CAN,CA,US,United States,USA"),ISO Alpha-3) ``` -------------------------------- ### DATE_IN Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Checks if given dates (in Unix time) fall within a specified time period based on a unit, optional relative value, start of unit, and timezone. ```APIDOC DATE_IN ( values, unit, [relative value], [first], [timezone] ) Parameters: - values: A list of 1 or more values in Unix time format. - unit: The unit to return the values in. Options include week, month, quarter, year. - relative value: [optional] Number of units to add or subtract. - first: [optional] The starting point for the unit parameter, when the unit parameter is set to week or year. Options include Sunday (default), Monday, ..., Saturday for week; January (default), February, ..., December for year. - timezone: [optional] The time zone. Example: DATE_IN(DATE(@Date,"yyyy-MM-dd HH:mm:ss"), year, -1) ``` -------------------------------- ### DATE_ENDOF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns the date at the end of a specified unit (week, month, quarter, year). Can optionally add or subtract a relative value and specify the start of the week or year. Results are in Unix time format. ```APIDOC DATE_ENDOF ( values, unit, [relative value], [first], [timezone] ) Parameters: values: A list of 1 or more values in Unix time format. unit: The unit to return the values in. Options include week, month, quarter, year. relative value: [optional] Number of units to add or subtract. first: [optional] The starting point for the unit parameter (e.g., Sunday for week, January for year). Requires a relative value if provided. timezone: [optional] The time zone. Example: // Returns the end date of each week, two weeks prior to the date in the 'Date' column, with Monday as the start of the week. DATE_ENDOF(DATE(@Date,"yyyy-MM-dd HH:mm:ss"),week ,-2 ,Monday ) // Assumes @Date is a column containing dates. ``` -------------------------------- ### BETWEEN Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The BETWEEN function checks if a numeric value falls within a specified inclusive range (start and end). It is useful for range-based filtering and analysis, including date ranges when dates are converted to Unix time. ```Klipfolio BETWEEN ( values, start, end ) ``` -------------------------------- ### FIRST Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns the first values in a list of data, with the number of values specified by the count parameter. It takes a list of items and an optional count as input. ```Klipfolio FIRST(@Company Name) ``` ```Klipfolio FIRST(@Company Name, 5) ``` -------------------------------- ### MAPFLAT/MAP Functions Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Repeats a formula or data source reference for each value in a specified list. MAPFLAT is recommended over MAP as it supports returning multiple items. ```Klipfolio MAPFLAT(values, variable name, formula) ``` -------------------------------- ### Mathematical and Statistical Functions Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Provides documentation for mathematical and statistical functions used in Klipfolio. These functions perform operations such as rounding, finding maximum/minimum values, calculating median and mode, exponentiation, and summation. ```Klipfolio FLOOR(data, significance) - Rounds numbers down to the nearest multiple of significance. - Non-numeric values return as 0. - Parameters: - data: A list of 1 or more values to round down. - significance: [optional] The multiple to round down to. - Example: FLOOR(-2.5) Returns: -3 ``` ```Klipfolio MAX(value) - Returns the maximum value from a list of numeric values. - Parameters: - value: A list of 1 or more numeric values. - Example: MAX(@Days of Activity) Returns: 30 ``` ```Klipfolio MEDIAN(value) - Returns the middle value from a list of numeric values. - Parameters: - value: A list of 1 or more numeric values. - Example: MEDIAN(@Days of Activity) Returns: 13 ``` ```Klipfolio MIN(value) - Returns the minimum value from a list of numeric values. - Parameters: - value: A list of 1 or more numeric values. - Example: MIN(@Days of Activity) Returns: 0 ``` ```Klipfolio MOD(values, modulus) - Returns the remainder of each value after dividing by the modulus. - Parameters: - values: A list of 1 or more numeric values. - modulus: Divisor - Example: MOD(@Days of Activity, 5) Returns: The remainder of active days after each value is divided by 5. ``` ```Klipfolio MODE(value) - Returns the most frequently occurring lowest value found in a list of items. - Parameters: - value: A list of 1 or more numeric values. - Example: MODE(@Days of Activity) Returns: 17 ``` ```Klipfolio POWER(bases, exponent) - Raises each base to the specified exponent. - Parameters: - bases: A list of 1 or more numeric items. - exponent: A single numeric value. - Example: POWER(20,3) Returns: 8000 ``` ```Klipfolio ROUND(data, digits) - Rounds a number to a specified number of digits or to a whole number. - Parameters: - data: The number to round. - digits: The number of digits to round the number to. - Example: ROUND(65.29, 1) Returns: 65.3 ``` ```Klipfolio SUM(data) - Returns the sum of all non-blank values in a range of data. - Parameters: - data: A list of 1 or more numeric items. - Example: SUM(@Revenue) Returns: 26012.90 ``` ```Klipfolio SUMIF(condition, sum range) - Sums values in a range that meet a certain condition. - Parameters: - condition: A list of true or false values. - sum range: A list of 1 or more numeric items. Non-numeric values return as 0. - Example: SUMIF(@Product="Bread", @Revenue) Returns: The sum of all Revenue values when the Product column contains Bread: 6974.13 ``` -------------------------------- ### LENGTH Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts and returns the total number of characters in a given text string. ```APIDOC LENGTH ( text ) Parameters: text: A list of 1 or more values. Example: LENGTH( @Company Name ) Returns the character count for each entry in the 'Company Name' column. ``` -------------------------------- ### LEFT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns a specified number of characters from the beginning (left side) of a text string. If the number of characters is not specified, it returns the first character. ```APIDOC LEFT ( text, [number] ) Parameters: text: A list of 1 or more values. number: [optional] The number of characters to return. Examples: LEFT(@Product) Returns the first letter of each value in the 'Product' column. LEFT(@Product, 2) Returns the first 2 letters of each value in the 'Product' column. ``` -------------------------------- ### SWITCH Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Compares a data value against multiple cases and returns a corresponding value if a match is found. A default value can be specified for cases where no match occurs. ```Klipfolio SWITCH(@Product,"Bread","BREAD","Milk",TEXT_REVERSE("Milk"),"Eggs","3","Cheese","2") ``` -------------------------------- ### COUNTALL Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts all items in a list, including numbers, text, and blank values. It takes a single parameter, 'data', which is a list of items. ```APIDOC COUNTALL ( data ) Parameters: data: A list of 1 or more items. Example: COUNTALL( @Shipping location ) Returns: The total count of all items (including blanks) in the 'data' list. ``` -------------------------------- ### SET Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Assigns values to variables. It is useful for dynamic datasources with multiple variables. ```Klipfolio SET ( variable names, values, expression ) ``` -------------------------------- ### LOWER Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Converts all characters in a given text string to lowercase. ```APIDOC LOWER ( data ) Parameters: data: A list of 1 or more values. Example: LOWER( @Company Name ) Converts all company names in the 'Company Name' column to lowercase. ``` -------------------------------- ### Text Manipulation Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Provides documentation for the CAPITALIZE function, which modifies text by capitalizing the first letter of each word. ```Klipfolio CAPITALIZE(data) - Changes the first letter in each word to uppercase. - Parameters: - data: The text value or values. - Example: CAPITALIZE("canada") Returns: Canada ``` -------------------------------- ### OR Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Evaluates a list of conditions and returns true if at least one condition is true. It returns false only if all provided conditions are false. ```Klipfolio OR(@Customer Type="Distributor", @Country="Mexico") ``` -------------------------------- ### NUMBERFORMAT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Formats numerical data as text with a specified number of decimal places and an optional thousands separator. ```APIDOC NUMBERFORMAT ( data, [precision], [separator] ) Parameters: data: A list of 1 or more items. precision: [optional] The number of decimal places to return. separator: [optional] The thousands separator character. Example: NUMBERFORMAT( @Price Retail, 1, "," ) Formats the 'Price Retail' column to one decimal place with a comma as the thousands separator. Note: If 'data' contains text or is blank, it returns 0. ``` -------------------------------- ### BLANK Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns one blank value or a specified number of blank values. Can be used to replace blank values with a non-blank placeholder. ```Klipfolio BLANK ( [count] ) Parameters: count: [optional] The number of blank items to be returned. Negative numbers are treated as positives. The maximum for count is 1000000. Example: BLANK(5) REPLACE(@Qty, BLANK(), "No value") ``` -------------------------------- ### SELECT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Selects values from a list based on a specified condition. The data and condition lists must have the same number of items. ```Klipfolio SELECT ( data, condition ) ``` ```Klipfolio SELECT(@Product, @Customer Type="Distributor") ``` -------------------------------- ### DATE_CONVERT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Converts date/time values from one format to another. Requires the values to convert, the input format, and the desired output format. ```APIDOC DATE_CONVERT ( values , format in , format out ) Parameters: values: A list of 1 or more date/time values. format in: The current date format of the date/time values. format out: The date/time format you want to convert the dates to. Example: DATE_CONVERT("9/11/2018", "d/M/yyyy", "MMM dd, yyyy") // Returns Nov 09, 2018 ``` -------------------------------- ### UPPER Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Converts all characters in a given text string or data set to uppercase. ```Klipfolio UPPER ( data ) ``` -------------------------------- ### LOOKUP Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Correlates data between two data sources by searching for matches and returning corresponding values. It's useful for aligning data across sub-components. ```Klipfolio LOOKUP(input, keys, results) ``` -------------------------------- ### COUNT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts all non-blank items (numeric and text) in a given list. It takes a single parameter, 'data', which is a list of items. ```APIDOC COUNT ( data ) Parameters: data: A list of 1 or more items. Example: COUNT( @Shipping location ) Returns: The count of non-blank items in the 'data' list. ``` -------------------------------- ### DATE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Converts dates and times into Unix time format, which is used internally by Klipfolio for date calculations. Requires specifying the input date format and optionally accepts a timezone. ```Klipfolio DATE ( dates , format , [timezone] ) ``` -------------------------------- ### REPEAT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Replicates one or more values a specified number of times, returning a list of the repeated values. Useful for creating target lines or repeating static data. ```Klipfolio REPEAT (values, times) ``` -------------------------------- ### IF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Tests a condition and returns a value based on whether the condition is true or false. It can be nested, but nesting more than two IFs is not recommended; use SWITCH or SELECT for more complex conditions. ```Klipfolio IF(@Country="Canada",@Company Name, BLANK()) ``` ```Klipfolio IF(AND(DATE_IN(DATE(@Date, "yyyy-MM-dd HH:mm:ss"),year,-1),@Customer Type="Direct Customer"),@Revenue, 0) ``` -------------------------------- ### COUNTBLANK Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts all blank values in a given list. It takes a single parameter, 'data', which is a list of items. ```APIDOC COUNTBLANK ( data ) Parameters: data: A list of 1 or more items. Example: COUNTBLANK( @Shipping location ) Returns: The count of blank items in the 'data' list. ``` -------------------------------- ### DATE_SET Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Sets a specified date unit to a given value. Accepts date values in Unix time format, a unit, the unit's value, and an optional timezone. ```APIDOC DATE_SET ( values, unit, unit value, [timezone] ) Parameters: - values: A list of 1 or more values in Unix time format. - unit: Options include second, minute, hour, day, month, year. - unit value: The value to be assigned to the unit parameter. - timezone: [optional] The time zone. Example: DATE_SET( 1542747573, month, 7 ) ``` -------------------------------- ### LAST Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns the last values in a list of data, with the number of values specified by the count parameter. It takes a list of values and an optional count as input. ```Klipfolio LAST(@Company Name) ``` ```Klipfolio LAST(@Company Name, 5) ``` -------------------------------- ### AND Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The AND function evaluates multiple conditions and returns true if all conditions are met, otherwise false. It is commonly used in conjunction with other functions like SELECT to filter data based on complex criteria. ```Klipfolio AND ( condition ) ``` -------------------------------- ### DATE_ADD Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Adds or subtracts time to/from given date/time values. Results are returned in Unix time format. Accepts a list of Unix time values, a unit (second, minute, hour, day, week, month, quarter, year), an amount, and an optional timezone. ```APIDOC DATE_ADD ( values , unit , amount, [timezone] ) Parameters: values: A list of 1 or more values in Unix time format. unit: The unit to add to the date. Options include: second, minute, hour, day, week, month, quarter, year. amount: The number of units to add. Use a negative number to subtract units. timezone: [optional] The time zone. Example: // Adds 6 days to today's date. DATE_ADD( TODAY() , day , 6 ) // Returns 1543035600 (Unix time for November 24, 2018) // Subtracts 6 days from today's date. DATE_ADD( TODAY() , day , -6 ) // Returns 1541998800 (Unix time for November 12, 2018) ``` -------------------------------- ### SUBSTITUTE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Replaces specified characters within a text string. It can replace all occurrences or a specific occurrence based on the 'occurrence' parameter. ```Klipfolio SUBSTITUTE ( text, old text, new text, [occurence] ) ``` -------------------------------- ### ARRAY Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Joins together single values and returns them as a single list in the order provided. Useful for combining data from multiple sources or adding values to a list. ```Klipfolio ARRAY ( data ) Parameters: data: The values to join together including strings or columns of data from different data sources. Example: ARRAY ( @Customer Contact, @Sales Rep ) ARRAY ("Exception", @Customer Type) ``` -------------------------------- ### AVERAGE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the average of numeric items in a list, ignoring non-numeric and blank values. It takes a single parameter, 'data', which is a list of values. ```APIDOC AVERAGE ( data ) Parameters: data: A list of 1 or more values to find the average of. Example: AVERAGE(@Days of Activity) Returns: The average of the provided data. ``` -------------------------------- ### REPLACE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Replaces items in a list that match a specified value with another value. It can handle single replacements or nested replacements. ```Klipfolio REPLACE( values, matching, [with value] ) ``` ```Klipfolio REPLACE(@Country,"US","USA") ``` ```Klipfolio REPLACE(REPLACE(@Country, "US","USA"),"Canada","CA") ``` -------------------------------- ### URLENCODE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Encodes data into a format that can be safely used in URLs. This function is essential for preparing data to be transmitted via URLs. ```Klipfolio URLENCODE ( data ) ``` -------------------------------- ### SUBSTITUTE_REGEX Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Substitutes text within a string based on a regular expression pattern. It allows for pattern-based replacements and can target specific occurrences. ```Klipfolio SUBSTITUTE_REGEX ( text , old text , new text , [occurence]) ``` -------------------------------- ### TRIM Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The TRIM function removes specified values or all blank values from a list. It can be used to clean data by removing unwanted characters or empty entries. ```Klipfolio TRIM ( values, [pattern] ) ``` -------------------------------- ### RIGHT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns a specified number of characters from the end (right side) of a text string. If the number of characters is not specified, it returns the last character. ```APIDOC RIGHT ( text, [number] ) Parameters: text: A list of 1 or more values. number: [optional] The number of characters to return. Examples: RIGHT(@Product) Returns the last letter of each value in the 'Product' column. RIGHT(@Product, 2) Returns the last 2 letters of each value in the 'Product' column. ``` -------------------------------- ### COUNTIF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts the number of items in a list that satisfy a given condition. It takes a single parameter, 'condition', which is a list of true/false values. ```APIDOC COUNTIF ( condition ) Parameters: condition: A list of true and false values. Example: COUNTIF( @Shipping location="warehouse" ) Returns: The count of 'true' values in the 'condition' list. ``` -------------------------------- ### IN Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Checks if one or more values are present within a specified set of values. Returns true if a value is found in the set, and false otherwise. ```Klipfolio IN (@Sales Rep, "Ahmed Arthurs") ``` -------------------------------- ### DATE_CLOSEST Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Finds the closest day of the week (in Unix time format) before or after a given date. Accepts a list of Unix time values, a day of the week (Sunday to Saturday), an optional direction (forward or backward), and an optional timezone. ```APIDOC DATE_CLOSEST( values , dow , [direction], [timezone]) Parameters: values: A list of 1 or more values in Unix time format. dow: Day of the week. Options include: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. direction: [optional] The direction. Options include forward or backward. timezone: [optional] The time zone. Example: // Returns the Unix time format of the closest Friday before the current date (November 19, 2018). DATE_CLOSEST( "1542641280", Friday, backward ) // Returns 1542382080 (Unix time for November 16, 2018) // Returns the date closest to the last Monday from 11/18/18, formatted as d-MMM-yyyy. DATEVALUE( DATE_CLOSEST( DATE( "11/18/18" , "M/d/yy" ) , Monday , backward ), "d-MMM-yyyy" ) // Returns 12-Nov-2018 ``` -------------------------------- ### SORT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Sorts values in a list according to specified order (ascending, ascending numeric, descending, descending numeric). It can also return corresponding values from another list. ```Klipfolio SORT ( values, type, [return values]) ``` ```Klipfolio SORT ( @Qty, descending numeric ) ``` -------------------------------- ### URLDECODE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Decodes URL-encoded data back into plain text. It is the inverse of the URLENCODE function and is useful for processing data received from URLs. ```Klipfolio URLDECODE ( data ) ``` -------------------------------- ### Statistical Functions Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Functions for statistical calculations including error function, moving averages, normal distribution, ranking, slope, standardization, standard deviation, and variance. ```APIDOC ERF Computes the standard error function integrated between the lower limit and upper limit, or between the lower limit and infinity if no upper limit is provided. ERFC Computes the complement of the standard error function integrated between the lower limit and infinity. MA_CUMULATIVE Returns the cumulative moving average for each of the given values. MA_EXPONENTIAL Returns the exponential moving average for each of the given values using the given period "n". MA_SIMPLE Returns the simple moving average for the previous "n" data points for each of the given values. NORMSDIST Takes a single value or a list of values and returns the normal standard distribution of each value provided. RANK ( data, [order] ) data: A list of 1 or more values. order: [optional] The order to rank the values in. Options include ascending or descending. Example: RANK(GROUP(@Days of Activity), ascending) Result: 2, 11, 12, 13, 14 (first five results) SLOPE Calculates the slope of the linear regression line represented by columns of known x and y values. STANDARDIZE Standardizes each value in a column of values using a supplied mean and a supplied standard deviation. STDEV Computes the standard deviation for a random sampled population using the (n-1) method. STDEVP Computes the standard deviation for a complete population using the (n) method. VARIANCE Computes the variance for a random sample population of values (n-1) method. VARIANCEP Computes the variance for a complete population of values (n) method. ``` -------------------------------- ### GROUP Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Groups data into unique instances and hides duplicate values. Results are returned in alphabetical order. It takes a list of values as input. ```Klipfolio GROUP (@Country) ``` -------------------------------- ### DATE_UNITVALUE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Extracts the value of a specified unit (e.g., second, month, week of month) from given date/time values in Unix time format. Supports specifying the first day of the week/year and timezone. ```APIDOC DATE_UNITVALUE ( values, unit, [first], [timezone] ) Parameters: - values: A list of 1 or more values in Unix time format. - unit: The unit to return the values in. Options include second, minute, hour, day, day of week, day of year, week, week of month, month, quarter, year. - first: [optional] The starting point for the unit parameter, when the unit parameter is set to week or year. Options include Sunday (default), Monday, ..., Saturday for week; January (default), February, ..., December for year. - timezone: [optional] The time zone. Example: DATE_UNITVALUE(DATE(@Date,"yyyy-MM-dd HH:mm:ss"), week) ``` -------------------------------- ### TRIM_WHITESPACE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Removes leading and trailing whitespace characters from a text string. ```Klipfolio TRIM_WHITESPACE ( text ) ``` -------------------------------- ### AVERAGEIF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the average of numeric items based on a condition. It requires a 'condition' (list of true/false values) and an 'average range' (list of numeric items). Non-numeric values in the average range are treated as 0. ```APIDOC AVERAGEIF ( condition, average range ) Parameters: condition: A list of 1 or more true/false values. average range: A list of 1 or more numeric items. Non-numeric values return as 0. Example: AVERAGEIF(@Product="Milk",@Revenue) Returns: The average of items in 'average range' where the corresponding 'condition' is true. ``` -------------------------------- ### NOT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Reverses the logical value of a given condition. If the condition evaluates to true, NOT returns false, and if it evaluates to false, NOT returns true. ```Klipfolio NOT(@Sales Rep="Ahmed Arthurs") ``` -------------------------------- ### REVERSE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Reverses the order of a list of values. It can be applied to the entire list or a subset. ```Klipfolio REVERSE( values ) ``` ```Klipfolio REVERSE(@Date) ``` ```Klipfolio REVERSE(SLICE(@Date, -12)) ``` -------------------------------- ### CUMULATIVE_DIFFERENCE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the difference between consecutive values in a list. It takes 'data' (a list of numeric items) and 'first value' (specifying how to handle the first value) as parameters. ```APIDOC CUMULATIVE_DIFFERENCE ( data, first value ) Parameters: data: A list of 1 or more numeric items. first value: Specifies how to treat the first value ('Ignore first value', 'Use first value', 'Use zero'). Example: CUMULATIVE_DIFFERENCE( @Qty, Ignore first value ) Returns: A list of cumulative differences between consecutive values. ``` -------------------------------- ### CUMULATIVE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the cumulative sum of numeric data in a list. It takes a single parameter, 'data', which is a list of numeric items. ```APIDOC CUMULATIVE ( data ) Parameters: data: A list of 1 or more numeric items. Example: CUMULATIVE( @Qty ) Returns: A list of cumulative sums for the provided 'data'. ``` -------------------------------- ### GROUPBY Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Returns values based on a specified aggregation method, aligning unique values with a parallel column. It accepts values, a measure, and an optional aggregation method. ```Klipfolio GROUPBY(@Country, @Days of Activity) ``` ```Klipfolio GROUPBY(@Sales Rep, @Days of Activity, Join) ``` -------------------------------- ### PADVALUES Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Adds padding or additional values to the end of a data list to ensure data alignment between lists of different sizes. Padding can be with blanks or a specified value. ```Klipfolio PADVALUES (values, times, [with value]) ``` -------------------------------- ### COUNTNUMERIC Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts all numeric values within a list of data. It takes a single parameter, 'data', which is a list of items. ```APIDOC COUNTNUMERIC ( data ) Parameters: data: A list of 1 or more items. Example: COUNTNUMERIC( @Units ) Returns: The count of numeric items in the 'data' list. ``` -------------------------------- ### TEXT_REVERSE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Reverses the order of characters in a given text string or data set. ```Klipfolio TEXT_REVERSE ( data ) ``` -------------------------------- ### COUNT_DAYS Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the number of whole days between two dates, with options to exclude specific days of the week or holidays. Dates must be in Unix time format. Supports optional timezone specification. ```Klipfolio COUNT_DAYS (start, end, [exclude DOW], [holidays], [timezone]) ``` -------------------------------- ### TRUNCATE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Truncates a text string to a specified number of characters, with options to insert a style character at a specific position. ```Klipfolio TRUNCATE ( text, number, [position], [style] ) ``` -------------------------------- ### LASTINDEXOF Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Searches for the last occurrence of a substring within a text and returns its position. It is case-sensitive and returns null if the substring is not found. Supports specifying an occurrence to search for. ```APIDOC LASTINDEXOF ( text, search text, [occurrence] ) Parameters: text: A list of 1 or more values. search text: The text string to search for. occurrence: [optional] The occurrence to search for. Example: LASTINDEXOF(@Sales Rep, "Car") Returns the position of the last occurrence of 'Car' in the 'Sales Rep' column. ``` -------------------------------- ### ABS Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Calculates the absolute (positive) value of numeric data. Non-numeric or blank values are returned as 0. ```Klipfolio ABS (-4) ``` -------------------------------- ### COUNTDISTINCT Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Counts the number of unique items in each group, returning results in alphabetical order. Useful for aggregating data according to specified groups. ```Klipfolio COUNTDISTINCT ( values ) Parameters: values: A list of 1 or more values. Related functions: GROUP, GROUPBY Example: COUNTDISTINCT (@Country) ``` -------------------------------- ### CEILING Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md Rounds numbers up to the nearest multiple of significance. Non-numeric values are treated as 0. It accepts 'data' and an optional 'significance' parameter. ```APIDOC CEILING ( data, significance ) Parameters: data: A list of 1 or more values to round up. significance: [optional] The multiple to round up to. Example: CEILING( -2.5 ) Returns: The value of 'data' rounded up to the nearest multiple of 'significance'. ``` -------------------------------- ### SPLICE Function Source: https://github.com/gneius/klipfolio-functions/blob/main/README.md The SPLICE function returns specified values from a list, optionally removing a number of values from a given index and inserting a new value at that position. It's useful for modifying array-like data structures within Klipfolio. ```Klipfolio SPLICE ( values, index, count, [insert] ) ```