How to sum repeated input values inside a RG?

Guys, I would like some help to try to solve this problem.

Well, imagine that a table (Table 1) has a list of compound formulas. There are many, but we will only consider Compound X and Compound Y for this example.

For compound X, we have the following formula:
50% of Element A
50% of Element B

For compound Y, we have:
50% of Element A
50% of Element C

However, element C is made up of 50% of Element A + 50% of Element B, so the final formula for Compound Y would be:
50% of Element A
25% of Element A
25% of Element B

This is:
75% of Element A
25% of Element B

The formulas for the Compounds (Table 1) are immutable. What can change is the composition of each Element, depending on the manufacturer. Therefore, Table 2 has the constitution of each Element, of each manufacturer. In this way, we can use Table 1 in conjunction with Table 2 to recalculate the final formula.

My question is, what would be the best way to do this?

Currently I’ve been trying to use an RG to search for the original formula. Through the Elements of the original formula I search, in a new RG, for a correspondence to each element and its constitution. However, I couldn’t think of a way to be able to sum the values ​​of the elements that are repeated, generating the correct percentage of each element in the final formula. Any idea?

Thx!