cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
alexa_0028
Resolver II
Resolver II

What is the sorting algorithm used by PBI?

Hi All,

I want to know the sorting algorithm of PBI. In Redshift DB when I sort a column(it sorts on ascii value),
but I don't see the same sorting results on the PBI visuals because my data is a mix of numbers/alphabets/special characters(.,_,#,$,etc.)

Can someone please help and suggest something?
This is breaking automation tool , when doing line by line comparison of PBI reports to database due to different sorting algorithms between database and PBI.


1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @alexa_0028 ,

 

As far as I know, Power BI will sort your data based on data format. As normal, Power BI will sort the numbers according to their size or dates according to chronological order.

If you have multiple different data in one cell like number, text, and delimiters. For example: 1,10,ACE

The data type of this columns is text. Power BI will sort this column by each value in same position in cells.

For example there is a column with two rows. 

row1: 1,10,ACE

row2: ACE,10

This column is in text format. Power BI will sort row1 and row2 by first value in them. 1<A so Power BI will use this sort to sort the column. If the first data in row1 and row2 are both 1. Power BI will compare the second value in them until get the result.

From my test, I know sort is delimiters<number<text. And delimiters/numbers/text still contain the normal logic in them. Like 1<2<3... A<B<C...

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
alexa_0028
Resolver II
Resolver II

Thank you @v-rzhou-msft and @Greg_Deckler   for the explaination

v-rzhou-msft
Community Support
Community Support

Hi @alexa_0028 ,

 

As far as I know, Power BI will sort your data based on data format. As normal, Power BI will sort the numbers according to their size or dates according to chronological order.

If you have multiple different data in one cell like number, text, and delimiters. For example: 1,10,ACE

The data type of this columns is text. Power BI will sort this column by each value in same position in cells.

For example there is a column with two rows. 

row1: 1,10,ACE

row2: ACE,10

This column is in text format. Power BI will sort row1 and row2 by first value in them. 1<A so Power BI will use this sort to sort the column. If the first data in row1 and row2 are both 1. Power BI will compare the second value in them until get the result.

From my test, I know sort is delimiters<number<text. And delimiters/numbers/text still contain the normal logic in them. Like 1<2<3... A<B<C...

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

alexa_0028
Resolver II
Resolver II

@Greg_Deckler 
Thanks for the information. But in the case my filed is not fully alphabetically or numerical. However, when I sort this column in PBI the sorting doesn't match with the sorting in the database(source of data) as database sorts with ascii key. 

Can someone please explain the rule in case of mixed column for PBI sorting? Is there anyway to do the sorting as ascii in PBI as well?

 

@alexa_0028 Sorting and string comparison - Globalization | Microsoft Docs

I would call Power BI's mixed alphabetical sorting to be the generally "normal" way of sorting based upon special characters first, numbers and then letters. Now in this sorting you will get things like , 1, 10, 11, 2, 20, 3, etc.

 

If you want a different sorting order, you could create a new column and use the UNICODE function, for example. Sample data would help to be more specific.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@alexa_0028 Would need to understand this better. PBI sorts text fields alphabetically and numeric fields numerically. You can set a custom Sort By column if you want something different.

 

Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors