Wiki source code of Create a calculated measure depending on the hierarchy level
Last modified by Aurelie Bertrand on 2020/10/19 18:35
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{ddtoc/}} | ||
2 | |||
3 | ---- | ||
4 | |||
5 | = With this.selection.dimsToExplore = | ||
6 | |||
7 | To choose the value of a calculated measure depending on the exploration level, add a calculated measure that uses the objects | ||
8 | {{code language="js"}}this.selection{{/code}} | ||
9 | and | ||
10 | {{code language="js"}}this.selection.dimsToExplore{{/code}} | ||
11 | allowing to determine the current hierarchy level. | ||
12 | |||
13 | Example: | ||
14 | {{code language="js"}}var dim = "myDimension"; // Dimension ID explored to search in the flow | ||
15 | var niv = -1; | ||
16 | // Look for the dimension in the information flow to get its exploration level | ||
17 | for (var idx = 0; idx < this.selection.dimsToExplore.length; idx++) | ||
18 | { | ||
19 | if (this.selection.dimsToExplore[idx].dim.id == dim) | ||
20 | { | ||
21 | niv = this.selection.dimsToExplore[idx].lPos; | ||
22 | // niv => -1: root level, 0: deepest level (close to root),.. n-1: highest level | ||
23 | break; | ||
24 | } | ||
25 | } | ||
26 | |||
27 | if (niv == 1) return 1234; | ||
28 | else if (niv == 0) return 5678; | ||
29 | else return 0;{{/code}} | ||
30 | |||
31 | = With this.selection.dimsToFilter = | ||
32 | |||
33 | To choose the value of a calculated measure depending on the exploration level, with filters, add a calculated measure that uses the objects | ||
34 | {{code language="js"}}this.selection{{/code}} | ||
35 | and | ||
36 | {{code language="js"}}this.selection.dimsToFilter{{/code}} | ||
37 | allowing to determine the current hierarchy level. | ||
38 | |||
39 | Example: | ||
40 | |||
41 | {{code language="JS"}} | ||
42 | var dim = "myDimension"; // Dimension ID explored to search in the flow | ||
43 | var niv = -1; | ||
44 | // Look for the dimension in the information flow to get its exploration level | ||
45 | for (var idx = 0; idx < this.selection.dimsToFilter.length; idx++) | ||
46 | { | ||
47 | if (this.selection.dimsToFilter[idx].dim.id == dim) | ||
48 | { | ||
49 | niv = this.selection.dimsToFilter[idx].lPos; | ||
50 | // niv => -1: root level, 0: deepest level (close to root),.. n-1: highest level | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | if (niv == 1) return 1234; | ||
56 | else if (niv == 0) return 5678; | ||
57 | else return 0; | ||
58 | {{/code}} |