Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a table with this structure
Year-Week | Group | Subgroup | Value | Ranking (New) |
2022-01 | A | A1 | 1 | 2 |
2022-01 | A | A2 | 1 | 2 |
2022-01 | B | B1 | 5 | 1 |
2022-01 | B | B2 | 5 | 1 |
2022-02 | A | A1 | 5 | 1 |
2022-02 | B | B1 | 3 | 2 |
Now I would like to add a column that shows me the rank for each week and for each group.
The result would be the last column.
How can this be done?
Solved! Go to Solution.
Hi,
Please try the below for creating a new column.
Ranking CC =
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
SUMMARIZE (
FILTER ( Data, Data[Year-Week] = currentweek && Data[Value] <> 0 ),
Data[Subgroup],
Data[Value]
)
RETURN
IF( Data[Value] = 0, BLANK(),
RANKX ( subgrouptable, Data[Value],, DESC, DENSE )
)
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
Ranking CC =
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
SUMMARIZE (
FILTER ( Data, Data[Year-Week] = currentweek ),
Data[Subgroup],
Data[Value]
)
RETURN
RANKX ( subgrouptable, Data[Value],, DESC, DENSE )
@Jihwan_Kim Thanks a lot! That works perfectly well. Is there any chance to exclude all rows where [Value] = 0 ?
So the RANK stops when row has 0 as a value.
Hi,
Thank you for your feedback.
Could you please share the sample data, and then I can try to come up with more accurate solution.
Thanks.
@Jihwan_Kim THanks a lot!
Please find below sample data:
Year-Week | Group | Subgroup | Value | Ranking (New) |
2022-01 | A | A1 | 1 | 2 |
2022-01 | A | A2 | 1 | 2 |
2022-01 | B | B1 | 5 | 1 |
2022-01 | B | B2 | 5 | 1 |
2022-02 | A | A1 | 5 | 1 |
2022-02 | B | B1 | 3 | 2 |
2022 | B | B2 | 0 |
As you can see the last row has a 0 value. This should be excluded in the function.
Hi,
Please try the below for creating a new column.
Ranking CC =
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
SUMMARIZE (
FILTER ( Data, Data[Year-Week] = currentweek && Data[Value] <> 0 ),
Data[Subgroup],
Data[Value]
)
RETURN
IF( Data[Value] = 0, BLANK(),
RANKX ( subgrouptable, Data[Value],, DESC, DENSE )
)
Thank you for that solution. And the version removing blanks is great.
@joshua1990 , Can explain logic , I tried a few combinations not able to get the same output
Column = rankx('Rank Table (2)',CALCULATE(sum([Value]), filter('Rank Table (2)', [Group] =EARLIER('Rank Table (2)'[Group]) && 'Rank Table (2)'[Subgroup] =max('Rank Table (2)'[Subgroup]) )),,DESC,Dense)
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
9 | |
8 | |
8 |
User | Count |
---|---|
14 | |
12 | |
11 | |
11 | |
8 |