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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

Hi @Anonymous ,

 

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
Super User
Super User

Hi @Anonymous

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





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


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




Anonymous
Not applicable

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.

Hi @Anonymous,

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'...





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


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




Anonymous
Not applicable

No worries, I appreciate the clarification and quick response. 

 

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

 

Thanks! 

 

Hi @Anonymous ,

 

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

Hi @Anonymous ,

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors