Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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