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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Thimma_pbi
Helper I
Helper I

DAX help

Hi,

I have data as mentioned below and wanted to create New Val calculated column, whenever there is negative make it zero and next row record should be substracted negative values.

 

In the below example, 1/1/2025 role 2 has -25 and it has to be zero in New Val and next row that is role 3 val has 40, but New Val should 40-25 i.e 15 should get it.

 

Not sure how to create calculated column to get values as I described.

 

Any help.

 

Thanks,
Thimma

 

DtCoderoleValNew Val
01-01-2025L113030
01-01-2025L12-250
01-01-2025L134015
01-02-2025L111515
01-02-2025L1200
01-02-2025L13-250
01-03-2025L11305
01-03-2025L12-50
01-03-2025L136560
01-04-2025L118383
01-04-2025L12-200
01-04-2025L134020
1 ACCEPTED SOLUTION
Kishore_KVN
Super User
Super User

Hello @Thimma_pbi ,
I can suggest quickly with the help of creating INDEX in Power Query. 

DAX for the new column will be like below:

New Value = 
VAR PV = LOOKUPVALUE('Table'[Val],'Table'[Index],'Table'[Index]-1)
RETURN
IF('Table'[Val]<0,0,
IF('Table'[Index] =1,'Table'[Val],
IF('Table'[Val]>0 && PV < 0, 'Table'[Val] + PV , 'Table'[Val])))

Output looks as below:

Kishore_KVN_0-1747300014448.png

Attached pbix as well for your refrence. 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

View solution in original post

8 REPLIES 8
v-priyankata
Community Support
Community Support

Hi @Thimma_pbi 
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 @Thimma_pbi 
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 @Thimma_pbi 

Thanks @Kishore_KVN @bhanu_gautam for your inputs, @Thimma_pbi 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.

Kishore_KVN
Super User
Super User

Hello @Thimma_pbi ,
I can suggest quickly with the help of creating INDEX in Power Query. 

DAX for the new column will be like below:

New Value = 
VAR PV = LOOKUPVALUE('Table'[Val],'Table'[Index],'Table'[Index]-1)
RETURN
IF('Table'[Val]<0,0,
IF('Table'[Index] =1,'Table'[Val],
IF('Table'[Val]>0 && PV < 0, 'Table'[Val] + PV , 'Table'[Val])))

Output looks as below:

Kishore_KVN_0-1747300014448.png

Attached pbix as well for your refrence. 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

Unfortunately I can't create Index, wanted to check using calculated column only.

No, that not right. You can create index without which how you know the order of the value column?

So, you have to figure out a way of creating index for your data. Atleast ROW NUMBER should be created. 

bhanu_gautam
Super User
Super User

@Thimma_pbi , Try using below dax for calculated column

 

New Val =
VAR CurrentVal = 'Table'[Val]
VAR PreviousRow =
CALCULATE(
SUM('Table'[Val]),
FILTER(
'Table',
'Table'[Dt] = EARLIER('Table'[Dt]) &&
'Table'[role] = EARLIER('Table'[role]) - 1
)
)
VAR Adjustment =
IF(PreviousRow < 0, -PreviousRow, 0)
RETURN
IF(CurrentVal < 0, 0, CurrentVal - Adjustment)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for the response, but previous val is not picking up and how will it take if any previous day has negative values. it should check current and previous date along with role as well.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors