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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
PowerBINoob24
Resolver I
Resolver I

Sorting visual by a "date" that is text based.

Hi all,

 

I have a line graph visual that shows data by month/year; however, the the data is a text field and the data is "11 2022 Name", "12 2022 Name", "01 2023 Name", "02 2023 Name", and so on.

 

On the visual when sorted they show up in the order of   ""01 2023 Name", "02 2023 Name", 11 2022 Name", "12 2022 Name", which is to be expected.

 

How I need it to sort is "11 2022 Name", "12 2022 Name", "01 2023 Name", "02 2023 Name", "03 2023 Name", "04 2023 Name" and so on.  Any thoughts on how to go about this?

 

TIA

13 REPLIES 13
jdbuchanan71
Super User
Super User

Can you share your file?  Put it on dropbox or onedrive and share the link here.

I'll have to see if I can sanitize it.

jdbuchanan71
Super User
Super User

@PowerBINoob24 

You don't sort the table by the [test sort] column.   You set the sort order for the column you are showing in the x axis using [test sort] column.

In the table view.

Select the column you are showing in the x axis.

Go to the 'Sort by column' drop down and pick the [test sort] column.

jdbuchanan71_0-1679492185321.png

You are telling PowerBI 'Sort this column I have clicked on using the values in this other column I pick in the drop down'

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column?tabs=powerbi-deskto...

 

 

Okay...did that.  Still doesn't change the sort order on the visual

jdbuchanan71
Super User
Super User

So you would need to add another column using the same source but change the output to be the numeric sort order for the field you already added.  What is the DAX code for the created column you are trying to sort?

jdbuchanan71
Super User
Super User

Sorry, I don't follow.  Do you mean the table that has the field you are trying to add the sort to is a calcualted table?  The code Text.Middle([Campaign Group],3,4) & Text.Start([Campaign Group],2)) will only work in PowerQuery, it will not work in DAX.  

If you are working on a calculated table you could add the sorting field at the same time as you caclulate the rest of the table.

No.  It's not a calcuated table.  It's the original data table, but the column that I need to apply the formula to is not part of the original table, but was created by grouping together data from another column.

rohit_singh
Solution Sage
Solution Sage

Hi @PowerBINoob24 ,

In DAX, you can create a new column named "DateIndex" as shown below :

rohit_singh_0-1678896937492.png

 

Then select the Date column, click on "Sort by column" and select DateIndex.

rohit_singh_1-1678896985460.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

@rohit_singh 

Don't you get a circular dependency from that?

Hi @jdbuchanan71 ,

Thanks for pointing that out. I should have checked before posting. The Power query approach is the correct one. 
 
Kind regards,

Rohit

jdbuchanan71
Super User
Super User

You need a field that has the sort order in numeric format.  You can add one in PowerQuery by adding a custom column that gets the portion of the field you need to use for the sort.

Text.Middle([Text Field],3,4) & Text.Start([Text Field],2)

jdbuchanan71_0-1678896429874.png

Then change the data type of the new column to whole number.

jdbuchanan71_1-1678896483491.png

 

Then, in the table view change the sort by of the text field to use the new column.

jdbuchanan71_2-1678896575919.png

 

Okay.  So I managed to make some changes so I could implement what you suggested above.  Added a text sort column through Power query, went into the table view and the sorted by the test sort column.  It sorts as you stated it would in the table, but that doesn't impact the visual because the visual still sorts the x axis by the "01 2023 Name", "02 2023 Name", 11 2022 Name", "12 2022 Name".

Well that would work, but I just realized that the Name field is a column created in a table that is a group, so when I go into power query it's not available as a column in the source spreadsheet if that makes sense.  I've tried this: 

Campaign Sort = Text.Middle([Campaign Group],3,4) & Text.Start([Campaign Group],2)) but that throws the following error: 
The syntax for '.' is incorrect. (DAX(Text.Middle([Campaign Group],3,4) & Text.Start([Campaign Group],2)))).

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.