The first is to use an advanced filter on the returned search results. That way you can easily filter the results by This BAGS's TotalStock < This BAGS's Monthly Sales.
Note that, unlike search constraints, filtering data is done client-side, so if the dataset is large it might not be good performance wise. But if you narrow your initial search as much as possible, and use Privacy rules to limit the data, it may not be too much of an issue.
The second way would be to add an additional field on the BAGS datatype to record the difference between the total stock and monthly sales, and then you can simply search for items where that field value is negative. It will be much faster (especially with a lot of data) but will require some extra workflow steps to set the data.
You can’t do field-to-field comparisons on constraints. As Adam suggested use an Advanced filter if you know your data set is never going to get very large. Advanced filters work client-side so every record in the table that’s not limited by a constraint is retrieved and filtered client-side which is very inefficient on anything other than maximum couple hundred records.
It’s been my experience with Bubble that it’s best to optimise for reads (searches) over writes which often means you prioritise performance over clean database design Therefore de-normalising the database to have duplicated or calculated fields that help optimise speed is the way to go. Therefore I would echo Adam in having a single field that contains the calculation and have a constraint that simply checks for < 0, > 0 etc. You’ll have to update that field whenever necessary but you’ll likely be updating it a lot less often than you’re querying it.
It’s part of the expression builder. Click in your expression (Search for BAG) and select the :filter operator. Then you can select the Advanced option, which lets you write a filter expression that will let you examine the properties of each item.
Ok great found it, I guess I can see now the advanced filter being more slow than adding that extra field as the search brings many more results that then get subsequently filtered where with the extra filed the results come straight away and they do not need to get further filtered…