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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

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
Solution Sage
Solution Sage

Hello @Anonymous ,
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 @Anonymous 
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 @Anonymous 
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 @Anonymous 

Thanks @Kishore_KVN @bhanu_gautam for your inputs, @Anonymous 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
Solution Sage
Solution Sage

Hello @Anonymous ,
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!!

Anonymous
Not applicable

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

@Anonymous , 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






Anonymous
Not applicable

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.