Forum Discussion
Previous Value
Hello,
I would like to create a column with the previous value of each salary increase of the employees according to the print, but I am not able to.
The id is the employee's registration, and I would like to bring the increase respecting the date order.
I tried date add but couldn't.
can you help me?
Link excel
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 !!
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
3 Replies
- Ashish_MathurSuper User
- VahidDMSuper User
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 !!
- v-luwang-msftCommunity Support
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