Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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 g...
  • dm-p's avatar
    6 years ago

    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