RankKind.Dense

Updated on

RankKind.Dense (1) is an enumeration that specifies the type of ranking. It is a member of the RankKind.Type and indicates that items which compare as equal receive the same ranking number and the next item is numbered consecutively with no gap. This ranking method guarantees a ranking with consecutive numbers where a rank can appear multiple times.

Examples

Imagine you have a dataset called Source with the following setup:

Source table as dataset for RankKind.Type

You can rank this data using the Table.AddRankColumn function. Below examples rank the data based on the revenue amount. The rank numbers can have duplicates, but there are no gaps in between the numbers.

= Table.AddRankColumn( 
    Source,
    "Revenue Asc",
    { "Revenue", Order.Ascending },   // Sort column in Ascending order
    [ RankKind = RankKind.Dense ]
 )

= Table.AddRankColumn( 
    Source,
    "Revenue Desc",
    { "Revenue", Order.Descending },  // Sort column in Descending order
    [ RankKind = RankKind.Dense ]
 )
Using Table.AddRank with RankKind.Dense in Ascending and Descending Sort Order

To make this ranking unique, you can provide provide multiple columns in the comparison criteria. Alternatively you can make use of RankKind.Ordinal.

= Table.AddRankColumn( 
    Source,
    "Revenue Asc",
    { { "Revenue", Order.Descending }, {"CustomerID", Order.Ascending } },
    [ RankKind = RankKind.Dense ]
 )

= Table.AddRankColumn( 
    Source,
    "Revenue Desc",
    { { "Revenue", Order.Descending }, {"CustomerID", Order.Ascending } },
    [ RankKind = RankKind.Dense ]
 )
Using Table.AddRankColumn with RankKind.Dense and multiple sorting columns

Other related enumerations are:

Applies to

Here’s a list of functions that work with RankKind.Type:

Contribute » | Contributors: Rick de Groot