Urgent help needed - grid custom field calculation

Hello
I have a grid for customers, all other field is a custom field type, I use sql query to get sum(value) from mysql db.
I need to sum two fields (red), subtract them from (green) field and put the result in (yellow) field, so in my grid onRecord:
{result-yellow} = {field-green} - ({field1-red}+{field2-red});
The result is correct in the first row, unfortunately it will be the same on other rows, even in the grid total its the same number for the first row, how to solve this problem

please see attached image

Thanks in advance

Calc

Not sure why this is happening. Are you doing the calculations on the On Record event?
You can also do the calculations in the sql query. This way the calculations are done when the record is loaded

Yes, its in onRecord event.
all calculations in the grid records are sql (every custom field has sql query) except the yellow (result).
Thank you very much ‘Nico’

i think that building the sum groups the data so further use is not possible,
i would suggest to calculate the other fields in the same sql where you sum
i use views to make such calculations on the fly!

I ever faced this kind of bugs in OnRecord Event in Grid. I change the field name/ column name. For the name of the field, I use something that really different, such as field name abc and the other is def. And it worked well.