cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

How to implement selections based on a categorical dataviewmapping with multiple fields

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

 

 

 

6 REPLIES 6
Highlighted
Super User II
Super User II

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Helper I
Helper I

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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}]}[]"}
...
...
...
Highlighted
Super User II
Super User II

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Super User II
Super User II

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Helper I
Helper I

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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

 

Highlighted
Helper I
Helper I

Re: How to implement selections based on a categorical dataviewmapping with multiple fields

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!

Helpful resources

Announcements
Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Kudoed Authors