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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Property 'rolesIndex' does not exist on type 'DataViewMetadataColumn'

Hi,

I am working on a Power BI visual where I would like to access a DataViewMetaDataColumn's rolesIndex property. However, accessing this property in Visual Studio Code throws an error.

Property 'rolesIndex' does not exist on type 'DataViewMetadataColumn'.ts(2339)

Current Version of Power BI Vis API: 3.8.0

 

My code looks like the following: 

const columns = options.dataViews[0].metadata.columns;
const labels = columns.filter(col => col.roles.labels)
labels.sort((col1 ,col2) => col1.rolesIndex.labels[0] - col2.rolesIndex.labels[0])

 Idea is to sort these columns based on the label index.

 

Is this a bug or am I doing something wrong here? Please let me know.

4 REPLIES 4
Anonymous
Not applicable

A solution I found which fixes this issue is by making the columns variable type to any[].

const columns: any[] = options.dataViews[0].metadata.columns;

 

However, this seems to be a Typescript fix to solve this issue, there might be a bug here.

Hi @Anonymous,

Indeed, it looks like rolesIndex is not an officially supported property in the API for a DataViewMetadataColumn, so whilst you might have worked around it for now, it might not always be present (or consistent) in the developer visual. It's probably worth creating an issue for it to see if the team can add official support for it in the available interfaces. You may get an more official response this way also, as the team do not monitor the forums currently.

Regards,

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)




Hi Daniel,

Just starting PBI custom visual development. rolesIndex seems to be the only way to determine the order/position of fields in an input.

Otherwise, the data in the dataView is ordered chronologically based on when the field was inserted into the input, regardless of its position in the field input.

I would like to order the columns of a table by position in the field input (like the default table) and need the indexes to do so. Do you know how that can be achieved without using the rolesIndex?

Please see screenshot for clarification.

Thanks!

ryan_f_0-1665179176131.png

 

Hi @ryan_f,

I would suggest following the advice in my original reply to create an issue for the property to be correctly supported by MS, or contact pbicvsupport@microsoft.com for an official response.

If you want to try this yourself in lieu of following this up, then I can (somewhat reluctantly) offer a possible approach, but no guarantees that it will work for your situation, as I don't have any details around your capabilities and how your dataRoles are named (or have they are mapped), but it may be enough for you to figure it out.

As such this approach assumes that in the rolesIndex property, I would see an object matching the role name, with an array of numbers (mine has a single digit entry, which I presume is the value you need), e.g.:

dmp_0-1665351638771.png

 

As the API doesn't type the property, you'll need to do this yourself, and based on this, I'd do something like the following to cast it:

interface IRoleIndex {[key: string]: number[]};
const roleIndex = (<IRoleIndex>column?.source?.['rolesIndex'])?.dataset?.[0];

What I've done here is:

  • Create an interface, IRoleIndex, which specifies flexible object keys, and a numeric array as its property (this could be done inline, but it makes the second line a bit harder to track, and also means the interface could be reused elsewhere.
  • Access the rolesIndex property using bracket notation rather than dot notation. By doing this, TypeScript will allow me to access a property that is not part of the DataViewMetadataColumn interface definition from the API and will cast is an an any type. I then surround this with brackets, casting it to the IRoleIndex interface.
  • After the bracket, attempt to acceess the property that correlates with my dataRole name, and then its first element.
  • Note that as this is potentially volatile, I'm using optional chaining all the way through, so my code will at least execute. Although, you may need to handle casting a null or undefined result from this chain into a fallback value.
This may help you, but I'd still recommend following this up with MS if its a feature you want to be supported, as this may break from one version API to the next (or even as a result of changes to the developer visual rather than the APIs... which has been known to happen).
Regards,
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)




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.