Unclear from the data but it seems you have designed a query, then you are running the query and getting the results, and THEN attempting to create calculations from it.
If that’s the case, just redesign the query. Add extra columns with the calculations already included. You aren’t limited in designing a query to only pulling existing columns from your database; you can create columns “on the fly” from the data in the other columns, and the extra columns you design will be generated as part of the query results. (You don’t even have to have them visible—you can just have them used for criteria.) Queries are very flexible.
Have a look at Chapter 5 of this PDF: https://wiki.documentfoundation.org/images/e/e8/BH40-BaseHandbook.pdf