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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors