The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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
Dt | Code | role | Val | New Val |
01-01-2025 | L1 | 1 | 30 | 30 |
01-01-2025 | L1 | 2 | -25 | 0 |
01-01-2025 | L1 | 3 | 40 | 15 |
01-02-2025 | L1 | 1 | 15 | 15 |
01-02-2025 | L1 | 2 | 0 | 0 |
01-02-2025 | L1 | 3 | -25 | 0 |
01-03-2025 | L1 | 1 | 30 | 5 |
01-03-2025 | L1 | 2 | -5 | 0 |
01-03-2025 | L1 | 3 | 65 | 60 |
01-04-2025 | L1 | 1 | 83 | 83 |
01-04-2025 | L1 | 2 | -20 | 0 |
01-04-2025 | L1 | 3 | 40 | 20 |
Solved! Go to Solution.
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:
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!!
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.
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
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.
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:
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.
@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)
Proud to be a Super User! |
|
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.