Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone,
Been trying to implement selections on my custom visual but somehow I cannot seem to make it work.
Context drillthrough works fine but the item selection just does not seem to be working.
Currently I am testing with 4 fields on the category and one measure only.
The logic that I have implemented is the following:
- For each of the measure values iterate through the 4 categories and add a new selection ID as for example:
for (var _i = 0; _i < categoricalDataView.values[0].values.length; _i++) {
...
...
categoricalDataView.categories.forEach((column: DataViewCategoryColumn) => {
const categorySelectionId = this.host.createSelectionIdBuilder();
categorySelectionId.withCategory(column, _i);
categorySelectionId.withMeasure(values[0].source.queryName);
_selectionIds.push(categorySelectionId.createSelectionId());
});
}
What is wrong here?
Thank you
Hi @djpirra
It's difficult to analyse 100% without seeing the rest of your code, but typically the methods you're calling against categorySelectionId to create your selectionId should usually be chained together.
Can you try the following and see if it works?
categoricalDataView.categories.forEach((column: DataViewCategoryColumn) => {
const categorySelectionId = this.host.createSelectionIdBuilder();
_selectionIds.push(
categorySelectionId
.withCategory(column, _i)
.withMeasure(values[0].source.queryName)
.createSelectionId()
);
});
If this isn't working, we might need to get a bit more detail, but let's start here.
Regards,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi Daniel,
I have tried that approach too...
I cannot use all together because I need to be sending an array to each datapoint since I have several category fields right?
This is the output of console.log for the selection ID:
e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":0}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":0}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":0}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":0}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":1}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":1}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":1}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":1}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":2}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":2}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":2}]}[]"}
VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":2}]}[]"}
...
...
...
Hi @djpirra,
Based on my understanding of the original code, the output looks okay, although you typically shouldn't need an array for each data point; just a selectionId. However,this will depend on how you are mapping your data, and how you are intending to use it within the visual. I have perhaps wrongly assumed you just wanted an array of all selectionIds available.
Normally, I might have an object array of my categories/values, with the selectionId as an attribute of that particular element, but again, this would depend on my intended use case.
Are you able to share your code at all? It might be more helpful if I can see how you're building your view model and how you are using it when you draw your visual. It might be that we need to make some changes elsewhere and it would be good if I can provide a more targeted answer for you.
Thanks,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi @djpirra,
In terms of selections with the categorical dataViewMapping, you can generate selectionIds for all values of 1 category x 1 grouping (series) x 1 measure. You would add a .withSeries() to your chain to include the grouping, similar to the worked example in the MS doc here.
I have also used this pattern in one of my visuals - this can be seen in how I map my view model here (and here's the dataViewMapping in the capabilities).
If you want to create a selectionId for a context of more categories than this, then you may need to use a table or matrix dataViewMapping (although if you wish to make use of highlighting in your visual, only categorical and matrix would be viable choices).
If you'd want to proceed with using the categorical approach, we should have a look at your code to see if it's possible to re-structure your capabilities or view model to see if we can make valid selectionIds work in this case.
Regards,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi Daniel,
This is what I have tried and also below is the output of one of the generated / triggered selectionIDs on the current setup.
Scenario 1:
- Created selectionId based on measure and 4 entries in categories ( current scenario )
- Created an array of selectionIds based on measure and each of the categories ( since apparently the selectionManager can receive an array of selectionIds )
e {measures: Array(1), dataMap: {…}, key: "{"XXXX.Is Auto":[{"identityIndex":11}],"Custo…tityIndex":11}]}["KPIs.# Active Customers"]"}
measures: ["KPIs.# Active Customers"]
dataMap:
XXXX.Is Auto: Array(1)
0: {identityIndex: 11}
length: 1
__proto__: Array(0)
XXXX.Is Malls: Array(1)
0: {identityIndex: 11}
length: 1
__proto__: Array(0)
XXXX.Is Real Estate: Array(1)
0: {identityIndex: 11}
length: 1
__proto__: Array(0)
XXXX.Is Retail: Array(1)
0: {identityIndex: 11}
length: 1
__proto__: Array(0)
__proto__: Object
key: "{"XXXX.Is Auto":[{"identityIndex":11}],"XXXX.Is Malls":[{"identityIndex":11}],"XXXX.Is Real Estate":[{"identityIndex":11}],"XXXX.Is Retail":[{"identityIndex":11}]}["KPIs.# Active Customers"]"
__proto__: Object
Hey everyone.
Was able to make it work....
Everything was ok with the code except that I had this option on my capabilities file:
"general": {
"displayName": "General",
"displayNameKey": "formattingGeneral",
"properties": {
"filter": {
"type": {
"filter": true
}
}
}
},
Apparently this disables the normal behavior.
Thank you!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.