Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Syndicate_Admin
Administrator
Administrator

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.

1 ACCEPTED SOLUTION
pankajnamekar25
Super User
Super User

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.

View solution in original post

4 REPLIES 4
v-priyankata
Community Support
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.

v-priyankata
Community Support
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
Community Support
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.

pankajnamekar25
Super User
Super User

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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.