Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Row Number in DAX

Hi,

My SQL query is this ;

 

SELECT 

            CommitteeName,
            AllotmentMainID,
            ApprovedTotalLimit,

            ROW_NUMBER() OVER(PARTITION BY CommitteeName,AllotmentMainID ORDER BY ApprovedTotalLimit DESC) AS RN

FROM Allotment;

 

I want to write in Dax. How to write Row Number in Dax?

 

Please Help.

Thanx 🙂

 

 

 

5 Replies

  • az38's avatar
    az38
    Icon for Community Champion rankCommunity Champion

    Anonymous 

    use rankx like

    Column = 
        RANKX(
            FILTER(
                    'Table',
                    'Table'[CommitteeName]=EARLIER('Table'[CommitteeName]) &&  'Table'[AllotmentMainID]=EARLIER('Table'[AllotmentMainID])
                    ),
            'Table'[ApprovedTotalLimit], , DESC
            )
    • sqldev2017's avatar
      sqldev2017
      Icon for Microsoft Employee rankMicrosoft Employee

      I think DAX is utter nonsense, compared to the simplicity of SQL ! 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your answer but I I could not tell sorry.

      For Example : 

       

      CommitteeNameAllotmentMainIDApprovedTotalLimit 
      A1002500 
      A1002500 
      A1003000 
      B2005000 
      C30010000 
      C3005000 

       

      Result : 

      CommitteeNameAllotmentMainIDApprovedTotalLimitRowNumber
      A10030001
      A10025002
      A10025003
      B20050001
      C300100001
      C30050002

       

      I want to this.

       

      Thank U:)

      • az38's avatar
        az38
        Icon for Community Champion rankCommunity Champion

        Anonymous 

        how do you want to break a tie-situations?

         

        you can add an Index column in powe query and the create a dax rankx calculated column

        Column = 
            RANKX(
                FILTER(
                        'Table',
                        'Table'[CommitteeName]=EARLIER('Table'[CommitteeName]) &&  'Table'[AllotmentMainID]=EARLIER('Table'[AllotmentMainID])
                        ),
                'Table'[ApprovedTotalLimit] + [Index]/1000000, , DESC, Skip
                )