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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
WILLIH
Helper I
Helper I

Id sequence

How do I get my id's to sort in order?

 

Power BI - Sort.PNG           Power BI - Sort 2.PNG

4 REPLIES 4
MFelix
Super User
Super User

Hi @WILLIH ,

 

Try the following code to add a custom column that you can then sort the other column by this one:

 

Power Query

try if  Value.Is (Number.From([ID]), type number) then Text.PadStart([ID], 10 , "0" ) else [ID] otherwise [ID]

Dax

Column = IF(IFERROR(VALUE('Table'[ID]);BLANK()) = BLANK();'Table'[ID];REPT("0";10 - LEN('Table'[ID])) & 'Table'[ID])

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @WILLIH ,

 

You need to convert the values into number, on the query editor if you click 123/ABC button you can select number on format.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi MFelix,

I did try changing the format of the data to a number but it still does not let me sort it. You can't see it from the pictures but some of the id's also have alpha in them like "D0017" or "EB255". Would that make a difference because the data is still being recognized as text?

 

Thanks,

 

WILLIH

Hi @WILLIH  if you alphanumeric codes you cannot convert to number,

 

Believe the best option is to add a new column with some additional zeros to the left on alll the number so you can then sort the numbers. 

 

Not on computer now but will send out the code tomorrow. 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.