cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vanillaicecream Frequent Visitor
Frequent Visitor

Any Documentation for Custom Sort

https://microsoft.github.io/PowerBI-visuals/docs/how-to-guide/sorting/#custom-sorting

 

So there appears to be documentation for default and implicit sort, but nothing for custom sorting. Are there any examples I can look at. 

1 ACCEPTED SOLUTION

Accepted Solutions
jppp
Advisor

Re: Any Documentation for Custom Sort

Hi @vanillaicecream ,

 

Just realized I got some code examples of fetchMoreData() and custom sorting:

Technicly the visual waits untill no data segments are available any more before parsing/converting the dataView.

 

-JP

View solution in original post

6 REPLIES 6
dm-p Established Member
Established Member

Re: Any Documentation for Custom Sort

Hi @vanillaicecream

I have a custom visual that sorts by various statistics, so I've added an object to my capabilities.json to let the user select how they want to sort and then manage the sorting of the resolved view model in my code based on these values.

The visual's codebase is pretty expansive but I'm happy to point you in the right direction if you want to review my implementation:

Note that in my capabilities.json, I'm actually using implicit sorting, and it looks like I forgot to set it to custom when I added in the sorting functionality that's there now. It's just forcing the dataViewMapping to sort by category when the data comes across from the data model and it subsequently doesn't get used like this due to the overrides detailed above anyway.

According to the validation schema for capabilities.json, you would just set this up as follows (much like default😞

"sorting" : {
    "custom": { }
}

Both implicit or custom sorting will disable the sort options in the visual header.

I hope that this helps you out!

Regards,

Daniel

vanillaicecream Frequent Visitor
Frequent Visitor

Re: Any Documentation for Custom Sort

Hey @dm-p , thanks for the informative reply, I really appreciate it. The examples you gave were very interesting and illuminating. 

 

I just have a small question. I've noticed that you are using a dataReductionAlgorithm of Top - 30,000 which will load the first 30,000 values. 

 

Hypothetically, if I have a dataset with 50,000 values and I implement a custom sort like this. Will it sort only the first 30,000 values or will it sort through all 50,000 values, then return the top 30,000?

 

Thanks again for your detailed reply.

dm-p Established Member
Established Member

Re: Any Documentation for Custom Sort

Hi @vanillaicecream,

No probs! There's not many of us that do custom visuals on here so I try to jump in where I can.

I believe that anything managed in code with respect to sorting will have to work post-data load from Power BI, as you can't work on the dataViewMapping until the data comes across from the data model and it's populated.

We might need guidance from @v-evelk or someone else from the team around the specifics on this one as anything I can offer would be wild speculation, I'm afraid.

Regards,

Daniel

 


But if you did want my speculation, I'd hazard a guess at just getting the top N rows that Power BI decides to provide, and something in my brain is nagging at me as to why I used implicit sorting here. There appears to have been a conscious decision to have done it, from looking back at my commit history. I'd further speculate that I probably wanted to make sure that if we had multiple categories, that we ensured at least some of them would be fully loaded in if we sorted the data this way. A good lesson here for improving quality of my commit messages to describe 'why' rather than 'what'...

vanillaicecream Frequent Visitor
Frequent Visitor

Re: Any Documentation for Custom Sort

No worries, I appreciate the clarification and quick response. 

 

Hopefully @v-evelk might be able to shed some light in this area. 

 

Thanks! 

 

jppp
Advisor

Re: Any Documentation for Custom Sort

Hi @vanillaicecream ,

 

There are no limits to use your own sorting algorithm within your visual. Set in the capabilities.json sorting to 'custom' and there will no sorting option the the visual menu. 

 

And if you are retrieve multiple data segments with size defined via the dataReductionAlgorithm property  (via fetchMoreData()https://microsoft.github.io/PowerBI-visuals/api/references/fetchmoredata/) users expect all the data to be sorted by the visual, so use your sorting algorithm for the complete dataview.

 

-JP

jppp
Advisor

Re: Any Documentation for Custom Sort

Hi @vanillaicecream ,

 

Just realized I got some code examples of fetchMoreData() and custom sorting:

Technicly the visual waits untill no data segments are available any more before parsing/converting the dataView.

 

-JP

View solution in original post

Helpful resources

Announcements
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (3,499)