Skip to content

Mapping.Time to Time.Month to Prior Month

The below code builds a mapping from Time.Month elements to prior month elements. For each month, it navigates back one month in the Month List hierarchy.

End outcome would be 2016 - Jul maps to 2016 - Jun

Process Code

vb
var mapName = "Mapping.Time to Time.Month to Prior Month";
var lDims = ["Time"];
var rDims = ["Time"];

function pre() {
    // This function is called once before the processes is executed.
    // Use this to setup prompts.
    script.log('process pre-execution parameters parsed.');
}

function begin() {
    // This function is called once at the start of the process
    script.log('process execution started.');

    if (mapping.exists(mapName)) {
        mapping.wipe(mapName);
    } else {
        mapping.create(mapName, lDims, rDims, false, true);
    }

    let months = JSON.parse(hierarchy.rootElements("Time", "Month List"));

    for (let i = 0; i < months.length; i++) {
        let mon = months[i];
        let priorMonth = hierarchy.offset("Time", "Month List", mon, -1)

        if (hierarchy.hasMember("Time", "Default", mon)) {
            mapping.rowAdd(mapName, [mon], [priorMonth]);
        }

        if (script.IsCancelled()) {
            return;
        }
    }
}

function data(record) {
    // This function is called once for each line of data on the second cycle
    // Use this to build dimensions and push data into cubes
}

function end() {
    // This function is called once at the end of the process
    script.log('process execution finished.');
}