Mapping.Date to Time.Date to Month
The below code builds a mapping from Date elements to Time elements. For each Date element in the Date List hierarchy, it walks two levels up one level in Default hierarchy - date to month, then maps the date to that month annual element in the Time dimension.
End outcome would be Date:2016-01-01 maps to Time:2026 - Jan.
Process Code
vb
var mapName = "Mapping.Date to Time.Date to Month";
var lDims = ["Date"];
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 dates = JSON.parse(hierarchy.rootElements("Date", "Date List"));
for (let i = 0; i < dates.length; i++) {
let date = dates[i];
let mon = hierarchy.parentByIndex("Date", "Default", date, 0);
if (hierarchy.hasMember("Time", "Default", mon)) {
mapping.rowAdd(mapName, [date], [mon]);
}
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.');
}