in src/dataViewBuilder/matrixBuilder.ts [328:390]
private ensureValueInHierarchy(
hierarchy: HierarchyMetadata,
node: powerbi.DataViewMatrixNode,
row: any[],
insertSorted: boolean): powerbi.DataViewMatrixNode {
for (let levelIdx = 0; levelIdx < hierarchy.levels.length; levelIdx++) {
const level = hierarchy.levels[levelIdx];
// const columnExprs = level.sources.map((col) => <powerbi.data.SQExpr>col.expr);
const isLeafLevel = levelIdx === hierarchy.levels.length - 1;
// TODO: describe the difference here, or create value nodes separately
if (isLeafLevel && every(level.sources, (source) => source.isMeasure)) {
node.children = map(level.sources, (source, i) => {
let child: powerbi.DataViewMatrixNode = {
level: levelIdx,
};
// We omit the levelSourceIndex only when it is 0
if (i !== 0)
child.levelSourceIndex = i;
return child;
});
}
else {
if (!node.children) {
node.children = [];
// node.childIdentityFields = columnExprs;
}
const columnValues = level.tableIndices.map((index) => row[index]);
let child = this.findMatchingNodeInList(node.children, columnValues);
if (!child) {
child = {
level: levelIdx,
levelValues: columnValues.map((value, i) => ({
value: value,
levelSourceIndex: i
})),
// TODO: support a different column for identities to simulate GOK
// identity: mocks.dataViewScopeIdentityCompositeWithEquality(columnExprs, columnValues),
};
// DEPRECATED: these values are deprecated
child.value = last(columnValues);
// let levelSourceIndex = columnValues.length - 1;
// if (levelSourceIndex !== 0)
// child.levelSourceIndex = levelSourceIndex;
if (insertSorted)
this.insertInSortedOrder(child, node.children);
else
node.children.push(child);
}
node = child;
}
}
return node;
}