Forum Discussion
Anonymous
9 years agoNot applicable
Row Context - calculating looking up a value from row
Hi I cannot fully get row context when doing a calculation. I have created some dummy data to illustrate and hoping to get some help. This is my data, all the values in the far right column fore...
- 9 years ago
Hi Anonymous,
We can try to get the values with conditions, then we can test them with "if" statements.
Result = VAR level1 = CALCULATE ( MAX ( 'Table1'[56BM] ), FILTER ( 'Table1', 'Table1'[Distance] = EARLIER ( 'Table1'[Distance] ) && 'Table1'[NameID] = EARLIER ( Table1[NameID] ) && 'Table1'[Date] < EARLIER ( 'Table1'[Date] ) ) ) VAR level2 = CALCULATE ( MAX ( 'Table1'[56BM] ), FILTER ( 'Table1', 'Table1'[NameID] = EARLIER ( 'Table1'[NameID] ) && 'Table1'[Date] < EARLIER ( 'Table1'[Date] ) && 'Table1'[Distance] >= EARLIER ( Table1[Distance] ) - 200 && 'Table1'[Distance] <= EARLIER ( Table1[Distance] ) + 200 ) ) RETURN IF ( ISBLANK ( level1 ), IF ( ISBLANK ( level2 ), 9999, level2 - ( [weight] - 56 ) / 0.5 ), level1 - ( [weight] - 56 ) / 0.5 )The columns start with "Test" are to verify the result only.
Best Regards!
Dale
v-jiascu-msft
Microsoft Employee
9 years agoHi Anonymous,
We can try to get the values with conditions, then we can test them with "if" statements.
Result =
VAR level1 =
CALCULATE (
MAX ( 'Table1'[56BM] ),
FILTER (
'Table1',
'Table1'[Distance] = EARLIER ( 'Table1'[Distance] )
&& 'Table1'[NameID] = EARLIER ( Table1[NameID] )
&& 'Table1'[Date] < EARLIER ( 'Table1'[Date] )
)
)
VAR level2 =
CALCULATE (
MAX ( 'Table1'[56BM] ),
FILTER (
'Table1',
'Table1'[NameID] = EARLIER ( 'Table1'[NameID] )
&& 'Table1'[Date] < EARLIER ( 'Table1'[Date] )
&& 'Table1'[Distance]
>= EARLIER ( Table1[Distance] ) - 200
&& 'Table1'[Distance]
<= EARLIER ( Table1[Distance] ) + 200
)
)
RETURN
IF (
ISBLANK ( level1 ),
IF ( ISBLANK ( level2 ), 9999, level2 - ( [weight] - 56 ) / 0.5 ),
level1
- ( [weight] - 56 )
/ 0.5
)The columns start with "Test" are to verify the result only.
Best Regards!
Dale
Anonymous
9 years agoNot applicable
Thanks for the awesome solution. I have now learnt EARLIEST. Always amazed at DAX seems to have a really deep level of functions for almost any purpose.