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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
RajK2
Helper IV
Helper IV

Sorting for date table

I've created custom date table and need to make sorting column by orders via DAX formula, please suggest

example : year 2024,2025 

 

I've created manual column as i would need custom column in date table.

 

AND('Calendar'[Year]=2023,'Calendar'[Month Number]=1),1,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=2),2,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=3),3,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=4),4,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=5),5,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=6),6,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=7),7,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=8),8,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=9),9,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=10),10,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=11),11,
AND('Calendar'[Year]=2023,'Calendar'[Month Number]=12),12,

AND('Calendar'[Year]=2024,'Calendar'[Month Number]=1),13,
AND('Calendar'[Year]=2024,'Calendar'[Month Number]=2),14,
AND('Calendar'[Year]=2024,'Calendar'[Month Number]=3),15,
AND('Calendar'[Year]=2024,'Calendar'[Month Number]=4),16,
AND('Calendar'[Year]=2024,'Calendar'[Month Number]=5),17,

 

YYYY-MMSorting
2024-Apr4
2024-Aug8
2024-Dec12
2024-Feb2
2024-Jan1
2024-Jul7
2024-Jun6
2024-Mar3
2024-May5
2024-Nov11
2024-Oct10
2024-Sep9
2025-Apr4
2025-Feb2
2025-Jan1
2025-Mar3
2025-May5

 

2 ACCEPTED SOLUTIONS
rohit1991
Super User
Super User

Hi @RajK2 ,
To create a custom sorting column in your manual date table that ensures proper chronological order across years and months, the most effective approach is to generate a continuous numeric sort key using a DAX formula that combines the year and month into a single value. Rather than writing multiple AND conditions, you can simplify your logic by creating a calculated column like this: Sort Order = 'Calendar'[Year] * 100 + 'Calendar'[Month Number]. This will give you values like 202401, 202402, ..., 202512, which naturally sort in the correct year-month order. You can then use this Sort Order column to sort your custom YYYY-MM column by going to the "Modeling" tab and choosing "Sort by Column." This approach is cleaner, scalable for future years, and eliminates the need for repetitive manual conditions.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

Anonymous
Not applicable

Hi @RajK2,

Thank you for reaching out in Microsoft Community Forum.

Thank you @rohit1991    for the helpful response.

As suggested by rohit1991,  I hope this information was helpful. Please let me know if you have any further questions or you'd like to discuss this further. If this answers your question, please "Accept as Solution" and give it a 'Kudos' so others can find it easily.

Please continue using Microsoft community forum.

Regards,
Pavan.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @RajK2,

Thank you for reaching out in Microsoft Community Forum.

Thank you @rohit1991    for the helpful response.

As suggested by rohit1991,  I hope this information was helpful. Please let me know if you have any further questions or you'd like to discuss this further. If this answers your question, please "Accept as Solution" and give it a 'Kudos' so others can find it easily.

Please continue using Microsoft community forum.

Regards,
Pavan.

rohit1991
Super User
Super User

Hi @RajK2 ,
To create a custom sorting column in your manual date table that ensures proper chronological order across years and months, the most effective approach is to generate a continuous numeric sort key using a DAX formula that combines the year and month into a single value. Rather than writing multiple AND conditions, you can simplify your logic by creating a calculated column like this: Sort Order = 'Calendar'[Year] * 100 + 'Calendar'[Month Number]. This will give you values like 202401, 202402, ..., 202512, which naturally sort in the correct year-month order. You can then use this Sort Order column to sort your custom YYYY-MM column by going to the "Modeling" tab and choosing "Sort by Column." This approach is cleaner, scalable for future years, and eliminates the need for repetitive manual conditions.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors