Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Sort X-axis Line and clustered column chart

Hey,

I want to sort a X-axis from a line and clustered column Chart (variable sortedChart) and show only another column call (values) is it possible??

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi,Anonymous.Hello, parry2kThank you very much for your help on this issue, now I  want to share my solution below .
    I am glad to help you.

    According to your description, you are trying to implement a sorting function for the x-axis of a line/bar chart, right.

    In response to your later question "show only another column call (values) is it possible?", could you elaborate a bit more on what you mean?

    Could you elaborate a bit more on what you mean, if you can provide me with non-sensitive data, it would be very helpful in solving your problem.

    Here are the results of my test, I hope it can help you.

    Normally, if the data in the X-axis is simple data, such as data type, date type, then Power BI Desktop can sort it by default. However, you can customize the index columns and sort the X-axis based on the custom columns

    My test data is as follows.

    1. Create a new custom sorting column: C_sortIndex

    C_sortIndex = 
     SWITCH(TRUE(),
     test_data[x_Name]="A",1,
     test_data[x_Name]="B",2,
     test_data[x_Name]="C",3,
     test_data[x_Name]="E",4,
     test_data[x_Name]="D",5
     )
    

    2. Relying on the X-axis stored columns to re-create a calculated column, so that the value of the same, so as to avoid direct use of the X-axis based on the creation of the column C_sortIndex sorting circular dependency problems:

    PS: Sorting directly on the original columns of the X-axis will cause a circular dependency problem.
    Here's the right way to do it.

    x_sortValue = 'test_data'[x_Name]

    3. Sort the newly created column “x_sort” using the created index column ordering.

    4. Re-create visual, the realization of the bar chart in the X-axis by customizing the order of the columns to be sorted.

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

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









2 Replies

  • Anonymous sorry your question is not fully clear, could you please provide more details?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,Anonymous.Hello, parry2kThank you very much for your help on this issue, now I  want to share my solution below .
    I am glad to help you.

    According to your description, you are trying to implement a sorting function for the x-axis of a line/bar chart, right.

    In response to your later question "show only another column call (values) is it possible?", could you elaborate a bit more on what you mean?

    Could you elaborate a bit more on what you mean, if you can provide me with non-sensitive data, it would be very helpful in solving your problem.

    Here are the results of my test, I hope it can help you.

    Normally, if the data in the X-axis is simple data, such as data type, date type, then Power BI Desktop can sort it by default. However, you can customize the index columns and sort the X-axis based on the custom columns

    My test data is as follows.

    1. Create a new custom sorting column: C_sortIndex

    C_sortIndex = 
     SWITCH(TRUE(),
     test_data[x_Name]="A",1,
     test_data[x_Name]="B",2,
     test_data[x_Name]="C",3,
     test_data[x_Name]="E",4,
     test_data[x_Name]="D",5
     )
    

    2. Relying on the X-axis stored columns to re-create a calculated column, so that the value of the same, so as to avoid direct use of the X-axis based on the creation of the column C_sortIndex sorting circular dependency problems:

    PS: Sorting directly on the original columns of the X-axis will cause a circular dependency problem.
    Here's the right way to do it.

    x_sortValue = 'test_data'[x_Name]

    3. Sort the newly created column “x_sort” using the created index column ordering.

    4. Re-create visual, the realization of the bar chart in the X-axis by customizing the order of the columns to be sorted.

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

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