Sort by Calculated Value

Without knowing your particular setup, I can’t offer specific advice. Perhaps you could include a link to your Editor.

Generally speaking, I think the key is to have another Datatype that is linked to your “things” so you can sort by a calculated value that is stored in the database (like I did with the “Line Item” datatype). This datatype acts as the variable based on the user inputs.

Rather than referencing the extracted list, I think you need to reference this special Datatype (i.e. line item) that is specific to the order or user, depending on your setup, and make the calculation based on some action taken by the user.

Thank you Robert, I will share an example in bubble editor in the coming days to make the situation clear. Really appreciate it!

Here’s a link to the example.

User enters a color. Colors are displayed in the repeating group. As User increases or reduces votes, Expression calculates trend factor in real time (because there is a time component; trend will be stale if it is saved to the database at the time the user votes). The goal is to sort the repeating group by the trend factor. How do I implement this?

@chrismchewols You could have it run a workflow on page load that recalculates it to the database. I’ve done this in the example. Check it out!

Note: I also had to change it from a text field to an input field so it can read/save to the database properly. Unfortunately, the input field will not display out to four digits properly. (this may be a bug). So I brought back the text field as a display only, and hid the input field.

Ah, thank you Robert. I like the set up. Issue is, on page load, “trend factor = This Color’s trend factor” is not updating the database with the output of the Expression. I added a Sort Button with the same instruction for good measure. I also displayed the trend factor in the database and the trend factor output of Expression to be sure.

1 Like

This seems like a good option, but doesn’t support a to-many relationship.
If a Contact stores a list of Transactions, and you need to display the Contacts ordered by the number of Transactions, this is surprisingly hard to pull off in Bubble.

This is why I added a SORT action to List Shifter. You can do any type of mapped sort. (List Shifter can of course also help you do things like build lists of values to sort by.)

3 Likes

Ahhh thanks! I heard about List Shifter previously but had forgotten about it :slight_smile:

Hi @mikepost80, can you tell me if List Shifter helped you in this particular case ?
I have exactly the same problem :slight_smile:

I installed List Shifter and Repeating Group and I can’t see my calculated value…

Hi Keith, do you by chance have an example of how use your SORT (list shifter) to sort by a calculated field? thank you

3 Likes

Hey Keith, can you explain this further about sorting by a calculated value? Or if you have a link to an example?

My particular example, I need to sort by Thing’s Date + days [number field of days] - Current date/time:formatted as days and sort by the resulting number.

This guy has a great short video on how to use List Shifter’s SORT action to sort on something you couldn’t usually sort on in vanilla Bubble:

Once you understand that, all you have to do @tylerboodman is generate that list of numbers and use that in the SORT action.

@tylerboodman further to my previous response, you’ll be interested in my NEXT video doc/demo about Floppy as I’ll be showing the List Math action, which makes computations on a list of numbers a snap.

I had meant to point to the video I did about sorting by calculated values / sorting by the count (number of items in) of some Thing’s list-type field, but had forgotten to do so. Here it is:

Originally shared here in the Floppy thread.

1 Like