Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PMF999
Frequent Visitor

Calculations by Rank

Capture.PNGI

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!

3 ACCEPTED SOLUTIONS
ChrisMendoza
Resident Rockstar
Resident Rockstar

@PMF999 -

 

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()
    )





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

@PMF999 -

 

The entire code block is your calculated column. Documentation on using VAR can be found @ https://docs.microsoft.com/en-us/dax/var-dax and a nice example article can be found @ https://www.sqlbi.com/articles/variables-in-dax/

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

@PMF999 -

 

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.

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

10 REPLIES 10

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.