Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Calculations by Rank

I

In my Var column I'd like to calculate the variance between the current rank and the next rank down/lower rank (for each Type). Eg: for Type B (on row 7) rank 4 is 120 less rank 3 (on row 6) is 105 thefore variance = 15.  Many thanks in advance!

  • Anonymous -

     

    Would the below work for you?

     

    Var = 
    VAR nextRank = Table1[Rank] + 1
    VAR differnce = 
        CALCULATE(
            VALUES(Table1[Value]),
            FILTER(ALLEXCEPT(Table1,Table1[Type]),Table1[Rank] = nextRank)
        ) - Table1[Value]
    RETURN
        IF(
            differnce >= 0,
            differnce,
            BLANK()
        )
  • Anonymous -

     

    You're missing closing ' ) ' in a couple places.

     

    Copy -> Paste my code and replace 'Table1' with 'Primary_ID' or try formatting multi-line by clicking ALT + ENTER so you can see your opening and closing Parentheses ' ( ' & ' )' respectively a little easier.

     

     

10 Replies

  • ChrisMendoza's avatar
    ChrisMendoza
    Resident Rockstar

    Anonymous -

     

    Would the below work for you?

     

    Var = 
    VAR nextRank = Table1[Rank] + 1
    VAR differnce = 
        CALCULATE(
            VALUES(Table1[Value]),
            FILTER(ALLEXCEPT(Table1,Table1[Type]),Table1[Rank] = nextRank)
        ) - Table1[Value]
    RETURN
        IF(
            differnce >= 0,
            differnce,
            BLANK()
        )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Chris,

      I'm afraid I don't really understand your reply (my fault).

      Which bit, exactly, do I need to type into my formula bar?

      Many thanks

      Peter

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        In particular I don'r understand how to feed this expression into the formula;

         

        Var = 
        VAR nextRank = Table1[Rank] + 1

        Thanks