The issue you’re experiencing with AppSheet could stem from how the column [Related Orders] is set up or how [FarmingtonQty] is structured within that related table. Here’s a checklist and solution to debug and fix this:
- Check the Column References
Ensure that [Related Orders] is a proper ref list column that references a related table, just like [Related POs]. If [Related Orders] is not properly set up, the SELECT function won’t retrieve the desired values.
Confirm that [FarmingtonQty] exists in the related table and has the correct data type (e.g., a number).
- Ensure Consistent Column Names
Verify that [Product] exists in both the current table and the related table being referenced by [Related Orders].
Check if there are any typos or mismatches in column names.
- Debugging Your Formula
Here’s how you can systematically test and isolate the issue:
a. Simplify the SELECT Statement
Run this SELECT statement independently to see if it retrieves the expected list of values:
SELECT([Related Orders][FarmingtonQty], TRUE)
This should return all the [FarmingtonQty] values from [Related Orders]. If it doesn’t, there’s an issue with the [Related Orders] setup.
b. Test the Conditional Logic
If the above works, add your condition back in:
SELECT([Related Orders][FarmingtonQty], [Product] = [_THISROW].[Product])
Check if the condition properly filters the results.
- Compare with the Working Formula
Look at [Related POs] and [Farmington]:
If [Related POs] works, it means [Farmington] and [Product] are correctly aligned. Compare this with [Related Orders] to ensure that [FarmingtonQty] and [Product] are similarly aligned.
- Solution
If all else fails, you can debug further using Virtual Columns to see intermediate results:
Create a Virtual Column to calculate the SELECT statement output:
SELECT([Related Orders][FarmingtonQty], [Product] = [_THISROW].[Product])
Use this Virtual Column in the SUM function to simplify debugging.
Revised Formula Example
If everything is correctly set up, your formula should look like this:
SUM(
SELECT(
[Related Orders][FarmingtonQty],
[Product] = [_THISROW].[Product]
)
)