Forum Discussion

taylororiger's avatar
taylororiger
Helper II
4 years ago
Solved

Adjusting Sort Order

Adjusting Columns/Rows Sort Order
Tuesday

 

I have these "Years as EL" in those groups.  Is there a way to display those in the correct order? (5-9 should be after 0-4, for example).  I have this issue with a few tables where the sorting needs to be rearranged.  I know you need to create a reference/dimension table with the specificed sort order and use a "RELATED" function, but I can't figure out how to create a dimension/reference table either.  Please help!

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi taylororiger ,

     

    [Year as EL] is a text type column, so Power BI will sort it by sort each word which is in same poisition. Power BI doesn't support us to sort a column by another calculated column which is built based on this one. So if you create a calcualted column like PijushRoy mention and sort [Year as EL] by this column, you will get an error as below.

    Here I suggest you to create a conditional column in Power Query Editor and select change column type to whole number.

    Then you can sort [Year as EL] by this custom column.

    For reference: Sort one column by another column in Power BI Desktop

    Result is as below.

     

    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.

2 Replies

  • PijushRoy's avatar
    PijushRoy
    Community Champion

    Create a Calculated Column with below DAX
    Sort Col= VAR _yearsasel = SELECTEDVALUE(Table'Years as EL')
    SWITCH(
    TRUE(),
    _yearsasel = "0-4",1,
    _yearsasel = "5-9",2,
    _yearsasel = "10-14",2,
    so on

    Click the column YEARS AS EL and select SORT BY from ribbon and select new calculated column.
    In the visual, 3 dot, Sort by YEARS AS EL and acceding order

    If you have any question, please posted
    If solve your requirement, please mark this answer as SOLUTION
    If this comment helps you, please LIKE this comment/Kudos

    Other option you can follow - https://community.powerbi.com/t5/Desktop/quot-Sort-by-column-quot-from-a-related-table/m-p/89265#M37...

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi taylororiger ,

     

    [Year as EL] is a text type column, so Power BI will sort it by sort each word which is in same poisition. Power BI doesn't support us to sort a column by another calculated column which is built based on this one. So if you create a calcualted column like PijushRoy mention and sort [Year as EL] by this column, you will get an error as below.

    Here I suggest you to create a conditional column in Power Query Editor and select change column type to whole number.

    Then you can sort [Year as EL] by this custom column.

    For reference: Sort one column by another column in Power BI Desktop

    Result is as below.

     

    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.