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
Anonymous
Not applicable

Sort by (in Switch)

Hello, 

 

I have a series of value ranges.   I know I could enforce the proper sorting be prefacing each one by using something like 1. xxxx   2. xxxx   or a. xxxxx   b. xxxxx, which I don't want to do for aesthetic reasons.  

 

Is there a way, within this formula, to enforce the same sort order in which they are written below?    So, when I put them in a chart visual for example, they appear in the legend in same order as below.    Or a better solution?

 

Value Cohorts = SWITCH
    (TRUE(),
    'AllOpps-Products'[Extended Price]<100000,"$0 - $100k",
    'AllOpps-Products'[Extended Price]<500000,"$100k - $499k",
'AllOpps-Products'[Extended Price]<1000000,"$500k - $999k",
    'AllOpps-Products'[Extended Price]<5000000,"$1M - $4.9M",
    'AllOpps-Products'[Extended Price]<10000000,"$5M - $9.9M",
    'AllOpps-Products'[Extended Price]>=10000000,"$10M +",BLANK()
    )
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous add another coloum for sort

 

Value Cohorts Sort = SWITCH
    (TRUE(),
    'AllOpps-Products'[Extended Price]<100000,1,
    'AllOpps-Products'[Extended Price]<500000,2,
'AllOpps-Products'[Extended Price]<1000000,3,
    'AllOpps-Products'[Extended Price]<5000000,4,
    'AllOpps-Products'[Extended Price]<10000000,5,
    'AllOpps-Products'[Extended Price]>=10000000,6
    )

and now select Value Cohorts column, in column tool, sort it by Value Cohort Sort

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey @Anonymous ,

 

it's not possible to define a sort order from within a DAX statement.

 

This article describes how a column can be used by another column: https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column#select-which-column-to-use-for-sorting

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
parry2k
Super User
Super User

@Anonymous add another coloum for sort

 

Value Cohorts Sort = SWITCH
    (TRUE(),
    'AllOpps-Products'[Extended Price]<100000,1,
    'AllOpps-Products'[Extended Price]<500000,2,
'AllOpps-Products'[Extended Price]<1000000,3,
    'AllOpps-Products'[Extended Price]<5000000,4,
    'AllOpps-Products'[Extended Price]<10000000,5,
    'AllOpps-Products'[Extended Price]>=10000000,6
    )

and now select Value Cohorts column, in column tool, sort it by Value Cohort Sort

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.