Hi there, I have a question about setting up a running total or count in an access query. I know this isn't the most efficient way to run things, but I trying it anyways, because it could automate a manual process for me.
A little background, I have a Monthly Production table (this is the base dataset, see 'Monthly Production Table Fields' image which is attached) which stores monthly production data for a number of wells. I have built a series of queries which pick the peak production rate in the first X months (user defined with a prompt) for each well and then normalizes that data, or rather it takes the monthly production from that month forward and reports it for all of the wells in the Monthly production table. The end result or query ( PBOE_XMo_Norm_Prod ) is shown in the attached image 'Query Results'. The problem is that the producing month starts at whatever is the peak month for each well, in the attached image it is month 4.
What I want to do is ad a running count that starts at 1 and counts each month consecutively but then resets to 1 when the well or category changes. I've done a bunch of research, but I can't seem to get the right results. I tried using a DSum initially as that was what I could find the most examples of. Regardless, what I seem to constantly get is a count or a sum of all the records in that field (in the example: Liquids) in the original Monthly Production Table. Any tips on what to do? Is it because I am prompting for data in the first query? Please advise, I've attached screenshots of some of the DB as well as the SQL text. Any advice or suggestion is appreciated.
Thanks,
SQL:
SELECT PBOE_XMo_Norm_Prod.Entity AS EntityID, PBOE_XMo_Norm_Prod.Prod_Mo AS NormMo, PBOE_XMo_Norm_Prod.Liquid, DCount("[Monthly Production].[Liquid]","[monthly production]","[monthly production].[Producing Month]=" & [NormMo] And "[monthly production].[entity]='" & [EntityID] & "'") AS Expr1
FROM PBOE_XMo_Norm_Prod;