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
mrskool
Frequent Visitor

DAX Ranking over a group, status flag and sequence columns

Hello -

I have been trying to wrap my brain around using a DAX calculated column to get a ranking over a group by status flag and sequence. The status flag that goes between 1 and 0.   The SK, sequence and flag are all in the data source.    I am trying to get a ranking sequence that starts back at 1 whenever the flag changes.  Example:

 

SKsequenceflaglooking for this ranking:
83050111
83050212
83050301
83050402
83050511
83050601
83050702
83050803
83050904
830501005
830501106
830501207
830501308
830501409
803051111
803051212
803051301
803051402
803051503
803051611
803051701
803051802
803051903
8030511011
8030511112
8030511213
8030511314
8030511415

 

Any thoughts/ideas would be greatly appreciated!

Thanks!

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @mrskool 

 

NewCol =
VAR PreviousFlagSeq_ =
    CALCULATE (
            MAX ( Table4[sequence] );
            Table4[flag] <> EARLIER ( Table4[flag] );
            Table4[sequence] < EARLIER ( Table4[sequence] );
            ALLEXCEPT ( Table4; Table4[SK] )
    ) + 0
RETURN
    Table4[sequence] - PreviousFlagSeq_

Please mark the question solved when we get to the solution and consider kudoing if posts are helpful.

 

Cheers  Datanaut

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @mrskool 

 

NewCol =
VAR PreviousFlagSeq_ =
    CALCULATE (
            MAX ( Table4[sequence] );
            Table4[flag] <> EARLIER ( Table4[flag] );
            Table4[sequence] < EARLIER ( Table4[sequence] );
            ALLEXCEPT ( Table4; Table4[SK] )
    ) + 0
RETURN
    Table4[sequence] - PreviousFlagSeq_

Please mark the question solved when we get to the solution and consider kudoing if posts are helpful.

 

Cheers  Datanaut

mrskool
Frequent Visitor

Thanks!   That worked!   I was lost in the row context...  Your code helped me understand where I was off on the wrong path!

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.