What's the right way to do multiple calculations on the same list?

I want to calculate Total ad cost of sales (Ad cost / Revenue)

I am getting this by calling sales per day from my database bounded by a time period (last 30 days etc)

So I get a list of sales per day for the last 30 days.

Right now I am doing this: “Do a search for sales per day:each items Ad Cost:sum / do a search for sales per day:each items Revenue:sum”

It seems silly that I have to search for the same list twice in the same expression. Is there a better way to do this?

Should I add a 1 pixel repeating group with the list of sales per day and just reference that?

FWIW: I can’t (rather, don’t want to) use a “state” because the data needs to update dynamically depending on what the user does on the page and I didn’t build it to use states - I want to avoid the workflows associated with updating states and want it to just update when the user changes dates or account etc the way a repeating group or expression does

There are two main reasons why you’d want to create a (variable) Group to store the search result

  1. You are referring the search result from more than one place
  2. You need to update the Search constraints dynamically

You are actually referring to the search result from more than one place, only that those references happen to be in the same expression, so it’s an edge case.

Those two searches aren’t actually happening twice as long as the constraints are equal. Bubble is smart enough to not search for the same thing twice, so the reason to create a (variable) Group here is purely based on maintainability rather than performance.

1 Like

Thanks for answering - getting clarity on the way bubble handles it is really great.

I think I will use the variable group anyway since I need to reference this list from multiple places throughout the dashboard.

Happy to help!

You can mark my answer as the solution so that others can find it more easily.

And if my answer has been of any help, a like is also appreciated :slight_smile: