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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
matteomatilde
Frequent Visitor

Iterate an operation between rows

Hi everyone.

I've got a table with the following columns:

  • Item ID
  • Date
  • Warehouse ID
  • Stock quantity
  • Unitary cost of each item
  • Stock value (for each item)
  • Moved quantity (for sales)

matteomatilde_0-1622575051293.png

 

I want to create another column that makes the subtraction between the quantity in stock (4th column) and the moved quantity (last column), for each item, warehouse and date. Do you know how to do it?

For example, for the second row I'd like to obtain the value 788,07 (817,31-29,24).

 

Many thanks.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@matteomatilde 

I am not sure if I understood it correctly, you can add a column as follows:

New Column = IF( [Quantita_movimentata] <> Blank() , [Quantita_in_Stock]-[Quantita_movimentata])


 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@matteomatilde 

I am not sure if I understood it correctly, you can add a column as follows:

New Column = IF( [Quantita_movimentata] <> Blank() , [Quantita_in_Stock]-[Quantita_movimentata])


 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you.

Greg_Deckler
Community Champion
Community Champion

@matteomatilde See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.