Reset Running Total if another field value of a previous record has a positive value

%3CLINGO-SUB%20id%3D%22lingo-sub-3018992%22%20slang%3D%22en-US%22%3EReset%20Running%20Total%20if%20another%20field%20value%20of%20a%20previous%20record%20has%20a%20positive%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3018992%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20running%20a%20query%20which%20has%20a%20Running%20Total%20field%20as%20below%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERunningTotal%3A%20(SELECT%20SUM(Total_On_Hand)%3CBR%20%2F%3EFROM%20Daily_Inventory_Report%3CBR%20%2F%3EWHERE%20T1.Shelf_Life_Date%20%26gt%3B%3D%20Shelf_Life_Date%3CBR%20%2F%3EAND%20T1.SKU_ID%20%3D%20SKU_ID)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20add%20a%20condition%20so%20that%20this%20running%20total%20stops%20and%20resets%20when%20the%20value%20of%20the%20previous%20'EORisk'%20field%20is%20%26gt%3B%3D0.%20See%20screenshot.%20The%20above%20expression%20works%20for%20all%20rows%20except%20the%20highlighted%20row.%20'RunningTotal'%20sums%20the%20amount%20of%20inventory%20on%20hand%20for%20a%20given%20batch.%20The%20'EORisk'%20field%20subtracts%20'Forecast_Usage'%20from%20'RunningTotal'%20to%20give%20us%20our%20E%26amp%3BO%20Risk.%20If%20this%20calculation%20is%20less%20than%20zero%20all%20runs%20fine.%20But%20if%20it%20is%20%26gt%3B%3D0%20as%20per%20circled%20example%20(340)%2C%20then%20I%20want%20the%20next%20running%20total%20to%20reset%2C%20i.e.%20circled%20example%20(5610)%20becomes%203870%2C%20which%20in%20turn%20would%20calculate%20-330%20in%20'EORisk'%20for%20that%20highlighted%20row.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20found%20a%20subquery%20which%20uses%20MAX%20to%20retrieve%20the%20value%20of%20a%20field%20from%20a%20previous%20record%20but%20not%20sure%20how%20this%20would%20fit%20into%20my%20running%20total%20query.%20Any%20help%20of%20this%20would%20be%20greatly%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3018992%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eaccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3021049%22%20slang%3D%22en-US%22%3ERe%3A%20Reset%20Running%20Total%20if%20another%20field%20value%20of%20a%20previous%20record%20has%20a%20positive%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3021049%22%20slang%3D%22en-US%22%3EAny%20chance%20of%20getting%20a%20sample%20accdb%20to%20work%20with.%20I%2C%20for%20one%2C%20often%20find%20it%20difficult%20to%20work%20with%20abstracted%20elements%20like%20the%20field%20shown%20and%20screenshots.%20It's%20quicker%20to%20have%20real%20data%20to%20work%20with.%20Sample%20data%20is%20fine%20if%20it%20reflects%20the%20structure%20and%20contents%20of%20the%20real%20data.%3C%2FLINGO-BODY%3E
Frequent Visitor

Hi there,

 

I am running a query which has a Running Total field as below;

 

RunningTotal: (SELECT SUM(Total_On_Hand)
FROM Daily_Inventory_Report
WHERE T1.Shelf_Life_Date >= Shelf_Life_Date
AND T1.SKU_ID = SKU_ID)

 

I want to add a condition so that this running total stops and resets when the value of the previous 'EORisk' field is >=0. See screenshot. The above expression works for all rows except the highlighted row. 'RunningTotal' sums the amount of inventory on hand for a given batch. The 'EORisk' field subtracts 'Forecast_Usage' from 'RunningTotal' to give us our E&O Risk. If this calculation is less than zero all runs fine. But if it is >=0 as per circled example (340), then I want the next running total to reset, i.e. circled example (5610) becomes 3870, which in turn would calculate -330 in 'EORisk' for that highlighted row.

 

I found a subquery which uses MAX to retrieve the value of a field from a previous record but not sure how this would fit into my running total query. Any help of this would be greatly appreciated.

 

Thanks!

2 Replies
Any chance of getting a sample accdb to work with. I, for one, often find it difficult to work with abstracted elements like the field shown and screenshots. It's quicker to have real data to work with. Sample data is fine if it reflects the structure and contents of the real data.