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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
pborah
Continued Contributor
Continued Contributor

Sort by another column not working.

I'm not sure of the issue as I'm not getting any errors. However I'm unable to sort by another column. Data is in import mode and I'm using an SQL query to pull the data. My categories/bins are created by a SWITCH statement, and I created a helper column with the sort order using another switch statement that referes to the calculated bins. But when go to modeling tab and select the the field for sorting, it doesn't sort the table in any order. Following is my table after sorting it by the helper column -

 

pborah_0-1601664922540.png

 

What am I doing wrong? Thank you.

 

1 ACCEPTED SOLUTION

Hi @pborah 

I build a sample table to have a test.

I think you can build two measures to achieve your goal.

In your screenshot I think Hold Time Cumulative has been impacted by the sort column. 

1.png

Hold Time Block = 
SWITCH (
    TRUE (),
    'Table'[Min] <= 5, "Under 5 Minutes",
    'Table'[Min] <= 8, "Under 8 Minutes",
    'Table'[Min] <= 10, "Under 10 Minutes",
    'Table'[Min] <= 11, "Under 11 Minutes",
    'Table'[Min] <= 12, "Under 12 Minutes",
    'Table'[Min] <= 13, "Under 13 Minutes",
    'Table'[Min] <= 14, "Under 14 Minutes",
    "Over 14 Minutes"
)
Hold Time Sort = 
SWITCH (
    TRUE (),
    'Table'[Hold Time Block] = "Under 5 Minutes",1,
    'Table'[Hold Time Block] = "Under 8 Minutes",2,
    'Table'[Hold Time Block] = "Under 10 Minutes",3,
    'Table'[Hold Time Block] = "Under 11 Minutes",4,
    'Table'[Hold Time Block] = "Under 12 Minutes",5,
    'Table'[Hold Time Block] = "Under 13 Minutes",6,
    'Table'[Hold Time Block] = "Under 14 Minutes",7,
    8
)

Measure:

Count of Report ID = CALCULATE(COUNT('Table'[Report ID]))
Report Cumulative Count = 
SUMX(FILTER(ALL('Table'),'Table'[Hold Time Sort]<=MAX('Table'[Hold Time Sort])),[Count of Report ID])

And you can sort the visual by Report Cumulative Count column. I try to add the sort column in this viausl and let it don't summarize, and the result shows correctly.

2.png

If this reply still couldn't solve your problem, please show me your data model(Without sensitive data), and tell your calculate logic about the Cumulative column. 

You can download the pbix file from this link: Sort by another column not working

Best Regards,

Rico Zhou

 

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

15 REPLIES 15
PaulDBrown
Community Champion
Community Champion

@pborah 

Oine way of solving this is to create a disconnected "Bin table" with the bin categories and an index column for sorting purposes. Sort the table by the index column
Next create the measures to refer to the bin's row context:

Measure= CALCULATE([Your value measure], FILTER(Table, [your switch defintion measure] = SELECTEDVALUE(Bin table[bin])))


Now create the visual by using the Bin Table field as rows and your measures as values. 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






The only solution right now is to do the sort by column funtion from the Model Table as previously recommened.

For some reason, in the October 2020 release of Power BI Desktop, the Sort By Column feature under the Column Tools Tab is not functioning, it is greyed out all the time, regardless which column the user clicks on.

 

Kenab22_0-1602012861538.png

This is the solution that worked for me, Thank you @themistoklis


If this solution does not work for you, then there is some other Data probelm. (circular reference, etc.)

 

 

pborah
Continued Contributor
Continued Contributor

@Kenab22 @PaulDBrown @themistoklis @v-rzhou-msft  Thanks all for contributing and I will try all of the solutions one by one but right now I have a bigger problem! And I'm about to lose it on this tool now. As soon as I drop the sort column onto the table and set it to "Don't Summarize", my cumulative totals break down. 

 

pborah_0-1602013815146.pngpborah_1-1602013849109.png

 

Not sure what is going on but now I'm back to being several steps backward in preparing this report. I really don't get why something this simple is so complicated in Power BI. We used Tableau in my last job. In there, you can simply drag and rearrange the bins... it's THAT easy.

Hi @pborah 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your data model and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

Hi @pborah 

I build a sample table to have a test.

I think you can build two measures to achieve your goal.

In your screenshot I think Hold Time Cumulative has been impacted by the sort column. 

1.png

Hold Time Block = 
SWITCH (
    TRUE (),
    'Table'[Min] <= 5, "Under 5 Minutes",
    'Table'[Min] <= 8, "Under 8 Minutes",
    'Table'[Min] <= 10, "Under 10 Minutes",
    'Table'[Min] <= 11, "Under 11 Minutes",
    'Table'[Min] <= 12, "Under 12 Minutes",
    'Table'[Min] <= 13, "Under 13 Minutes",
    'Table'[Min] <= 14, "Under 14 Minutes",
    "Over 14 Minutes"
)
Hold Time Sort = 
SWITCH (
    TRUE (),
    'Table'[Hold Time Block] = "Under 5 Minutes",1,
    'Table'[Hold Time Block] = "Under 8 Minutes",2,
    'Table'[Hold Time Block] = "Under 10 Minutes",3,
    'Table'[Hold Time Block] = "Under 11 Minutes",4,
    'Table'[Hold Time Block] = "Under 12 Minutes",5,
    'Table'[Hold Time Block] = "Under 13 Minutes",6,
    'Table'[Hold Time Block] = "Under 14 Minutes",7,
    8
)

Measure:

Count of Report ID = CALCULATE(COUNT('Table'[Report ID]))
Report Cumulative Count = 
SUMX(FILTER(ALL('Table'),'Table'[Hold Time Sort]<=MAX('Table'[Hold Time Sort])),[Count of Report ID])

And you can sort the visual by Report Cumulative Count column. I try to add the sort column in this viausl and let it don't summarize, and the result shows correctly.

2.png

If this reply still couldn't solve your problem, please show me your data model(Without sensitive data), and tell your calculate logic about the Cumulative column. 

You can download the pbix file from this link: Sort by another column not working

Best Regards,

Rico Zhou

 

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

 

v-rzhou-msft
Community Support
Community Support

Hi @pborah 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

themistoklis
Community Champion
Community Champion

@pborah Could you share the file with us?

pborah
Continued Contributor
Continued Contributor

Thank you for your response @themistoklis. Unfortunately I can't share the file as it contains highly sensitive data. Masking it would take a while but if I can get to it over the weekend, I will post the pbix for sure. In the meantime if you have any questions regarding what you THINK I might be doing wrong, I'd be happy answer them. Thanks!

my guess would be the helper column.

 

Can you add it to the table next to the first column so as to see the ordering?

Is the helper column numeric?

pborah
Continued Contributor
Continued Contributor

The helper column is numeric. I even checked the data type under the modeling tab to make sure it was correct. Interestingly enough, when I add it to the table, sorting is no problem! But I don't want it there.

 

pborah_0-1601671459837.png

 

Can you go to 'Model' view

Select the field

on Properies Pane --> Select Advanced

The sort by column (helper column)

pborah
Continued Contributor
Continued Contributor

@themistoklis @v-rzhou-msft  no my problem still remains. I tried the last suggestion @themistoklis suggested but still to no avail. Does it have anything to do with the fact that I'm using a report server compatible version of Power BI Desktop? Build is Jan 2020 and I cannot simply upgrade without putting a change request to my manager. 

 

As a workaround, I've included the helper column in the table and renamed it to something more suitable. 

 

Thanks.

@pborah 

Maybe it has to do that you are using an older version.

 

There is also a workaround. Add the helper column to the table... then hide it

There is not 'hide' option in PowerBI. You can do it by minimizing the column width.

Just move the curson over the line between the helper field heading and the column heading next to it. Then drag it to the left so as to completely hide it.

 

Make sure you have for column 'Headings' and 'Values' the word wrap set to 'off'. So as not to have the row height increased.

 

I hope it makes sense??

pborah
Continued Contributor
Continued Contributor

@themistoklis I already partially did what you suggested, I will go ahead and hide that column in the table. I'll kudo your responses for helping me, but please don't mind if I do not accept it as a solution. Thanks very much!

Thanks for the kudos @pborah 

 

The last resolution would be to share the file with us (if it doesnt contain any confidential data)

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.