Is there a way to create 1 database item for the sum product of 10,000+ results from an API request?

Hi,

Basically, I make an API request and it returns over 10,000 results. Let’s say this for every major city in America and I want to create a weighted average of each city’s income to get a total income for America.

Each result from the API request has 2 parameters: income of each city and population. I simply want each city’s income * its population (weighted average) and to get the sum of this weighted average for all 10,000+ cities.

However, I only want to know the sum of America’s average income based on the weighted average of each city (1 line) and not create 10,000 different lines which is 1 for each city, then do the sum of that.

Is there a way to do this in a single line before creating a line in the DB? Any code suggestions maybe in the API connector?

Thanks!

1 Like

Clear instructions are located here ^^^^^

1 Like

Yes…dynamic expression operators for average or use sum operator with division operator and count operator

1 Like

Not sure, just trying to help out.

Is it not possible to have that API call be an action and then in the workflow (I would do backend workflow) do computations and aggregation on that step where you retrieved the API data? In that case you might be able to use that result in a next workflow step to make a new thing

Another solution might be something as Supabase which can do the call, run any function and automatically provides an API for that function for you to call in Bubble.

1 Like

The dynamic expression operator will take the aggregate of all of the results and I need each to be weighted by each specific line. E.g. each cities population * income and not the sum of all cities * sum of all income.

I tried to have it but it will still need to make several calls in one… Supabase may be the solution I can check it out!

Did you find a way to make the sum product of two lists?