Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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.
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
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!
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.:
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:
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 5 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |