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. In the following example, on 1/1/2025 role 2 has -25 and has to be zero in New Val and the next row which is role 3 val has 40, but New Val must 40-25, i.e. 15 must get it. I'm not sure how to create a calculated column to get values like the ones I described. Any help.

  • 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.

4 Replies

  • 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.

  • v-priyankata's avatar
    v-priyankata
    Community Support

    Hi Syndicate_Admin 

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

    Thank you.

  • v-priyankata's avatar
    v-priyankata
    Community Support

    Hi Syndicate_Admin 
    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
    Thank you

  • v-priyankata's avatar
    v-priyankata
    Community Support

    Hi Syndicate_Admin 
    I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
    Thank you.