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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
astorey1
Frequent Visitor

Matrix Column sort following an IF statement

I have a set of data that has dates in it and added a column in the data view (Because i didnt know how to do it in query editor) with the following statement:

Overdue Status = IF([Due Date]<TODAY(),"Overdue", IF([Due Date]-30<TODAY(), "Next 30 Days", "30+ Days Away"))

This is fine apart from on my visuals I want to sort in a certain order:
1. Overdue
2. Next 30 Days
3. 30+ Days away
I now find I cant conditionally sort in query editor as the column 'Overdue Status' does not exist. 
 
Any help appreciated. 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello @astorey1 

The easiest way to do this is by creating a new column that represents your sort order and use the "Sort by column" option in the modelling ribon.

Overdue Status = IF([Due Date]<TODAY(),1, IF([Due Date]-30<TODAY(), 2, 3))

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Following are the steps:

Sort each row of the matrix.
Get transpose of the matrix.
Again sort each row of the matrix.
Again get transpose of the matrix.
Algorithm for sorting each row of matrix using C++ STL sort():

for (int i = 0 ; i < n; i++)
sort(mat[i], mat[i] + n);
Algorithm for getting transpose of the matrix:

for (int i = 0; i < n; i++) {
for (int j = i + 1; i < n; i++) {
int temp = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = temp;
}
}

I hope this helps!

Regards,

Lewis

Tech-consultant

apps4rent | o365cloudexperts | clouddesktoponline

Anonymous
Not applicable

Hello @astorey1 

The easiest way to do this is by creating a new column that represents your sort order and use the "Sort by column" option in the modelling ribon.

Overdue Status = IF([Due Date]<TODAY(),1, IF([Due Date]-30<TODAY(), 2, 3))

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors