Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
VidyaSagarMalla
New Member

Creating Dense Ranks for Multiple Categories using M Query or Dax

Hello All,

I am trying to figure how the acheive the Dense Ranks for the below sample data. I was able to get the Rank right for category level per Year but when i am comibing for other columns ranks reuslts are NOT coming right. 

 

Expression used in M : = Table.Group(#"Removed Columns", {"Category","Years"}, {{"All", each Table.AddRankColumn(_,"Fixed Rank",{"Price",Order.Ascending},[RankKind = RankKind.Dense])}})

 

I would love to see whats the best approach to get the below result. Thanks in Advance for looking into this.

 

Actual DataTransformation Columns in Power BI
IndexClassCategroyProductYear Price Product Rank Per YearRank by Category Per YearRank by  Class Per YearRank by Index Per Year
ActiveEquityFruitsApple Gala2022 $                1.001121
ActiveEquityFruitsApple Pink2022 $                2.002121
ActiveEquityFruitsGrapes2022 $                3.003121
ActiveEquityVegCarrots2022 $                2.001221
ActiveEquityVegonions2022 $                3.002221
ActiveEquityVegBrocli2022 $                4.003221
ActiveFixed IncomeBeveragesPepsi2022 $                3.001311
ActiveFixed IncomeBeveragesDew2022 $                5.002311
ActiveFixed IncomeBeveragescoke2022 $                6.003311
1 ACCEPTED SOLUTION
v-achippa
Community Support
Community Support

Hi @VidyaSagarMalla,

 

Thank you for reaching out to Microsoft Fabric Community.

 

The power query method using Table.AddRankColumn only works per one grouping at a time. So if you want multiple dense rank columns we have to repeat the grouping and ranking logic separately for each combination. So use DAX calculated columns in power bi.

 

Rank by Category Per Year =

RANKX(

    FILTER('YourTable',

        'YourTable'[Year] = EARLIER('YourTable'[Year]) &&

        'YourTable'[Categroy] = EARLIER('YourTable'[Categroy])

    ),

    'YourTable'[Price], ,

    ASC,

    DENSE

)

 

You can simply apply similar formulas for other combinations like Product, Class, and Index.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

View solution in original post

6 REPLIES 6
techies
Super User
Super User

Hi @VidyaSagarMalla you can add measures like this

 

techies_0-1747890270227.png

 

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
v-achippa
Community Support
Community Support

Hi @VidyaSagarMalla,

 

Thank you for reaching out to Microsoft Fabric Community.

 

The power query method using Table.AddRankColumn only works per one grouping at a time. So if you want multiple dense rank columns we have to repeat the grouping and ranking logic separately for each combination. So use DAX calculated columns in power bi.

 

Rank by Category Per Year =

RANKX(

    FILTER('YourTable',

        'YourTable'[Year] = EARLIER('YourTable'[Year]) &&

        'YourTable'[Categroy] = EARLIER('YourTable'[Categroy])

    ),

    'YourTable'[Price], ,

    ASC,

    DENSE

)

 

You can simply apply similar formulas for other combinations like Product, Class, and Index.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

Hi @VidyaSagarMalla,

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution I have provided for the issue worked? or let us know if you need any further assistance.
If my response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

Ashish_Excel
Super User
Super User

Hi,

Would you be OK with a measure based solution?

VidyaSagarMalla
New Member

Thank for looking into this @pankajnamekar25 . But looks like you have provided the same query from my question.  

pankajnamekar25
Super User
Super User

Hello @VidyaSagarMalla 

You can try for this in PQ

But I will suggest use DAX measure

 

Table.Group(#"Previous Step", {"Category","Year"}, {

    {"All", each Table.AddRankColumn(_, "CategoryYearRank", {"Price", Order.Ascending}, [RankKind = RankKind.Dense])}

})

Thanks,
 Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.