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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
eloomis
Advocate II
Advocate II

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

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

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

eloomis
Advocate II
Advocate II

@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

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors