Forum Discussion

dp106's avatar
dp106
Helper I
7 years ago
Solved

Create Sequence Number using DAX

Hi,

 

I need create Sequence number using DAX function.  Here is an example

 

DEPT NO   EMP NO   SEQNO

10               100          3

10               200          2

10               300          1

20               400          3

20               500          2

20               600          1

 

I tried using Rankx  but could not get it right.

 

Thanks

 

  • Hi dp106,

     

    For calculated column,

    SEQNO =
    RANKX (
        FILTER ( Table8, Table8[DEPT NO] = EARLIER ( Table8[DEPT NO] ) ),
        Table8[EMP NO],
        ,
        DESC,
        DENSE
    )

     

    For measure,

    SEQNO measure =
    RANKX (
        ALLEXCEPT ( Table8, Table8[DEPT NO] ),
        CALCULATE ( SUM ( Table8[EMP NO] ) ),
        ,
        DESC,
        DENSE
    )
    

     

    Best regards,

    Yuliana Gu

2 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi dp106

    Do you want to follow the order of 'EMP NO'?

    Show your code for RANKX and we can have a look

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi dp106,

     

    For calculated column,

    SEQNO =
    RANKX (
        FILTER ( Table8, Table8[DEPT NO] = EARLIER ( Table8[DEPT NO] ) ),
        Table8[EMP NO],
        ,
        DESC,
        DENSE
    )

     

    For measure,

    SEQNO measure =
    RANKX (
        ALLEXCEPT ( Table8, Table8[DEPT NO] ),
        CALCULATE ( SUM ( Table8[EMP NO] ) ),
        ,
        DESC,
        DENSE
    )
    

     

    Best regards,

    Yuliana Gu