Hi all,

I totally get the logic I need to apply here and would be able to code it in half an hour using python or whatever but I'm struggling putting it into PowerQuery.

I need to do the following, please see my data here:

OpeningUnitRate is actually the column i need to calculate, it's just for better reading that it is already here in this case. It resembles the initial unit rate (which I got for some months).

I need:

UnitRate=

If OpeningUnitRate<>0 then

OpeningUnitRate

else

InventoryFromOpening(GroupIndex-1)***UnitRate**+ (I need the previous result of the column i'm calculating!)

InventoryFromPurchases(GroupIndex-1)*PurchasePrice(GroupIndex-1) (I have the PurchasePrice)

/

ClosingStock(GroupIndex-1) (I have the closingStock)

Thanks for your help!