Forum Discussion

edgar's avatar
edgar
New Member
5 years ago
Solved

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 wo...
  • VahidDM's avatar
    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  !!

  • Ashish_Mathur's avatar
    5 years ago

    Hi,

    You may download my PBI file from here.

    Hope this helps.

  • v-luwang-msft's avatar
    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