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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. 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

Share with Power BI Enthusiasts: 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.