Forum Discussion

Dvayro's avatar
Dvayro
Frequent Visitor
2 years ago

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'

(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