Forum Discussion
Sort Values from Calculated Column
Hi AkshayManke,
Sorting the "Due Status" column as per your expectations is possible. We can use the Sort By Column functionality in Power BI to achieve the desired sorting, though we need to keep in mind to avoid circular dependency while sorting. Please follow the steps below -
- I am assuming you created the Due Status calculated column using some logic in DAX. Assume the following sample data I created
- We need to assign a number/ code to each due status which will be used for sorting the column. If you create a calculated column "Due Status Order" based on Due Status column itself, it will lead to circular dependency issues, as shown below -
Due Status Order =
SWITCH(
Products[Due Status],
"Overdue", 1,
"Due Today", 2,
"Not Due Today", 3
)
- Hence instead, create a calculated column with the exact same formula as your Due Status column, just replace the values "Overdue", "Due Today" and "Not Due Today" with 1, 2 and 3 respectively. This means we are just creating a calculated column for ordering statuses based on the source column itself. I will call this column as "Due Status Order Source"
- Select Due Status Column and click on Column Tools Tab -> Sort By Column -> Due Status Order Source
Voila! The columns in the matrix should now be sorted
Before Sorting:
After Sorting:
This behaviour is very well explained using the following diagrams available here
Let me know if you have any questions!
- AkshayManke2 years ago
Helper II
Hello Bipin-Lala , Bipin,
I tried with the steps but getting the above error while trying to sort column based on the newly created. Could you please help what additionally needs to be done?
Thanks and Regards,
- Bipin-Lala2 years ago
Solution Sage
Hi AkshayManke,
It seems like for each Status value, you are assigning multiple values of S Sort, which is causing this issue. Could you please share the DAX formula you used for creating the Status and S Sort columns?
Also, some more information about the data would be helpful, such as does the Status column contains any blanks, etc.
- AkshayManke2 years ago
Helper II
Hello Bipin-Lala, _AAndrade, and Anonymous,
Apologies for late reply. Actually after trying all the possibilities i simply added numbers in prefix in the expected order and now i am getting the expected output. Below the DAX which finally i used.
Status = IF( 'Tasks List'[Completion] = "Not-Started" && 'Tasks List'[PlannedEndDate]='Tasks List'[Today] , "2. Due Today", IF( 'Tasks List'[Completion] = "Not-Started" && 'Tasks List'[PlannedEndDate]<'Tasks List'[Today], "1. Overdue", "3. Not Due Today" ) )However many thanks for your quick suggestions and help.
I am marking both of your responces as solutions.
Thanks and Regards,