Smart segment sorted by calculated value

hello.

assuming i was running a rails shop app that sells products.
i wanted to create a segment in products table that shows the most sold items. unfortunately i don’t have a column that shows how many times an item has been sold so i need to create a smart segment that counts how many times an item has been sold from the log table.

doing that is possible but i wanted to show the items in order from most sold to least and my SQL query does return them in that order but unfortunately when displayed they’re not in that order.

i would appreciate it if someone could help me with this. if it is even possible.

thanks

Hi @huss,

Welcome to Forest community.

A smart segment definition defines a where clause. This where clause is then used to fetch records. A where clause has no impact on the sort order in a SQL query.
I think our doc can be misleading about this fact, sorry. The order in the IN operator has no impact, as described by this documentation.

You can sort your smart-segment via the layout editor:
-click the pencil to go to edition mode
-click the wheel next to the collection to edit
-under the tab segment, select the sort you want.

Regards

1 Like