Forum Discussion

user01's avatar
user01
Resolver I
2 years ago
Solved

Rank Based on Selected Data from Scatterplot

I have pulled some data via DirectQuery. The two tables are "asum" and "po". There is a one-to-many relationship from asum to po. I use asum to make a scatter plot. For example, if I query ID = 5, then I get the subsets of asum and po with ID = 5. Then I use X1 as the x values and Y as the y values for the scatter plot. I have a simple table for po. I want a measure that ranks the Option column based on selected values in the scatter plot. So when the scatter plot is unflitered (no selection) the rank on the Option is just the Option. Then for example if I select Options 2, 3, and 5 in the scatter plot, the ranks will be 1, 2, 3 respectively. I want this desired rank for both asum and po (po has duplicate Options). Seems simple but I cannot figure it out. How can I accomplish this?

 

Table asum

IDOptionX1X2YMean
4115155210053
42853198130
4319672197868
5110338143136
5217965205462
5315958160555
5416159146456
5523285192981

 

Table po

IDOptionValueLevel
41500
417001
4117502
4117502
4125003
42500
4249501
43500
437001
437001
4342502
511000
514001
515002
515002
5115003
521000
5224001
531000
534001
534001
535002
535002
535003
535003
5310004
541000
544001
544001
545002
545002
545003
545003
545004
545004
545005
551000
554001
554001
555002
555002
555003
555003
555004
555004
555005
555005

 

Desired result on asum when Options 2, 3, 5 are selected on scatter plot

 

Desired result on po when Options 2, 3, 5 are selected on scatter plot

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi user01 ,

    Ashish_Mathur mentioned the relationships , and I will continue to add to it later in this section:

    Below is my table1:

    Below is my table2:

    The following DAX might work for you:

     

    Rank asum = 
    VAR SelectedOptions = SELECTEDVALUE('asum'[Option])
    RETURN
        RANKX(
         ALLSELECTED('asum'),
            CALCULATE(MAX('asum'[Option])),
            ,
            ASC,
            DENSE
        )
    
    
    Rank po = 
    VAR SelectedOptions = SELECTEDVALUE('po'[Option])
    RETURN
        RANKX(
            ALLSELECTED('po'),
           
           
            CALCULATE(MAX('po'[Option])),
            ,
            ASC,
            DENSE
        )
    

     

    The final output is shown in the following figure:

    Best Regards,

    Xianda Tang

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

6 Replies

  • Hi,

    Which columns have you used in both tables for the 1 to Many relationship?  I do not see a way to do that because ID and Options in both tables have duplicates.

    • user01's avatar
      user01
      Resolver I

      Sorry for being unclear. It is asum Option (one) to po Option (many). The SQL Server has all the data, but I just query one ID (eg. ID = 5) into Power Bi via Direct Query. So asum[Option] looks like it has no duplicates.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi user01 ,

    Ashish_Mathur mentioned the relationships , and I will continue to add to it later in this section:

    Below is my table1:

    Below is my table2:

    The following DAX might work for you:

     

    Rank asum = 
    VAR SelectedOptions = SELECTEDVALUE('asum'[Option])
    RETURN
        RANKX(
         ALLSELECTED('asum'),
            CALCULATE(MAX('asum'[Option])),
            ,
            ASC,
            DENSE
        )
    
    
    Rank po = 
    VAR SelectedOptions = SELECTEDVALUE('po'[Option])
    RETURN
        RANKX(
            ALLSELECTED('po'),
           
           
            CALCULATE(MAX('po'[Option])),
            ,
            ASC,
            DENSE
        )
    

     

    The final output is shown in the following figure:

    Best Regards,

    Xianda Tang

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