Ranking


๐Ÿ“Š Ranking Function (HGrid247)

๐Ÿ” Definition

Ranking is a function to rank data that has been:
  1. Grouped (GroupBy)
  2. Sorted (ascending / descending)
โžก๏ธ Rank is determined based on the sorting result field

โš™๏ธ Parameter

๐ŸŽฏ Max Rank which will be passed on to the next assembly

๐Ÿ“Œ If not filled in:

โžก๏ธ All data remains out (unrestricted)

๐Ÿ“ฅ Input & ๐Ÿ“ค Output

Input Output

๐Ÿง  How it works

For example, the data is already sorted:
    category	views
    ---------------------
    A           90
    A           100
    A           80
โžก๏ธ After Ranking:
    category	views	ranking
    --------------------------
    A           100	1
    A           90	2
    A           80	3

๐Ÿงช Case Example (Top N per Group)

๐ŸŽฏ Case Study:

Displays the Top 2 videos with the most views per category ๐Ÿ”„ Workflow
  1. Group By โ†’ category
  2. Sort โ†’ views DESC
  3. Ranking (Max Rank = 2) ๐Ÿ“Š Results:
        category	video	views	ranking
        -----------------------------------
        Music	V1	1000	1
        Music	V2	900	2
        Music	V3	800	โŒ (not out)
    

    ๐Ÿ”ฅ Important Insights

    1. Ranking requires sorting

    Without sorting:
    โžก๏ธ ranking becomes meaningless

    2. Used for Top-N

    Common use cases:
    • Top 10 best-selling products
    • Top 5 video trending
    • Top customer per region