I'm trying to recreate the following logic I create in SQL in Power Query. I'm tried doing it by grouping by the OrderNumber column, but I wasn't able to use a rank function or anything similar. I'm trying to keep the query folding enabled if I can.
SELECT * -- columns
FROM(
SELECT j.*,
rn = ROW_NUMBER() OVER(
PARTITION BY OrderNumber
ORDER BY LineNumber, DateReceived DESC, StatusName DESC
)
FROM [dbo].[Orders] j
) ord
WHERE
ord.rn = 1
Here's a sample of what I'm trying to achieve with this query. I want to rank each order by their LineNumber, in order to select only lowest LineNumber for each order, and in the case of a tie, I use the OrderStatus to determine a winner.
