Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
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.
Solved! Go to Solution.
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...
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.
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...
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.
@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.
@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.
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.