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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Dvayro
Frequent Visitor

PQ: Row calculation based on previous row calculation | how to loop variable in PQ?

Hi,

I'm trying to calculate inventory usage dates based on the demand and expiry.
This allows us to show what inventory will go to waste based on current demand (allowing time to push sales deals or warn finance.)

This works fine in Excel, but I'm struggling to move it to Power Query because I need to reference the cell above. The usual index-merge technique will not work here as the row needs to be calculated based on the calculation of the previous row.


If I were to write this in VBA i would loop through each row, holding the previous row 'stockcompletiondate' in a variable.

Is this functionality available in Power Query? Is there another workaround I should explore?
Excel mock-up below; everything links back to 'stockcompletiondate'

Dvayro_0-1715640263660.png

Dvayro_1-1715640268485.png

(data changed between screenshots to show more examples)


Edit:
Table of sample data used in the above example.

SiteProductQTYSLEDSameSiteAndSku
1A10012/05/2024FALSE
1A5317/05/2024TRUE
1A8021/05/2024TRUE
1b100025/05/2024FALSE
1b4022/06/2024TRUE
2 REPLIES 2
lbendlin
Super User
Super User

Use List.Accumulate.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Sample data added.

List.Accumulate looks very promising.
I'm unsure how I would work with the multiple columns; I thought that lists are single column. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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