Explanation:
To calculate the ranking shown in the Rank field, you need to use the RANK_UNIQUE function, which returns the unique rank of each value in a partition. You need to specify the expression as SUM([Sales]), which calculates the total sales for each product. You also need to specify the order as descending, which means that the highest sales will have the lowest rank. Finally, you need to specify the restart as every [Category], which means that the ranking will reset for each category.
Reference:
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm
https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_lod_rank.htm