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
danielbrownau
Regular Visitor

Custom Month Sort Order

I'm trying to create a sort order for months, but where the current month = 1, next month = 2, next next month = 3, etc.


I've tried a couple of measures, but not sure on how to start with this one.


Any help would be greatly appreciated.

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @danielbrownau ,

 

For your issue, you can do like this:

First, create a ‘datediff’ column by ‘DATEDIFF()’ function:

datediff = DATEDIFF(NOW(), Sheet1[Date], MONTH)

Second, create a ‘month_order’ column by ‘IF’ function:

month_order = 
IF(
    Sheet1[datediff] = 0,
    1,
    Sheet1[datediff] + 1
)

The result is as follows:

h4.PNG

 

Best regards,

Lionel Chen

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @danielbrownau ,

 

For your issue, you can do like this:

First, create a ‘datediff’ column by ‘DATEDIFF()’ function:

datediff = DATEDIFF(NOW(), Sheet1[Date], MONTH)

Second, create a ‘month_order’ column by ‘IF’ function:

month_order = 
IF(
    Sheet1[datediff] = 0,
    1,
    Sheet1[datediff] + 1
)

The result is as follows:

h4.PNG

 

Best regards,

Lionel Chen

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lionel-msft 

 

Perfect! Thank you for the assistance, works like a charm, and even over several past years.

Thank you again.

 

DB

Hi @danielbrownau ,

 

I think it's better to use RANKX() function:

Column = 
VAR now_date = MONTH(NOW())
RETURN
RANKX(
   ALL(Sheet1),
   DATEDIFF(now_date, Sheet1[date], MONTH),
    ,
    1,
   Dense
)

DATEDIFF(): https://docs.microsoft.com/en-us/dax/datediff-function-dax

RANKX(): https://docs.microsoft.com/en-us/dax/rankx-function-dax

 

Best regards
Lionel Chen

 

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.