Forum Discussion

valcat27's avatar
valcat27
Icon for Helper III rankHelper III
5 years ago

Scatter plot- add legend removes the X axis ordering

Hello all,

 

I created a scatter plot that is defined to be sorted by x-axis, but when I add the legend, it is no longer ordered correctly. 

 

For a better understanding, imagine that I want to observe the product that each client bought and how much he paid.

These are some information about it that I can share:

- All the fields belong to the same table;
- X axis corresponds to the ProductID and its data type is "Whole Number";
- I have more than 500 products and a ProductID can have up to 8 digits;
- Y axis is a created column that corresponds to the price and its data type is "Decimal Number";;
- Legend is the name of clients and its data type is "Text";
- Each column is defined to be ordered by itself.

 

Can anyone help me?

 

Thanks in advance.

 

 

 

 

10 Replies

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, valcat27 ;

    You could create a column by dax or create a index column in power query as a  auxiliary sorting column. as follows:

    1.create a sort column.

    sort = RANKX('Table',[ProductID],,ASC,Dense)

    2.Select the name field, and then sort by sort column.

    3.The final output is shown below: 

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • valcat27's avatar
      valcat27
      Icon for Helper III rankHelper III

      Hello v-yalanwu-msft, 

       

      Thank you for your help, but it did not work because I have more than one Client per Product. 
      I tried with my data and I got this message: It's not possible to sort the column "ClientID" by "sort". It cannot exist more than one value in "sort" for the same value in "ClientID". Choose a different column to sort or update the data in "sort". 

      • v-yalanwu-msft's avatar
        v-yalanwu-msft
        Icon for Community Support rankCommunity Support

        Hi, valcat27 ;

        According to your description, I tested it which one product have three different client . then use same ways sort ,and it is ok.

        The final output is shown below:

        I am sorry that i can't reproduce your error, however , you also could try to create a index column as a sort column in power query .
        1.sort by ProductID

        2.Add index column as a sort column.

        3.sort by index column.

        If it doesn't work, can you share the picture of your data or pbix whitout any sesentive information and the result you want to output? 

        Best Regards,
        Community Support Team_ Yalan Wu
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, valcat27 ;

    I am not very clear about your meaning and scenario, can you share similar screenshots or more information about your question? After my test, if the X-axis and Y-axis are of Whole Number and Decimal Number, it is automatically sorted according to the size of the number,such as the below:

    If you change the ProductID type to "text", the sort and the chart will change also.

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • valcat27's avatar
      valcat27
      Icon for Helper III rankHelper III

      Hello v-yalanwu-msft ,

       

      Thank you for your answer.

       

      Defininig ProductID as text, it does not work because it sorts it considering only the first digits and ignoring how many digits the number has. It sort is like this: 12345, 124,15, 2357, 274...

       

      With the productID as Whole Number type, I selected the type of the x-axis as categorical to avoid overlapping values. As you can see in the following figure, the values are not all sorted. It looks like they are sorted for some groups/periods. (The visual was selected to be sorted by ProductID and ascending).