Miscellaneous Functions
Spectre includes several miscellaneous functions.
For example:
Suppose a cPlan includes the following expression:
calc "Profit" `calc("Revenue") - calc("Cost")` {
custom-property "Currency" "USD"
}
Then, `calc_custom_property("Profit", "Currency")` returns "USD".
For example:
Suppose a cPlan includes the following expression:
calc "max_units" `max(value("Units"))` label="Max Units" { property "Description" "The biggest units number" }
Then, `calc_system_property("max_units", "Description")` returns "The biggest units number".
For example:
Suppose a cPlan includes the following expression:
calc "PFT" `calc("Revenue") - calc("Cost")` label="Total Profit"
Then, `calc_label("PFT")` returns "Total Profit".
For example:
`catch(parse_integer(calc("Volume")),0)` where the column Volume contains some integer and some string values, the strings are treated as zero.
For example:
`coalesce(null, 1, 2)` returns 1
calc "INVOICE_KEY Count" `coalesce(dimcount("INVOICE_KEY"), 0)` returns the number of invoice keys or zero
add "Phone" `coalesce(value("Home Phone"), value("Work Phone"), value("Cell Phone"))` returns the first non-null phone number
For example:
Suppose a Build script includes the following expression:
add "Profit" `value("Revenue") - value("Cost")` {
custom-property "Currency" "USD"
}
Then, `column_custom_property("Profit", "Currency")` returns "USD".
For example:
Suppose a Build script includes the following expression:
add "Profit" `value("Revenue") - value("Cost")` format="$#,0.00"
Then, `column_system_property("Profit", "Format")` returns "$#,0.00".
For example:
`current_file()` might return: project://My Project/testing/current-file.dive
For example:
`current_user()` might return "jane_doe"
calc "Logged In User" `current_user()` creates a calculated column in a cPlan that contains the DiveLine userid of the current user.
For example:
`if(is_null(value("Cost")), error("Uh-oh, cost is null!"), value("Cost"))` when true, results in a blank value and the "Uh-oh" error in the log
calc "error" `if(calc("Mood") != "Dopey", error("not dopey"), "OK")` if true, creates a message in the log prefaced with ERROR:, followed by the error string ("not dopey" in this example); result of the error calc is UNKNOWN.
For example:
date(rtrim(file_contents("date.txt"))) reads the contents of date.txt, strips off any trailing white space (such as a newline character), and converts the result into a date by using the default date format "YYYY/MM/DD". This is a good way to specify a time-series anchor for data extract processes that are not necessarily run daily.
calc("Cost") * parse_float(rtrim(file_contents("multiplier.txt"))) reads the contents of multiplier.txt, strips off any trailing white space, converts the result into a floating point number, and multiples that number by the result of the "Cost" calc.
For example:
`filter(calc("Revenue"), value("State") = "Ohio")` runs the "Revenue" calc only on detail rows where the "State" column is "Ohio". This is the preferred way to do a filtered calculation.
`top(filter(calc("Revenue"), value("State") = "Ohio"))` returns the "revenue" calc run on all rows in the cBase where the "State" column is "Ohio". This produces the same value on every window row, because the call to top replaces the current working set with the entire cBase.
`parent(filter(calc("Revenue"), value("State") = "Ohio"))` returns the "Revenue" calc run on detail records in the window's working set where the "State" column is "Ohio". This produces the same value on every window row, because the call to 'parent' replaces the current working set with the entire window's working set.
`filter(sum(value("Revenue")), value("State") = "Ohio")` returns the sum of "Revenue" where "State" is "Ohio".
`filter(calc("Rev"), value("State") = "Ohio") * 100 / top(calc("Rev"))` returns the percentage of the overall "Rev" value contributed by the part of the current working set where the "State" column is "Ohio".
`filter(filter(expression, pred1), pred2)` is equivalent to `filter(expression, pred1 and pred2)`.
`filter( dimcount("OrderNbr"), value("DeliveryDate") = today() )` does a filtered dimcount using a date function. This expression can be used in a cPlan and the calc accessed by a Marker. The expression can also be used in ProDiver's Edit Column dialog.
For example:
`group_match("Manager")` returns true when the current user is in the "Manager" group; returns false when the current user is not in the "Manager" group.
For example:
Assuming cbase-input "data-A.cbase" name="A" and cbase-input "data-B.cbase" name="B",
then `input("B", sum(value("Units")))` returns the sum of "Units" in the data-B.cbase.
`input("Sales", calc("Revenue"))` returns the sum of the value for the Revenue column in the source named "Sales".
For example:
`kilometers(42.3731998,-71.1137217,42.5054961,-71.194671)` returns 16.1409561.
For example:
miles(Maximum[sum_long], Maximum[sum _lat], Info[longitude], Info[latitude]) uses the maximum of the summary values in the cPlan, along with latitude-longitude values from another cBase in the cPlan to calculate the miles.
For example:
`notnull(0)` returns true.
`notnull("")` returns false.
filter `notnull(value("city"))` filters out null city values; this is equivalent to filter `value("city") != ""`
calc "test" `notnul(value("Units"))` adds a calc column in a cPlan with true(1) if Units is not null, or false(0) if Units is null
For example:
`on_previous_row(value("A"))` returns the value of A on the input row before the current row
`on_previous_row(value("A"), 0)` returns the value of A on the input row before the current row
`on_previous_row(on_previous_row(value("A"))` returns the value of A two rows before the current row
add "Last ED Visit for Account" `if(on_previous_row(value("Account ID"))=value("Account ID"),"","Y")`returns, when run against sorted data, the last ED visit for each account
add "break" `value("Dim1") != on_previous_row(value("Dim1"))` could simulate the Integrator "break" functionality by allowing you to add a column when a break in multi-sorted data occurs, setting the data up for a filter or calc
For example:
`parent(calc("Revenue"))` returns the same value as an unfiltered totals row would for Revenue.
`parent(filter(calc("Revenue"), value("State") = "Ohio"))` returns the "Revenue" calc run on detail records in the window's working set where the "State" column is "Ohio". This produces the same value on every window row, because the call to 'parent' tells it to replace the current working set and with the entire window's working set.
`parent(calc("Rev")) * 100 / top(calc("Rev"))` returns the percentage of the overall "Rev" value contributed by the current window's total "Rev".
`calc("Rev") * 100 / parent(calc("Rev"))` returns the percentage of the window's total "Rev" value contributed by the current working set.
`filter(calc("Rev"), value("State") = "Ohio") * 100 / parent(calc("Rev"))` returns the percentage of the window's total "Rev" value contributed by the part of the current working set where the "State" column is "Ohio".
The Spectre expression: ‘parent(calc(“Units”))‘ computes the same number as ProDiver’s: ‘parent(units)’
For example:
`top(calc("Rev"))` runs the "Rev" calc over all cBase rows. This is what you would get in the totals row for "Rev" on any top-level dive.
`top(filter(calc("Rev"), value("State") = "Ohio"))`returns the "Rev" calc run on detail records in the window's working set where the "State" column is "Ohio". This produces the same value on every window row, because the call to top replaces the current working set with the entire cBase.
`top(max(value("Profit")))` returns the largest value of "Profit" in the entire cBase.
`top(max(value("Ship Date")))` returns the last ship date in the cBase.
`top(sum(value("Rev")))` returns the sum of "Rev" over the entire cBase.
`calc("Rev") * 100 / top(calc("Rev"))` returns the percentage of the overall "Rev" value contributed by the current working set.
For example:
`value("State")` returns the contents of the state column
See also: