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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Custom Sort Order for a Measure

I have the following measure which returns the screenshot of data below when applied to a matrix - essentially the date with a little calculation of how many days old the note is. 

 

 

StatusNoteDateFormatted = 
VAR DaysOld = 
    CALCULATE(
        DATEDIFF(
            SELECTEDVALUE('#Success - Project List'[ProjectStatusNoteDate]), 
            TODAY(),
            DAY
        )
    )
RETURN
        IF(
            DaysOld = BLANK(), 
            BLANK(), 
            SELECTEDVALUE('#Success - Project List'[ProjectStatusNoteDate]) & " (" & DaysOld & " Days Old)"
        )

 

 

eloomis_0-1684335349478.png

When you click the matrix header to sort chronologically, it sorts numerically rather than by the date.

i.e. 
5/9

5/8

5/5

5/3

5/12

5/11

 

I would like it to sort chronologically, oldest to newest or vice versa. 

 

I found this article which shows how to introduce a custom sort order to a measure but they only have 3 specific categories wheras my measure is dynamic based on the value of Status Note Date. Does anyone have any other methods similar where I could make this measure sort by date (or even by the count of days old) rather than numeric order when the column header is clicked?

 

Thank you in advance.

1 ACCEPTED SOLUTION

I meant you can FORMAT the date in your measure.

 

FORMAT(SELECTEDVALUE(...), "yyyy/MM/dd")

 

Pat

Microsoft Employee

View solution in original post

7 REPLIES 7
ppm1
Solution Sage
Solution Sage

It is sorting alphabetically (descending). You can FORMAT your date as "MM/dd/yyyy" so that the zeros show up and you get the needed order.

 

Pat

Microsoft Employee
Anonymous
Not applicable

Hi @ppm1 thanks for your response. So the sort by column (StatusNoteDate) I changed the date format to "MM/dd/yyyy". I can't format the calculated column (StatusNoteDate&DaysOld) that way since I am adding a string, it can't be both date and string. But if I sort the Calculated column by StatusNoteDate, it sorts in the correct order in data view but is still going alphabetical in the visual.

I meant you can FORMAT the date in your measure.

 

FORMAT(SELECTEDVALUE(...), "yyyy/MM/dd")

 

Pat

Microsoft Employee
Anonymous
Not applicable

Oh I understand now, thank you. This works!!

Anonymous
Not applicable

@amitchandak I converted my measure to a calculated column so that I could use the method you described. I'm still having a problem though. In data view, you can see that the calculated column is being sorted by ProjectStatusNoteDate (which is marked as a date field) and the sort is in the correct order.

 

eloomis_0-1684435209097.png

 

 

However, when I go to my visual it is still out of order. In descending order, we see 5/5, 5/3, 5/2, then 5/11, 5/10, 4/29 and so on.

 

eloomis_1-1684435355194.png

 

I've tried resorting the visual many times and continue to get the same result. Is there anything else I can try?

amitchandak
Super User
Super User

@Anonymous , Mark the datetime column (or take out from this column) and mark that sort column for Status Not Date

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hey @amitchandak, thanks for your reply.

 

Unfortunately Status Note Date Formatted is a measure which is the column you see in the visual (Status Note Date). I was under the impression you can't define a column to sort a measure by.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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