Possible to display certain field based on value?

I’ve got a price comparison app that I’m building and when displaying a list of products, I would like to show the price field that is the lowest.

I’ve created this dummy data type to illustrate a simple product that has a name and then three different prices (presumably from three different sources):
image

Would I need to create a 4th field and call it something like “Best Price” and behind the scenes have some type of workflow running that is always looking at the 3 prices and then updating the 4th field to the lowest value?

Or is there a way to dynamically pull the lowest price in the RG via a calcuation? If so, would that still allow the “products” to be sorted/searched by price (always defaulting to the price field with the lowest value)?

It might be a better idea to have a separate datatype for price, then have a list of prices on the product.

Then it’s simple to show the lowest price.

1 Like

Yup, what Adam said is one way to go, and FYI, this would work with the setup you are showing.

You won’t be able to sort by the lowest price, though, unless you have a field in the data type that is storing the lowest price.

Best…
Mike

1 Like

Ahhh yes, that makes more sense! Very helpful! So would Adam’s solution allow the user to sort by price? Or would an extra field storing the lowest price be the solution regardless?

1 Like

Unless Adam knows something I don’t (and it wouldn’t surprise me at all if he does), that solution wouldn’t allow you to sort by the lowest price in each product’s list of prices.

2 Likes

Yeah, as @mikeloc says, in order to sort by lowest price you’ll need to have a field for that directly on the product datatype.

The way I would do it is have a list of product_prices on the Product, AND a lowest price field on the Product as well.

Depending on exactly what you’re doing, I would automatically set the lowest price field to the be lowest of the product_price prices any time a new price is added to the product prices list.

That gives you the best of both worlds (easy to work with the price data without having to use complex conditionals, AND a quick sort on lowest price when you need it).

2 Likes

Absolutely love this. Thanks so much for sharing! Excuse my foggy brain, but in your head what would be the best approach to accomplish this? Let’s say once a day I update all the prices. What would be the most effeciate workflow to run to ensure that the “lowest_price” field is always displaying the lowest value inside the “product_prices” field?