Slicer definition object properties
The following tables list the properties that are available for use when defining the JavaScript object for dynamic data definition of report slicers.
Page-level properties
| Property | Type | Description |
|---|---|---|
same_as | O | Used when your page contains slicers that should have same dynamically calculated value as a slicer on another page. |
| [slicerNames] | C | All other properties of this object will be the names/titles of the slicers on this page converted to the single-word camel-case property format. |
All visible slicers that are required to have dynamically calculated values must have per-page unique titles to be able to be referenced from the dynamic value definition JavaScript object. That includes linked slicers since the order in which the user will be opening the report pages cannot be pre-determined.
Even if two or more pages contain visible slicers that are linked to other slicers these must ALL be named and must ALL have their dynamic data definitions set separately for each if they are to be dynamically populated. However, repeating the same dynamic definition for more than one slicer would be error prone and tedious. The same_as property is available to solve exactly that problem.
On the page level this property’s value is a JavaScript array of arrays (”[[]]”) where the top-level array will contain an array per each page from which you are referencing slicers. The second-level arrays are then expected to contain each two or more strings where the first string is always the name of the page that is being referenced and the second and following strings represent the names of the slicers from that page whose dynamic definitions are to be reused.
You can only successfully use this page-level property if your slicers have exactly the same titles, which are converted to property names as described in Dynamic slicer definition > Page and slicer names topic.
If your slicers have different titles you will have to use the same_as property on slicer level.
Top-level slicer object properties
| Property | Type | Description |
|---|---|---|
same_as | N | Used when this slicer should have same dynamically calculated value as a slicer on another page. This property expects a single JavaScript array containing exactly 2 string elements where the first is the property name of the page it is referencing and the second the property name of the slicer found on that page whose definition of the dynamic value should be reused. |
name | O | Name of the slicer purely to help you identify the slicer. |
description | O | Description of the slicer purely to help you identify the slicer. |
target | N | May be needed if there are more then one target for the slicer, in which case the target must be specified. This object has two properties - table and column - which both must EXACTLY MATCH the same properties of the slicer. |
format | O | The format string to be used to format the items produced by the expression. For example if the result of the A special format of |
expression | N | A function that generates a value or list of values that will be checked against selectConditions to be included and selected. NOTE that due to the way how Power BI currently works any values that the slicer selection lists are supposed to contain but not have selected must be present in the data of the underlying target table(s). The expression can generate additional values that are not present in the underlying table(s) but these will also be automatically pre-selected. Power BI currently does not seem to allow adding values to the slicer list without selecting them at the same time. |
selectConditions | N | If any items generated by the expression are to be selected they must return true from running this condition expression. If the condition returns false and at the same time the value is not present in the underlying data table such value will not be present in the list. IMPORTANT: Only values generated by The allowed values of this property are:
|
values | N | Is an array which can contain one of the following:
|
conditions | N | Defines values for single-value slicers like date slicer or date range slicer, which contains two single-value fields. Each condition then corresponds to each single-value field. Must contain an array of JavaScript objects where each contains one of the following properties, but not both: keepOriginal or expression. These are described below. |
Lower-level object properties
target properties
| Property | Type | Description |
|---|---|---|
table | C | The name of the underlying data source table. |
column | C | The name of the linked data table column. |
value properties
The value property is an array of either objects or sub-arrays.
value objects properties
If the value array contains objects then these represent distinct list definitions and the first one whose condition will evaluate to true will be used to generate the value list and to select those values.
| Property | Type | Description |
|---|---|---|
condition | C | An expression which when it evaluates to true will override any properties defined in the parent object. The condition in these objects in the values list is evaluate for each of the contained objects until the evaluation returns true. When it does the evaluation of any subsequent object’s condition is skipped and the current object’s properties are used as overrides for the parent objects definition. The last object in this list may have the condition property omitted in which case it will be used to override the parent’s properties if no other preceding object’s condition property evaluated to true.An example condition: |
name | O | Overrides the same property in the parent object. |
description | O | Overrides the same property in the parent object. |
target | O | Overrides the same property in the parent object. |
format | O | Overrides the same property in the parent object. |
expression | O | Overrides the same property in the parent object. |
selectConditions | O | Overrides the same property in the parent object. |
value sub-arrays properties
If the value array contains sub-arrays then each of these sub-arrays represents a single value that the slicer should contain in its selection list.
The sub-arrays can have one to three properties like so: ["string or expression", isExpression, isSelected].
| Property | Type | Description |
|---|---|---|
string or expression | C | Either a direct value expressed as a string or a string representing an expression that needs to be evaluated to get the value. |
isExpression | O | true if the string or expression is in fact an expression. Defaults to false. |
isSelected | O | true if this value should be selected. Defaults to false. |
conditions property
This property contains an array which itself contains simple single-property JavaScript objects, one for each single-value field in the slicer. For example, for a simple date slicer there is only one value that may need to be dynamically set and so the array will only contain a single JS object. For a date period selector slicer which consists of two fields (Date From and Date To) - the array will contain two JS objects.
The JS objects can each contain one of the following properties, but not both as they are mutually exclusive:
| Property | Type | Description |
|---|---|---|
keepOriginal | N | Simply leaves the value defined in the definition of the report itself in that field. |
expression | N | A function that generates the single value for the corresponding slicer field. |
NOTE THAT you can use, if useful, a variable called originalValue within the expression. Its value will always be the original value coming from the report design itself.
Definition reuse using the same_as property
There will be cases where you need the same slicers with the same values on different report pages. This is actually necessary for all linked slicers unless their dynamic values are set on the ‘Cover’ page and are at the same time hidden on all the other pages where they are reused (linked).
In order not to have to repeat the same definitions for multiple slicers on different pages (or even the same page) you can utilize a property called same_as. This property lets you set in the root of a page definition or per slicer that its dynamic data definition is the same as a slicer already defined previously in the JavaScript definition object. That way you also avoid the cases where you could otherwise change the definition of one and forget to change it for the other(s).
Here is how to do this:
If your slicers names are identical between the pages
If you want to reuse the definitions for dynamic slicer data on another page and all the slicers that are to contain dynamic data have the exact same names on the other page, use the same_as property at the root level of that page’s definition like so:
{ slicers: { page1: { slicer1: { //..the dynamic data definition for "slicer1" }, slicer2: { //..the dynamic data definition for "slicer2 } }, page2: { same_as: [ ["page1", "slicer1", "slicer2" /*, slicer3, ...*/] ] } }}Here the value of the same_as property when it is found in the root of a report page definition is an array of arrays. Each second-level array represents a specific previously defined page. The first string in the array represents the name of the (source) page whose slicers’ dynamic data setup we want to apply to the slicers with the same name on the page being currently defined (the target page). Any strings that follow after the name represent the names of the slicers from the source page whose dynamic data definition should also apply the the same-named slicers on the target page.
If your slicer names are different between the pages
To reuse the definition of a slicer from another page where the slicer has a different name than the slicer we want to define as having the same dynamic value, put the same_as property into the definition of the slicer to be duplicated like so:
{ slicers: { page1: { slicer1_1: { //..the dynamic data definition for "slicer1" }, slicer1_2: { //..the dynamic data definition for "slicer2 } }, page3: { slicer3_1: { same_as: ["page1", "slicer1_1"] }, slicer3_2: { same_as: ["page1", "slicer1_2"] } } }}The value of the same_as property here, when it is found at the slicer definition level is a simple array with always only two members. Same as in the note for the previous slicer type above the first string represents the name of the source report page containing the slicer whose definition is to be dynamically copied and the second member of the array has to match the name of the actual slicer on that source page whose dynamic data definition we are instructing the program to reuse.