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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RDinho
New Member

Calculate value in a row based on a value in the previous row

Hello everyone,

 

I have a table that looks like this:

 

RDinho_0-1675256468463.png

 

This table is currently filtered on article (first column). Within this filter I want to have a measure which calculates the inventory based on the required quantity of each row. The inventory is currently 17.992 so, based on the first row in the table, the new inventory number should be 17.992 - 30.000 = -12.008. So far so good. However, the calculated inventory on the second row should be -12.008 - 84.000 = -96.008. What it does now, is look back at the at the starting inventory (17.992) and use that to calculate the new value, instead of using the calculated inventory from the new row. The first 4 rows should look like this (ignore the top most row seeing I've put the inventory there for better understanding):

RDinho_1-1675256806680.png

I'm currently using the following measure to calculate the inventory:
 
CALCULATE(
SUM(Articles[Inventory])-SUM(Articlelines[Required Quantity]),
FILTER(ALL(Articlelines),
Articlelines
[Startdate] >= SELECTEDVALUE(Articlelines[Startdate]) &&
Articlelines[Startdate]
 <= SELECTEDVALUE(Articlelines[Startdate]) &&
Articlelines
[Status] = "Open" &&
Articlelines
[Artikelnummer] = SELECTEDVALUE(Artikelregels[Artikelnummer])))

I imagine the mistake is somewhere in the first line because I'm using the SUM of the inventory number. However, I don't know how to get around this. Any help would be much appreciated!
1 REPLY 1
v-xinruzhu-msft
Community Support
Community Support

Hi @RDinho 

You can refer to the following example

 

Measure=
var _suminven=17992
return CALCULATE(_suminven-SUM(Articlelines[Required Quantity]),FILTER(ALL(Articlelines),
Articlelines[Startdate] <= SELECTEDVALUE(Articlelines[Startdate]) &&Articlelines[Status] = "Open" &&Articlelines[Artikelnummer] = SELECTEDVALUE(Artikelregels[Artikelnummer])))

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors