This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
I am trying to rank within a group in python. I know how to do this outside of python in powerBI, and also how to do it in python but the python script function yields errors. I tried using groupby + rank and also groupby + transform and both give errors. When inspecting the advanced editor, additional quotes were added to the function by powerBI, I removed them and it still didn't fix the error.
dataset['rank'] = dataset.groupby(""Category"")[""value""].rank(method=""dense"", ascending=False)
https://stackoverflow.com/questions/46998281/how-to-rank-within-a-group-in-python
Maybe there is some syntax issue that I am missing? If this isn't working in python then perhaps a lot of things won't work with python in PBI since this is a very basic pandas function that does not require importing any external libraries. PBI imports pandas by default and uses pandas dataframes as the default data structure.
Hi @cyborgdroid
Since I am not the expert of Python, I can't figure out how to do the rank task with Python.
In Power BI, there is a simple way to do that.
Out of Edit queries, in the Report view, create measures
Measure = SUM(Table1[value]) Measure 2 = RANKX(ALLEXCEPT(Table1,Table1[category]),[Measure],,DESC)
Best regards
Maggie
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 38 | |
| 29 | |
| 28 | |
| 20 | |
| 18 |
| User | Count |
|---|---|
| 65 | |
| 35 | |
| 30 | |
| 25 | |
| 23 |