Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
1 year ago
Solved

DAX ??? Help

Hi I have the data mentioned below and I wanted to create a New Val calculated column, as long as there is negative, make it zero and the record of the next row should subtract the negative values. I...
  • pankajnamekar25's avatar
    1 year ago

    Hello Syndicate_Admin 

     

    You can try with below DAX for calculated column

     

    New Val =

    VAR CurrentIndex = 'Table'[Index]

    VAR CurrentVal = 'Table'[Val]

    VAR PrevVal =

        CALCULATE(

            MAX('Table'[Val]),

            FILTER(

                'Table',

                'Table'[Index] = CurrentIndex - 1

            )

        )

    RETURN

        IF(

            CurrentVal < 0,

            0,

            IF(

                PrevVal < 0,

                CurrentVal + PrevVal,  -- because PrevVal is negative

                CurrentVal

            )

        )

     

    Thanks,
     Pankaj Namekar | LinkedIn

    If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.