Sorting a reference column in a form view by the most used record?

Hello everyone,

I have a form view for adding a new record on the table TRANSACTIONS where there is a column TRANSACTIONS[transactionAccount] which is a reference of another table ACCOUNTS.

In the form view, the TRANSACTIONS[transactionAccount] column appears as a dropdown list.

I want to know if there is a way to display such list in a different order, by the โ€œmost usedโ€ accounts.

For instance, in the ACCOUNTS table, I was able to add a โ€œread-onlyโ€ virtual column [accountTransactionsCount] like this:

COUNT(
  SELECT(TRANSACTIONS[transactionKey],[transactionAccount]=[_THISROW].[accountId])
)

So this virtual column tells me the number of occurrences of the [accountId] in the TRANSACTIONS table ,and so, I can tell from that which ones are the accounts that are โ€œmost usedโ€.

I just donโ€™t know how I could use this ACCOUNTS[accountTransactionsCount] virtual column for sorting the dropdown list in the form view.

Would anyone know if this is possible and if so how? Thank you! Carlos

Solved Solved
0 9 1,251
1 ACCEPTED SOLUTION

Thank you Steve!

If anyone is having a similar issue than me, the problem was that in the second argument I was including the name of the table โ€œACCOUNTSโ€ which seems that is not needed (and it even was causing problems).

So, in the end, this is what I have, and now it works as expected!

ORDERBY(
  ACCOUNTS[accountId],
  [accountTransactionsCount],
  TRUE
)

View solution in original post

9 REPLIES 9
Top Labels in this Space