I’m trying to populate a column with values from another table that have been filtered and then summed.
The screenshot shows 2 data sources:
a table called runTable has a column called totalSamples that I am trying to automatically populate
a query called getSamples loads a resource table called projects, shown in the bottom right.
To calculate the value of the totalSamples column in runTable, I’d like to use the string in the Run ID column in runTable to filter the getSamples output. Then in the resulting getSamples output, I’d like to sum the column called sample_number.
In this example, the totalSample column should fill to 50.
Should I be looking to transformers to accomplish this? Any help is much appreciated!
Welcome! Like most problems, there's a lot of ways to approach this and someone may have a more eloquent or efficient way of doing it, but I would approach this with JavaScript in the Value field of the totalSamples column. If I'm understanding correctly you're taking the ID from the runTable and trying to add all the sample_numbers from getSamples that have the same run number. I can't see the ID of the 'Run ID' from the table so replace that with the runID below, but paste this into the Value field of the totalSamples column and it should get your really close:
{{ _.sum(formatDataAsArray(getSamples.data).filter( x => x.run === currentSourceRow.runID).map(y => y.sample_number)) }}
If the dataset is large I'd consider joining your two tables in SQL and not doing any summing or mapping on the frontend, as they'll not scale very well. These approaches are fine for 15 rows though.