Forum Discussion
Categorical data view mapping with non-numerical values
Hi! I'm building a visual which draws geometry from a 3d file which is uploaded through a button in html and then stored as a string object in the visual's properties. Each object in the file has a guid id (string), which I'd like to use to link the objects with data in the dashboard. So, in capabilities.json I have data roles like this:
"dataRoles": [
{
"displayName": "Guid",
"name": "guid",
"kind": "GroupingOrMeasure"
},
{
"displayName": "Color grouping",
"name": "category",
"kind": "GroupingOrMeasure"
}
]
But now I'm not sure how to set up the dataViewMappings. I'd really prefer to use categorical, in order to support getting highlights. The sticking point seems to be that as far as I can tell categorical's `values` object only works with numerical values (undocumented, as far as I have found). So, if I do something like this:
"categorical": {
"categories": {
"bind": {
"to": "category"
}
},
"values": {
"for": {
"in": "guid"
}
}
}
In Dataview I get category values for each of the guids, but no values array. And, if I try to highlight some values from another visual, no highlights array comes through.
So what does work is to set up categorical with both my `category` and `guid` data as categories, and then add a dummy numerical dataRole in `values`:
...
{
"displayName": "Required dummy numerical data",
"name": "data",
"kind": "GroupingOrMeasure"
}
],
"dataViewMappings": [
{
"categorical": {
"categories": {
"select": [
{
"for": {
"in": "guid"
}
},
{
"bind": {
"to": "category"
}
}
],
"dataReductionAlgorithm": {
"top": {}
}
},
"values": {
"bind": {
"to": "data"
}
}
}
}
]
Now in Dataview I get all the data I need, plus the array of dummy data, and even though the values in the highlights array are meaningless, I can look for nulls in order to filter. But of course I'd really prefer not to have to require this hack of the client. Is there another way to do this that I'm missing?
Hi Anonymous,
It's not necessarily that the categorical data view mapping only supports numeric values; it will only populate the values object if the data role for values is aggegrated - this could be a numeric value, or some kind of valid textual aggregate such as first or last. Either way, a valid mapping would only resolve one value per category in this scenario.
I have a similar challenge with one of my visuals, where the only way I'm able to 'force' the grain of the data is to introduce a 'sampling' or 'index' value, which generates a unique value for each row of the datset that the user needs to add into their data roles. I wrote up my findings here, which might provide some additional useful context for you. This approach requires work from the user's side, which is not ideal but is the only way I can get it to work with the way that Power BI provides data in this scenario.
If you didn't need highlighting, the table dataViewMapping would be my go-to, but that's not suitable for you either.
I spent some time, and trying to keep to your requirements, the best I could get was with the configuration below. Note that this only worked if I manually specified an aggregate (e,g, first) for category, which would still require some education for the end-user:
{ "dataRoles": [ { "displayName": "Guid", "name": "guid", "kind": "Grouping" }, { "displayName": "Color grouping", "name": "category", "kind": "GroupingOrMeasure" } ], ... "dataViewMappings": [ { "categorical": { "categories": { "select": [ { "for": { "in": "guid" } }, { "bind": { "to": "category" } } ], "dataReductionAlgorithm": { "top": {} } }, "values": { "bind": { "to": "category" } } } } ], "supportsHighlight": true }I'd be keen to see if this can be improved by anyone else, but with the current limits of my knowledge, I would probably go with the dummy measure 😛
I hope this helps in some way,
Daniel
4 Replies
- dm-pSuper User
Hi Anonymous,
It's not necessarily that the categorical data view mapping only supports numeric values; it will only populate the values object if the data role for values is aggegrated - this could be a numeric value, or some kind of valid textual aggregate such as first or last. Either way, a valid mapping would only resolve one value per category in this scenario.
I have a similar challenge with one of my visuals, where the only way I'm able to 'force' the grain of the data is to introduce a 'sampling' or 'index' value, which generates a unique value for each row of the datset that the user needs to add into their data roles. I wrote up my findings here, which might provide some additional useful context for you. This approach requires work from the user's side, which is not ideal but is the only way I can get it to work with the way that Power BI provides data in this scenario.
If you didn't need highlighting, the table dataViewMapping would be my go-to, but that's not suitable for you either.
I spent some time, and trying to keep to your requirements, the best I could get was with the configuration below. Note that this only worked if I manually specified an aggregate (e,g, first) for category, which would still require some education for the end-user:
{ "dataRoles": [ { "displayName": "Guid", "name": "guid", "kind": "Grouping" }, { "displayName": "Color grouping", "name": "category", "kind": "GroupingOrMeasure" } ], ... "dataViewMappings": [ { "categorical": { "categories": { "select": [ { "for": { "in": "guid" } }, { "bind": { "to": "category" } } ], "dataReductionAlgorithm": { "top": {} } }, "values": { "bind": { "to": "category" } } } } ], "supportsHighlight": true }I'd be keen to see if this can be improved by anyone else, but with the current limits of my knowledge, I would probably go with the dummy measure 😛
I hope this helps in some way,
Daniel
- AnonymousNot applicable
dm-p wrote:It's not necessarily that the categorical data view mapping only supports numeric values; it will only populate the values object if the data role for values is aggegrated
dm-p ,
Thanks! That's very helpful to know. I think I'll actually go with your version as I think it might appear slightly less hacky. Thanks for taking the time to explore! And yes, I too would love to see a better alternative. I'll accept your solution in a while if no one comes along with something better.
- AnonymousNot applicable
Hmm. Actually, I ran into another issue with something I didn't mention. I'm also using the category to color objects through the Format pane, so (according to my limited understanding) I need the `objects` object to be present on the category data in the dataview. With capabilities as you have it above, the category only comes in on the `values` object, which I'm guessing is why it doesn't carry the `objects` data. Guess we're back to dummy data, unless I've missed something.