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
Anonymous
Not applicable

How to rank categories?

HI, 

I have table with set order and known categories. What I want to get as result of calculated column rankColorGroup is something like this.  RankXByCategory.jpg If you have some ideas, please share them. Thanks

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@Anonymous 

ok, let's rock

 

first, create two calculated columns:

_colMaxInGroup = 
VAR _nextColor = LOOKUPVALUE('Table'[color],'Table'[order],'Table'[order]+1)
RETURN
IF(_nextColor='Table'[color],0,1)

and

_colGroup = IF('Table'[_colMaxInGroup]=1,'Table'[order],
calculate(min('Table'[order]),FILTER(ALL('Table'),'Table'[order]>EARLIER('Table'[order]) && 'Table'[_colMaxInGroup]=1))
)

 

and cherry on the top

rankColourGroup = RANKX('Table','Table'[_colGroup],,,Dense)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous ,

 

if I have understood it currectly your wants to rank the color by using order as Categorgy.

To do so, please use the below DAX formula:

 

 

RankColorGroup =
IF (
    'Table'[Color] = "Red",
    RANKX ( FILTER ( 'Table', 'Table'[Color] = "Red" ), 'Table'[Order],, ASC ),
    IF (
        'Table'[Color] = "Blue",
        RANKX ( FILTER ( 'Table', 'Table'[Color] = "Blue" ), 'Table'[Order],, ASC ),
        IF (
            'Table'[Color] = "Orange",
            RANKX ( FILTER ( 'Table', 'Table'[Color] = "Orange" ), 'Table'[Order],, ASC )
        )
    )
)

 

 

 

If this post helps, then please consider Accepting it as the solution.

 

Regards,

Gaurav Raj Singh

LinkedIN : https://www.linkedin.com/in/gauravrajsingh/

 

 

 

az38
Community Champion
Community Champion

hi @Anonymous 

i couldn't find any logic in your rankColorGroup rule

can you describe more detailed how it should be defined?

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Same color that form 1 or more rows in series get unique number, in ascending order.

Anonymous
Not applicable

NEw.jpg

az38
Community Champion
Community Champion

@Anonymous 

ok, let's rock

 

first, create two calculated columns:

_colMaxInGroup = 
VAR _nextColor = LOOKUPVALUE('Table'[color],'Table'[order],'Table'[order]+1)
RETURN
IF(_nextColor='Table'[color],0,1)

and

_colGroup = IF('Table'[_colMaxInGroup]=1,'Table'[order],
calculate(min('Table'[order]),FILTER(ALL('Table'),'Table'[order]>EARLIER('Table'[order]) && 'Table'[_colMaxInGroup]=1))
)

 

and cherry on the top

rankColourGroup = RANKX('Table','Table'[_colGroup],,,Dense)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks, your way of solving this gave me ideas for other things too 🙂

az38
Community Champion
Community Champion

@Anonymous 

for your second question with CaseID always the same

_colMaxInGroup = 
VAR _nextColor = LOOKUPVALUE('Table'[color],'Table'[order],'Table'[order]+1,'Table'[CaseID],'Table'[CaseID])
RETURN
IF(_nextColor='Table'[color],0,1)

and

_colGroup = IF('Table'[_colMaxInGroup]=1,'Table'[order],calculate(min('Table'[order]),FILTER(ALL('Table'),'Table'[order]>EARLIER('Table'[order]) && 'Table'[_colMaxInGroup]=1 && 'Table'[CaseID]=EARLIER('Table'[CaseID]))))

and then

rankColourGroup = RANKX(FILTER('Table','Table'[CaseID]=EARLIER('Table'[CaseID])),'Table'[_colGroup],,,Dense)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.