Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION
dm-p
Super User
Super 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





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

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

4 REPLIES 4
dm-p
Super User
Super 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





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

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not 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.

Anonymous
Not 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.

Anonymous
Not applicable

@dm-p 

I've been using the dummy data method, which works well for most things, but have run into an issue that I believe it's causing. Maybe there's a workaround?

 

As mentioned in my last post, I'm trying to use the category to color objects through the Format pane. This works, until the visual is filtered. I think what is happening, is that because we have the guid set as a second category, the Format pane colors are tied to specific combinations of category and guid, not just a category. If the specific guid-category combination that we used to create the color picker in the Format pane is not still visible in the filtered view, then no color is passed in and we get a default theme color.

 

I can't see any way around this, but I'm hoping someone else can!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.