forked from KiaraGrouwstra/pquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.RankDense.pq
More file actions
19 lines (16 loc) · 791 Bytes
/
List.RankDense.pq
File metadata and controls
19 lines (16 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
//Ranks an input value in a series (ascendingly or descendingly). Removes duplicates to rank only unique values.
//Usage:
List.RankDense = Load("List.RankDense"),
List.RankDense("B",{"A","A","B","C"})
//Result: 3
*/
//Originally written by Colin Banfield: http://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),
DistinctSeries = List.Distinct(SortedSeries),
RankDense = List.PositionOf(DistinctSeries,inputValue)+1
in
RankDense