forked from KiaraGrouwstra/pquery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
List.RankEqual.pq
17 lines (15 loc) · 723 Bytes
/
List.RankEqual.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
//Ranks an input value in a series (ascendingly or descendingly). Does not filter out duplicates.
//Usage:
List.RankEqual = Load("List.RankEqual"),
List.RankEqual("B",{"A","A","B","C"})
//Result: 3
*/
//Originally written by Colin Banfield: http:https://social.technet.microsoft.com/Forums/en-US/973e9381-ff46-4756-a071-88bb4c2105e4/pushing-more-calcs-to-power-query-replacing-dax-rankx
(inputValue as any, inputSeries as list, optional orderDescending as nullable logical) as number =>
let
order = if orderDescending or orderDescending = null then Order.Descending else Order.Ascending,
SortedSeries = List.Sort(inputSeries, order),
RankEqual = List.PositionOf(SortedSeries,inputValue)+1
in
RankEqual