Forum Discussion

mrskool's avatar
mrskool
Frequent Visitor
7 years ago
Solved

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!

  • 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

2 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity 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's avatar
      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!