Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

RANKX Measure

Hi to everyone!

 

I'm stuck with a RANKX measure that ranks always in 1 position. Hope somebody can help me with this.

 

As you can see, I have a matrix opened by "Grupo". I need to rank each of them by sales. The sales measure is already calculated and used in the RANKX measure.

 

What am I doing wrong?

 

Thanks in advance.

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi everyone!

     

    Happy to say that is know working, and ashamed after discovering the problem.

     

    The "Grupo" shown in the matrix, is from the facts table, not from the table "GruposIMS". I just changed the dimension of the matrix and the RANKX measure started to show real values.

     

    Thanks for the help.

8 Replies

  • Anonymous

     

    Hey!

     

    I have to make presumptions concerning measures used in your IF/RANKX expression. When testing I used a table with salaries, and then I created a measure MsrSumSalary where I summed salaries:

     

    MsrSumSalary = 
    SUM(Salary[Salary])

    I then created a RANKX expression , similar to yours: 

     

    Rank Salary = 
    IF(
        [MsrSumSalary] <> 0,
        RANKX(
             ALLSELECTED(Salary),ROUND(Salary[MsrSumSalary],0)
        )
    )

    Here is a screenshot of my table:

     

    HERE is a link to my .pbix file.

     

    The biggest difference is with ALLSELECTED; you appeared to reference a column. When I changed to reference the table, all seemed okay.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi ccakjcrx. Thanks for your reply.

       

      I've tried as you described but it's not working for me. The IF condition could be or not, never mind about that. The problem is with the RANKX.

       

      Here is my model:

       

      This is the Sales measure:

      Ventas IMS = 
      SWITCH(
      	VALUES('Selector Medida'[Medida]);
      	"USD";
      	'Medidas VentasIMS'[Ventas IMS MUSD];
      	"ML";
      	'Medidas VentasIMS'[Ventas IMS ML];
      	"UN";
      	'Medidas VentasIMS'[Ventas IMS MUN]
      )

      And "USD" as example:

      Ventas IMS MUSD = 
      SWITCH(
      	VALUES(
      		'Selector Período'[Período]
      	);
      	"YTD";
          CALCULATE(
              SUM(
                  'Ventas IMS'[ImporteVendidoUSD]
              );
              DATESYTD(
                  'Período IMS'[Fecha]
              )
          );
      	"MTH";
          SUM(
              'Ventas IMS'[ImporteVendidoUSD]
          );
      	"MAT";
          CALCULATE(
              SUM(
                  'Ventas IMS'[ImporteVendidoUSD]
              );
              DATESINPERIOD(
                  'Período IMS'[Fecha];
                  LASTDATE(
                      'Período IMS'[Fecha]
                  );
                  -1;
                  YEAR
              )
          )
      )

      And the RANKX:

      Ranking Grupos = 
      RANKX(
          ALLSELECTED('GruposIMS');
          ROUND('Medidas VentasIMS'[Ventas IMS];0)
      )

      I've deleted the IF condition.

       

      I'm still getting 1 position of rank for all options of "Grupo".

       

      Any other advice?

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        Anonymous

         

        Please try this

         

        Ranking Grupos =
        RANKX (
            ALLSELECTED ( 'GruposIMS' ),
            CALCULATE ( VALUES ( 'Medidas VentasIMS'[Ventas IMS] ) )
        )