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 696
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

Thank you @Marc_Dillon ,

Iโ€™m just not sure how to use this ORDERBY() function so the drop-down list in the form view will be displayed in the order Iโ€™m expecting.

Could you please elaborate a bit more on how to use this fiction to achieve the result that Iโ€™m trying to get with the form view?

Hello @Marc_Dillon I tried to follow the advice on the page you had linked, but it didnโ€™t seem to have worked.

This is what I did:

On the TRANSACTIONS table, I went to edit the [transactionAccount] column which is a reference of the ACCOUNTS table (which has the [accountId] column).

Then, I added this formula under the โ€œData Validity โ†’ Valid Ifโ€ field of the TRANSACTIONS[transactionAccount] column:

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

I saved the changes, but when I open the form view to add a new transaction, and I click on the Accounts field, the dropdown still displays in the order the accounts are in the source spreadsheet (not even in alphabetical order).

What would I be missing?

To better show the issue that Iโ€™m having, I had created a virtual column which I called ACCOUNTS[accountLongName] and that Iโ€™m using as the โ€œLabelโ€ which has this formula:

[_RowNumber]&" - "&[accountName]&" ("&[accountTransactionsCount]&")"

So, as you can see from the screenshot below, the dropdownlist in the form view still is ordered by the [_RowNumber] instead of the [accountTransactionsCount]

My case is quite similar to @Diogenes_ASBL_VZW case in here:

Iโ€™ve tried using the ORDERBY as @Grant_Stead had suggested in there, in this way:

On the column TRANSACTIONS[transactionAccount], which is of type โ€œRefโ€ to the ACCOUNTS table, Iโ€™ve added this formula under the โ€œData Validity โ†’ Valid Ifโ€ formula field:

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

But Iโ€™m still not getting the result that Iโ€™m expecting.

Iโ€™m sure there might be something simple that Iโ€™m missing in the whole process, but Iโ€™m not able to figure out what it isโ€ฆ

Your ORDERBY() expression is wrong. Please review the docs and correct the second argument, ACCOUNTS[accountTransactionsCount].

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
)

Well done!

Top Labels in this Space