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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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