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
DanCasSan
Helper V
Helper V

Row_Number in column with DAX

Dear community:

 

I need your support. I want to perform an equivalency of the SQL ROW_NUMBER function on one of my tables in Power BI; basically, do what I put in the image. This equivalence should be as a column and not a measure.

 

ROW_NUMBER.PNG

 

Thanks for your support!

 

Cheers,

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @DanCasSan ,

 

You can add an index column in query editor first.

Then use the rankx function to create the calculated column.

Rank =
RANKX (
    FILTER (
        'Table',
        'Table'[KEYRATE] = EARLIER ( 'Table'[KEYRATE] )
            && 'Table'[PRDLIT] = EARLIER ( 'Table'[PRDLIT] )
    ),
    'Table'[Index],
    ,
    ASC
)

Test_rankx.PNG

Sample .pbix 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-lianl-msft
Community Support
Community Support

Hi @DanCasSan ,

 

You can add an index column in query editor first.

Then use the rankx function to create the calculated column.

Rank =
RANKX (
    FILTER (
        'Table',
        'Table'[KEYRATE] = EARLIER ( 'Table'[KEYRATE] )
            && 'Table'[PRDLIT] = EARLIER ( 'Table'[PRDLIT] )
    ),
    'Table'[Index],
    ,
    ASC
)

Test_rankx.PNG

Sample .pbix 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@DanCasSan 
For Rank Refer these links

https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale

 

Refer Rank by sub Category both in 1 and 2 article and use dense option in the last argument of RankX You have also use breaking ties option

edhans
Super User
Super User

I'm not aware of a way to put an index in a column in DAX. without a unique value to sort on. In Power Query, you just use the Add Column ribbon, then Index Column.

 

if you can rank your data and create an index that way, see this post 

 

The problem is your data doesn't have a unique field, and row numbers aren't really a concept in a DAX table like they can be in SQL or Power Query.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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