Rank the rows in the table using the input column. Begins with 1. Identical values are assigned identical rank. Defaults to sort Ascending.
Rank(<column>,<direction ”asc” | “desc”>)
column (required) The column used to order the table.
direction (optional) The direction to sort the input column. Enter is “asc” to sort ascending and “desc” to sort descending. Default sort is ascending.
NOTE: Rows which sort identically are ranked identically, with gaps inserted into the sequence to compensate. For example: if the input has “Anne”, “Jane”, “Jane” and “Pari”, they would be ranked 1, 2, 2 and 4.
Rank([Population by State])
- This will assign the state with the smallest population rank 1, the second smallest population will be assigned rank 2 and so on.
Rank([Population by State], “desc”)
- This will rank the state with largest population as rank 1, the second smallest populations will be assigned rank 2, and so on.
Rank([COUNTY – Count])
More About Window Functions
For most Window Functions, the results are dependent on how the rows within the window are sorted. Many Window Functions will only work properly if the table is uniquely sorted by a column in the same “window” as the Window Function. To ensure that there is a unique sort order without any duplicate values, it is often useful to use multi-column sorting criteria to clearly define how to handle duplicate values.
The complexity of Window Functions makes them a little harder to use, but they are also a very powerful tool.
Cumulative Window Functions
Cumulative Window Functions are aggregate functions that apply to all of the rows up-to and including the current row.
The window that Cumulative Window Functions are applied in must be uniquely sorted for the function to work properly.
Moving Window Functions
Moving Window Functions are aggregate functions which apply to a “window” bracketing the current row. A common moving Window Function is a “moving average”.
The window is specified as a certain number of rows above and below the current row, constrained by the grouping.
The window that Moving Window Functions are applied in must be uniquely sorted for the function to work properly.
Shifting Window Functions
Shifting Window functions either shift the values in a column or repeat a specified value. The functions are useful when calculating month over month data.
The window that Shifting Window Functions are applied in must be uniquely sorted for the function to work properly.
Ranking Window Functions
Ranking Window Functions apply a rank to each row based on the criteria in a row provided to the function.
Ranking functions are not dependent on the sort order of the rows in the window it is applied in.