Forum Academy Marketplace Showcase Pricing Features

Workflow to compare two inputs and only use the larger one

Is there a way to compare two inputs (with additional math), then use only the larger result to populate a field?

Here is an example:

I have a field called “Larger”

I have two inputs “A” and “B”

In my workflow I want to populate field “Larger” with (A * 2) or (B * 5), whichever is greater.

Can this be done?

I would do a visual solution:

Make 2 fields of Larger with each you put in a condition and display whichever one meets the condition you want and hide it when it doesn’t.

Sure thing.

One way to do that would be that you need to create a workflow that will consist of the following steps:

  1. First step in your workflow to populate the field “Larger” with Input A*2 value
  2. Second step in your workflow to populate the field “Larger” with Input B*5 value

Set conditions for both steps to only run if the result of the math is what you need (A2>B5 or vice versa for the appropriate step).

Sometimes Bubble math behaves funny, so you may need to use setStates to store the results of the A2 and B5 operations, but I believe you get the idea.

Here’s the link to the WF conditions feature description and discussion:

Vlad.

GM at Bubblewits - Bubble Certified Partner


http://bubblestore.io – a place to buy Bubble templates for landing pages, e-commerce, workflows, APIs etc.
http://iambubble.com - one page Bubble demo
http://builtonbubble.com - Collection of apps built on Bubble

Using the max function on a number should be the simplest option.

Thanks @john3 and @vladlarin. Both should be easy enough to apply.

@Scott, I tried to experiment with the max and it didn’t work. The reference manual didn’t help. I tried to put in A’s value * 2 <- max -> B’s value * 5. That didn’t work. I’m thinking that I didn’t use it correctly. Do you put <- max -> between two input values? That seemed to be the only place I was able to put it.

Since Bubble processes values from left to right, it will interpret that statement as max(A’s value * 2, B’s value), and omit the factor of 5. To get around this, put the inputs in a group whose data are numbers that evaluate A * 2, and B * 5, respectively. Then feed the group’s numbers into the max function.

Thanks all!

I made a hybrid change incorporating all of your suggestions and created two custom states instead of one long math formula.

CS1 = A * 2

CS2 = B * 5

Then the max worked!

CS1 <- max -> CS2

Worked like a charm! It always used the larger of the two states.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.