This is almost certainly going to require VBA coding to achieve. Doing this by query would be incredibly tricky at best and totally impossible at worst because queries don't stop running in the middle of what they are doing (unless they throw an error of some type.) I'll spare you the rather boring technical reason of why queries behave that way until a later time.
However, your statement is not very clear in terms of design intent. From your description we don't know your data source and your intended data use or destination once you've done this computation. We can answer questions in the abstract sometimes, but we aren't psychic. We do need at least a little bit of detail to go on. Like, what is the OVERALL problem? What are you building here?
When starting with a database, my advice is usually that you would simulate the operation on paper to lay out what it is you want to do. The short form of my rule is, "If you can't do it on paper, you can't do it in Access." I.e. if you don't have a clear enough understanding of the goals so that you could simulate the process, you are not ready to use Access anyway. Remember, Access is dumber than a box of rocks. It is a tool, just like a power drill is a tool. The drill doesn't know where to make holes... you do. The drill just spins very fast and turns whatever is loaded to the chuck.
Don't take this as an insult, because it is not intended that way, but... You say "you are unsure" in your question. This is a sure sign that you don't (yet) know what you are doing. Time for some "skull sweat" to think through your intent. Stop thinking in code. Ask yourself what you would do by hand to achieve this desired result. Focus on the steps you need to perform to get from starting point A to ending point B. Then you have a shot at figuring this out well enough to implement something. This is also where you will need a particularly scarce commodity to help you... patience.
My late father-in-law was a carpenter. His rule was "Measure twice, cut once." For programming, the rule is "Design once, review twice, implement once."
Finally, since that is your first post, hello and welcome to the forum.