Help! How to sort rows by column and return a non keyed column

Kal
New Member

I have a table with JoinID (key); ProductID (ref); VendorID (ref) and Pref (Number from 1-10).
Iโ€™d like to return the VendorIDโ€™s according with the lowest Pref value first, but only of a certain ProductID.
Below works (sorts) but returns the key, I canโ€™t get the VendorID from it without losing the sorted order.
ORDERBY(SELECT(ProductVendorJoin[JoinID], [_THISROW].[ProductID] = [ProductID]), [Pref], FALSE)
Iโ€™d like something like below, but now Orderby canโ€™t find Pref as it is in the VendorID table.
ORDERBY(SELECT(ProductVendorJoin[VendorID], [_THISROW].[ProductID] = [ProductID]), [Pref], FALSE)
Iโ€™m probably missing something real small, but itโ€™s been hours. Please help if you can.

0 2 224
2 REPLIES 2

Steve
Platinum 4
Platinum 4

The only way Iโ€™m aware of to do what you want is to store the ordered JoinID values in an intermediate column (e.g., orderedJoinIDs), the dereference that list, like:

[orderedJoinIDs][VendorID]

See Constructing a List from a List Dereference here:

I can see how to do this in Google Sheets for example, but how can I create the orderedJoinIDs column in an SQL database, if I use my first statement:

That produces a list of VendorIDs, I can use Index with [_RowNumber] but that only works for the first product and is I believe bad practice.

Top Labels in this Space