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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors