Forum Discussion
Previous Value
- 5 years ago
Hi edgar
Please try this measure:
PREVIOUS VALUE = VAR _LastV = CALCULATE ( MAX ( 'Table'[VALUE] ), FILTER ( FILTER ( ALLEXCEPT ( 'Table', 'Table'[NAME] ), 'Table'[ID] = FIRSTNONBLANK ( 'Table'[ID], "" ) ), 'Table'[DATE] < MAX ( 'Table'[DATE] ) ) ) RETURN IF ( ISBLANK ( _LastV ), 0, _LastV )The Output would be as below:
Did I answer your question? Mark my post as a solution!
Appreciate your Kudos !!
- 5 years ago
- 5 years ago
Hi edgar ,
If you can create more than one column, you can use the following approach to add two new columns. This method is easier to understand, first group sort and use the sort order number for matching.
index = RANKX ( FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) ), 'Table'[DATE], , ASC, DENSE )pre = IF ( CALCULATE ( MAX ( 'Table'[VALUE] ), FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) && 'Table'[index] = EARLIER ( 'Table'[index] ) - 1 ) ) = BLANK (), "0", CALCULATE ( MAX ( 'Table'[VALUE] ), FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) && 'Table'[index] = EARLIER ( 'Table'[index] ) - 1 ) ) )If you can only create one column, you can use the following dax.
pre2 = VAR _max = MAXX ( FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] < EARLIER ( [DATE] ) ), [DATE] ) RETURN IF ( MAXX ( FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] = _max ), [VALUE] ) = BLANK (), 0, 0 + MAXX ( FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] = _max ), [VALUE] )Final result:
Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Best Regards
Lucien
Hi edgar ,
If you can create more than one column, you can use the following approach to add two new columns. This method is easier to understand, first group sort and use the sort order number for matching.
index =
RANKX (
FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) ),
'Table'[DATE],
,
ASC,
DENSE
)pre =
IF (
CALCULATE (
MAX ( 'Table'[VALUE] ),
FILTER (
'Table',
'Table'[ID] = EARLIER ( 'Table'[ID] )
&& 'Table'[index]
= EARLIER ( 'Table'[index] ) - 1
)
)
= BLANK (),
"0",
CALCULATE (
MAX ( 'Table'[VALUE] ),
FILTER (
'Table',
'Table'[ID] = EARLIER ( 'Table'[ID] )
&& 'Table'[index]
= EARLIER ( 'Table'[index] ) - 1
)
)
)
If you can only create one column, you can use the following dax.
pre2 =
VAR _max =
MAXX (
FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] < EARLIER ( [DATE] ) ),
[DATE]
)
RETURN
IF (
MAXX ( FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] = _max ), [VALUE] )
= BLANK (),
0,
0
+ MAXX ( FILTER ( 'table', [ID] = EARLIER ( [ID] ) && [DATE] = _max ), [VALUE] )
Final result:
Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Best Regards
Lucien