Forum Discussion
Calculations by Rank
- 7 years ago
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() ) - 7 years ago
Anonymous -
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/
- 7 years ago
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.
Here's my code...
= VAR prevRank = Primary_ID[Rank] - 1 VAR differnce = Primary_ID[Value] - CALCULATE( VALUES(Primary_ID[Value], FILTER(ALLEXCEPT(Primary_ID,Primary_ID[Type],Primary_ID[Rank] = prevRank ) ) RETURN IF( differnce < Primary_ID[Value], differnce, 0 )
and here's the error I get...
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.
- Anonymous7 years agoNot applicable
Perfect! Many thanks for perservering with me Chris.
Much appreciated.
I learnt a lot.
Thanks again.
Peter