Sort by count within each group

I’m getting started with Coda and enjoying it, and I’m glad to see how helpful this community is.

Is there a way to sort a tabular view based on the count of items within each group?

For example, below I would like to be able to sort the “Orders by Customer” by the count of orders by each Customer.

This seems like it’s probably simple to do in Coda, but the sorting options for Customer use the value of the text in the Customer field, not the count.

Thanks,
Wallace

Hey @Wallace_White welcome to the community! You’re right there are some legends on here :slight_smile:

OK so I think your issue can be solved by adding another column to your Orders table which counts the number of orders by customer on each line:

thisTable.Filter(Customer=thisRow.Customer).Count()

Then you can sort the grouping by that column.

The cool thing about the community is you’ll probably get a few more (better?) answers too! Good luck.

Thanks very much, Johg. That makes sense but, unfortunately, didn’t have the intended effect. When the view is using the grouping, sorting on my new Order count for customer field doesn’t actually sort the grouped rows:

If I turn off the grouping, then of course the sorting works as intended.

Any other ideas?

Change the grouping to be by Order Count for customer and then set grouping to sort ascending or descending. It won’t be as ‘nice’ as having the Customer name be the sort/group, but it will accomplish what you are trying to do.

Then if two Customers had the same Order count for customer, their rows would be falsely grouped together, but I used that basic idea in the following approach that concatenates the Customer name within the group label:

It’s a little awkward to embed the count in that field but it’s decent.

Thanks, Johg.

Ah you got it! Yes I agree that the Grouping system can be finessed … this situation where you want to sort/group by one column but want to present / show a different will probably be eventually reconciled. I have many cases where I want to sort by a date (or a count) but want to show a person’s name. But! Atleast you can get the effect you’re going for and be happily surprised when Coda eventually releases the feature.

Right. It’s good there are a few ways of doing things. I am drawn to how Coda seems to be able to cleanly do certain things that are awkward to do in Excel, but I can also appreciate that as a backup Coda lets you build your own things, like Excel.

I also realized that your suggestion of grouping by the count of orders does work so long as you use a second grouping by Customer. Then you don’t need the field with the concatenation. I think that’s better.

Thanks again, Johg!