Hi, all, I have this RG showing selected products, I’d like to calculate a Total from each row’s Subtotal.
I’ve been searching hours for tips on forum but haven’t been able to find an answer, some posts say if the inputs are editable, they can’t be calculated, is that true? My problem seems to be that Total field cannot even reference Subtotal fields’ values.
Here’s how I set up the fields:
step 1 - select product and add to custom state
step 2 - enter Qty and Subtotal field value changes by calculation of the 2
step 3 - Sum each row’s Subtotal (stuck here)
- the Total Field is outside of RG
- Subtotal fields cannot be referenced in workflow, either, tried adding to custom state list but couldn’t
Is there a way to do it without a plugin?
Thanks a lot
Hi, @cmarchan , thanks for the tip, but I still cannot refer to the Qty field that allows manual input.
Am I doing something wrong?
I don’t think you’re doing anything wrong per se, Bubble has this frustrating limitation of not being able to refer to elements inside cells of a RG from workflows triggered outside of the RG. The Orchestra plugin is usually helpful for this as it lets you loop through each cell in a repeating group.
You could do the following:
- Create custom state for the Total with default value zero.
- Se the Total field to use the custom state.
- Trigger a workflow any time the quantity input is updated (don’t need Orchestra for that). In this workflow, set the custom state to zero first because we’re going to recalculate it. Then trigger the Musicians in Orchestra (see plugin page for details) to loop through and in each iteration you’ll add the current cell’s subtotal to the custom state value. After this is done, you’ll have the correct total.
You could also do it without Orchestra:
- Set a custom state on the Qty field that’s current-value.
- Set a custom state for the Total and have that text reference it, just like above.
- Trigger a workflow whenever the Qty field input is updated, just like above. In this workflow:
- Calculate the new total with the formula: Total = (Input Qty’s value - current-state) x Price + Total
- Set the state current-value for Qty to the Input’s new value.
In this method you’re not summing the subtotals, you’re starting the total at zero and just adjusting the total whenever the user updates a Qty input.
For example:
The user has selected 2 products A and B with prices $40 and $50. Initially Total is 0 as all quantities start at 0. Then they update product A’s Qty to 2, and using the formula above:
New Total = (2 - 0) x $40 + 0 = $80
Then say they update B’s Qty to 4:
New Total = (4 - 0) x $50 + $80 = $280
Then say they realize they only need 3 B’s and update B’s Qty to 3:
New Total = (3 - 4) x $50 + $280 = $280 - $50 = $230
Let’s check our work, we have
2 A’s = 2 * $40 = $80
3 B’s = 3 * $50 = $150
Total = $80 + $150 = $230
The total will remain correct.
Hope that’s helpful.