How to return sum of all values for specific numeric field in database table

I have a database table named “Investor Principals” with fields:

  • “Owner” (User type)
  • “Active Principal” (Number type)
  • “Parked Principal” (Number type)

I simply want to return the SUM of all of the “Active Principals” from the database table as a single value.

How can I do this?

Hi there, @francisburns… if I understand your post correctly, this expression should do the trick.

sum

Hope this helps.

Best…
Mike

1 Like

Hi @mikeloc,

Yes that is exactly what I needed. :slight_smile: ! Thanks!

I wonder can I ask you a further related question related to the same task.

In the same table, the “Owners” (User type) each have one or more “Roles” (where the “Roles” are a list of values from a “Role” Option Set).

The question is: How could I do the same database query and receive the sum of all values of “Active Principals” only for those “Owners” of a specific “Role”?

Thanks,

Francis

If I understand that question correctly, I believe you would need to use an advanced filter that looks something like this.

Keep in mind that advanced filters happen on the client side, so that expression could be a bit slow depending on how many things are being returned in the search and then filtered in the browser.

1 Like

Hi @mikeloc ,

Thanks again.

I am very new to Bubble. Could you please tell me how do I get to this “advanced filter”?

And if you don’t mind, could you also please tell me where I can learn about these search/database query options you are giving me? :slight_smile:

Kind regards,

Francis

When you are adding a constraint to the filter, the Advanced option is all the way at the bottom of the dropdown.

With regard to how you can learn about this stuff, have you completed the tutorials that Bubble offers? If you haven’t, I would suggest taking a step back and working through them because Bubble has a pretty steep learning curve, and if you don’t have a good understanding of the basics, you will almost certainly struggle on your journey.

1 Like