Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
We need to provide rank. The logic for the ranking is that whenever you have a value “Product” then you must start the new number and all others below should follow the same rank. Please check out the sample input and the expected output. Please provide or help me with the DAX to use
Solved! Go to Solution.
Thanks for 123abc's concern about this issue.
Hi, @yashkumarbhatia
I am glad to help you.
Based on your description, you need a ranking of the data that whenever you have a value "Product" then you must start the new number and all others below should follow the same rank.
Maybe you can refer to my DAX.
New Column in Power BI Desktop:
RNK =
VAR CurrentRow = Table1[ID]
VAR RNKVal =
CALCULATE(
COUNTROWS(Table1),
FILTER(
Table1,
Table1[ID] <= CurrentRow && Table1[Vals] = "Product"
)
)
RETURN RNKVal
Here is the result:
I have attached the corresponding pbix file below, I hope it helps you.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for 123abc's concern about this issue.
Hi, @yashkumarbhatia
I am glad to help you.
Based on your description, you need a ranking of the data that whenever you have a value "Product" then you must start the new number and all others below should follow the same rank.
Maybe you can refer to my DAX.
New Column in Power BI Desktop:
RNK =
VAR CurrentRow = Table1[ID]
VAR RNKVal =
CALCULATE(
COUNTROWS(Table1),
FILTER(
Table1,
Table1[ID] <= CurrentRow && Table1[Vals] = "Product"
)
)
RETURN RNKVal
Here is the result:
I have attached the corresponding pbix file below, I hope it helps you.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
To create a ranking based on the "Product" column as per your logic in Power BI, where a new rank starts whenever "Product" appears, you can use a DAX formula to generate this custom ranking.
Here's a sample approach:
Row Product
| 1 | A |
| 2 | |
| 3 | |
| 4 | B |
| 5 | |
| 6 | C |
| 7 |
Row Product Rank
| 1 | A | 1 |
| 2 | 1 | |
| 3 | 1 | |
| 4 | B | 2 |
| 5 | 2 | |
| 6 | C | 3 |
| 7 | 3 |
Please write the DAx in and aaranged manner and the output after writing this is please help @123abc
I can see that you're trying to assign a ranking to values in the "Vals" column. The requirement is to reset the rank every time a "Product" entry appears. I will provide a more detailed and organized DAX approach to achieve this.
Here is a step-by-step guide to writing the DAX measure for this case:
Rank =
VAR CurrentRow = Table[ID]
VAR IsProduct = Table[Vals] = "Product"
RETURN
IF(
IsProduct,
RANKX(
FILTER(Table, Table[ID] <= CurrentRow && Table[Vals] = "Product"),
Table[ID],
, ASC
),
CALCULATE(
MAXX(
FILTER(Table, Table[ID] < CurrentRow && Table[Vals] = "Product"),
RANKX(FILTER(Table, Table[ID] <= CurrentRow && Table[Vals] = "Product"), Table[ID], , ASC)
)
)
)
| 1 | Product | 1 |
| 2 | Milk | 1 |
| 3 | Butter | 1 |
| 4 | Cheese | 1 |
| 5 | Yogurt | 1 |
| 6 | Product | 2 |
| 7 | Muesli | 2 |
| 8 | Porridge | 2 |
| 9 | Product | 3 |
| 10 | Banana | 3 |
This approach should generate the expected output, where each "Product" starts a new rank, and all other values below it follow the same rank until a new "Product" appears.
Let me know if this resolves the issue!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 45 | |
| 42 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 122 | |
| 96 | |
| 66 | |
| 47 |