Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article describes the different options available for to specifying the way a visual sorts items in Power BI.
By default, a visual doesn't support modifying its sorting order, unless stated otherwise in the capabilities.json file.
The sorting capability requires at least one of the following parameters:
The default
option is the simplest form. It allows the user to sort according to any one field and direction (ascending or descending). The user selects the direction and field from the more options menu.
To enable default sorting, add the following code to your capabilities.json file:
"sorting": {
"default": { }
}
Implicit sorting allows you to pre-define a sorting array using parameter clauses
, that describes sorting for each data role. The user can't change the sorting order, so Power BI doesn't display sorting options in the visual's menu. However, Power BI does sort data according to specified settings.
To enable implicit sorting, add the implicit clauses
to your capabilities.json file
clauses
parameters can contain several objects with two parameters each:
role
: Determines DataMapping
for sortingdirection
: Determines sort direction (1 = Ascending, 2 = Descending) "sorting": {
"implicit": {
"clauses": [
{
"role": "category",
"direction": 1
},
{
"role": "measure",
"direction": 2
}
]
}
}
Custom sorting gives the developer more flexibility when sorting. The developer can:
To enable custom sorting, add the following code to your capabilities.json file:
"sorting": {
"custom": {}
}
let queryName1 = this.dataView.matrix.columns.levels[0].sources[0].queryName;
let queryName2 = this.dataView.matrix.columns.levels[1].sources[0].queryName;
let args: CustomVisualApplyCustomSortArgs = {
sortDescriptors: [
{
queryName: queryName1,
sortDirection: powerbi.SortDirection.Ascending
},
{
queryName: queryName2,
sortDirection: powerbi.SortDirection.Descending
},
]
};
this.host.applyCustomSort(args);
Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn more