Skip to content

Creating a Cube via a Process

All of the following functions are documented in full in the Process Documentation section of the portal.

Cube Management Functions

These functions can be used to manage cubes, not the information stored within them.

js
cube.create(cubeName, dim1 - dimN);
cube.exists(cubeName);
cube.remove(cubeName);
cube.create(cubeName, dim1 - dimN);
cube.exists(cubeName);
cube.remove(cubeName);

Cube Data Functions

These functions are used to store, retrieve or affect the data values in a cube.

cube.wipe is commonly used at the beginning of a process to clear out the portion of the cube which is about to be loaded.

js
cube.get(cubeName, elm1 - elmN);
cube.set(value, cubeName, elm1 - elmN);
cube.increment(value, cubeName, elm1 - elmN);
cube.wipe(cubeName, elm1 - elmN);
cube.get(cubeName, elm1 - elmN);
cube.set(value, cubeName, elm1 - elmN);
cube.increment(value, cubeName, elm1 - elmN);
cube.wipe(cubeName, elm1 - elmN);

Optimisation Functions

These functions can be used to improve the performance of loading data into a data cube. These are not used in most models.

js
/*
turn off/on the write-after log. 
This log is typically on by default and is used to recover information 
    should the environment crash for any reason.
*/
cube.log(cubeName, bShouldLog);
/*
turn off/on the formulas of a cube. 
This can be used to speed up loading into a cube 
    which feeds a multitude of calculated cells.
*/
cube.formulaEvaluation(cubeName, bShouldEvaluate);
/*
turn off/on the write-after log. 
This log is typically on by default and is used to recover information 
    should the environment crash for any reason.
*/
cube.log(cubeName, bShouldLog);
/*
turn off/on the formulas of a cube. 
This can be used to speed up loading into a cube 
    which feeds a multitude of calculated cells.
*/
cube.formulaEvaluation(cubeName, bShouldEvaluate);

Cube Slice Functions

When a process needs to iterate over a large slice of information from a cube the cube.slice function can be used to generate a iterator object which can progress through the cells of a cube slice.

js
//create a slice of the Sales cube containing the 'Units Sold' in '2017' and '2018'. 
//This slice excludes any plan data by restricting on 'Actual'
var slice = cube.slice("Sales","2017|2018","","Actual","","","Units sold"); 
while( !slice.EOF() ) {
    var elms = slice.Next();
    /*
    `elms` will be returned as an array 
    i.e. 
    [
        "2017 - Jan","Product A","Actual",
        "Department A","Retail Sales",
        "Units Sold", 5293
    ]
    The last value in the array is the value stored at the 
    intersection described by the proceeding array items.
    */

}
//create a slice of the Sales cube containing the 'Units Sold' in '2017' and '2018'. 
//This slice excludes any plan data by restricting on 'Actual'
var slice = cube.slice("Sales","2017|2018","","Actual","","","Units sold"); 
while( !slice.EOF() ) {
    var elms = slice.Next();
    /*
    `elms` will be returned as an array 
    i.e. 
    [
        "2017 - Jan","Product A","Actual",
        "Department A","Retail Sales",
        "Units Sold", 5293
    ]
    The last value in the array is the value stored at the 
    intersection described by the proceeding array items.
    */

}

Standard Template for loading data into a Cube

For information on how scripted processes are structured and how each of the standard functions is used, refer to the Scripted Processes documentation.

js
/**
 * Author: example name
 * Date Created: 2022-12-15
 * Date Modified: 2022-12-15
 * Date Deprecated: #N/A
 *
 * Parent Process: #N/A
 * Primary Function: Populate the Sales cube
 * Target: Sales
 * Datasource: CSV file from business users
 * Datasource Fields: 
 *      dept - department code
 *      product - product code
 *      channel - sales channel code
 *      month - the month in YYYY - MMM
 *      units - units sold
 *      revenue - invoiced revenue
 * 
 * Wipes and then reloads the Sales cube from a 
 *  CSV file containing all history
 */
var cubeName = "Sales";

function pre() { 
    //do nothing 
}
function begin() {

    /*
    wipe the Actuals data from the cube against the 
        Units and Revenue Measures.
    */
    cube.wipe(cubeName, ["","Actual","","","","Units|Revenue"]);

}
function data(record) {
    /* 
    Increment the Units and Revenue measures in the cube 
        (at the intersection of Month, Actuals, Department, Product and Channel).
    */
    cube.increment(record.units, cubeName, record.month, "Actual", record.dept, record.product, record.channel, "Units");
    cube.increment(record.revenue, cubeName, record.month, "Actual", record.dept, record.product, record.channel, "Revenue");

}
function end() {
    //do nothing 
}
/**
 * Author: example name
 * Date Created: 2022-12-15
 * Date Modified: 2022-12-15
 * Date Deprecated: #N/A
 *
 * Parent Process: #N/A
 * Primary Function: Populate the Sales cube
 * Target: Sales
 * Datasource: CSV file from business users
 * Datasource Fields: 
 *      dept - department code
 *      product - product code
 *      channel - sales channel code
 *      month - the month in YYYY - MMM
 *      units - units sold
 *      revenue - invoiced revenue
 * 
 * Wipes and then reloads the Sales cube from a 
 *  CSV file containing all history
 */
var cubeName = "Sales";

function pre() { 
    //do nothing 
}
function begin() {

    /*
    wipe the Actuals data from the cube against the 
        Units and Revenue Measures.
    */
    cube.wipe(cubeName, ["","Actual","","","","Units|Revenue"]);

}
function data(record) {
    /* 
    Increment the Units and Revenue measures in the cube 
        (at the intersection of Month, Actuals, Department, Product and Channel).
    */
    cube.increment(record.units, cubeName, record.month, "Actual", record.dept, record.product, record.channel, "Units");
    cube.increment(record.revenue, cubeName, record.month, "Actual", record.dept, record.product, record.channel, "Revenue");

}
function end() {
    //do nothing 
}