How to select the closest Data Type record to a target value?

Hi everyone,

I’m trying to build a simple recommendation feature and I’m stuck on the formula.

What I have:

  • Current health points = 50

  • Target points = 120

  • A Data Type called ConnectionType with a number field Base Points. It currently has these records:

    • Message → 30

    • Call → 60

    • In-Person → 120

    • Visit → 180

Goal:
I want to automatically select one record from the ConnectionType Data Type that, when added to the current points (50), gets as close as possible to the target (120).

In the example above, adding “Call” (60) gives 110 — which is the closest to 120.

Question:
What is the cleanest way in Bubble to do this?

I need a formula (or workflow) that:

  1. Looks at all ConnectionType records

  2. Calculates (current health + Base Points) for each

  3. Finds the one with the smallest difference to the target (120)

  4. Returns that specific ConnectionType record

Any help or example would be greatly appreciated!
Thank you!

1 Like