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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Esong2023
Frequent Visitor

Sequential Row Number like in Tableau

Hi there,

I'm working with a table with more than 10 fields, and I'm looking to create a 'Row Num' column that shows a sequential row number (not changing when sorting by a field). Specifically, I want the 'Row Num' to display from 1 to the last row number regardless of the sorting field.

Could you please guide me on how to achieve this? Any insights or suggestions on the best approach would be greatly appreciated.

Thanks in advance for your assistance!

 

Here are examples.

When sorting by Name:

Row NumNameStateCityEnrolled StatusContact for incentive
1CarlCAOrangeYesYes
2EllenTXAustinNoNo
3RayPAPhilaPendingYes

 

Now, when sorting by State:

Row NumNameStateCityEnrolled StatusContact for incentive
1CarlCAOrangeYesYes
2RayPAPhilaPendingYes
3EllenTXAustinNoNo

 

Now, when sorting by Enrolled Status: 

Row NumNameStateCityEnrolled StatusContact for incentive
1EllenTXAustinNoNo
2RayPAPhilaPendingYes
3CarlCAOrangeYesYes
1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @Esong2023 ,

Based on the sample and description you provided, You may also consider try the following steps:
1. Please try code as below to Create a Calculated table.

Select Column = 
DATATABLE(
    "Select Column",STRING,
    "Order",INTEGER,
    {
        {"Name",1},
        {"State",2},
        {"City",3},
        {"Enrolled Status",4},
        {"Contact for incentive",5}
    }
)

2. Use the following code to create a measure.

M_Row Num = 
VAR _SELECTVALUE =
    SELECTEDVALUE ( 'Select Column'[Order] )
VAR _RANKX1 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Name] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX2 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[State] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX3 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[City] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX4 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Enrolled Status] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX5 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Contact for incentive] ) ),
        ,
        ASC,
        DENSE
    )
RETURN
    SWITCH (
        _SELECTVALUE,
        1, _RANKX1,
        2, _RANKX2,
        3, _RANKX3,
        4, _RANKX4,
        5, _RANKX5,
        _RANKX1
    )

3. Put the corresponding field into the visual object and do the following.

vweiyan1msft_0-1703675296774.png

Result is as below.

vweiyan1msft_1-1703675335312.png

 

Best Regards,
Yulia Yan

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

4 REPLIES 4
v-weiyan1-msft
Community Support
Community Support

Hi @Esong2023 ,

Based on the sample and description you provided, You may also consider try the following steps:
1. Please try code as below to Create a Calculated table.

Select Column = 
DATATABLE(
    "Select Column",STRING,
    "Order",INTEGER,
    {
        {"Name",1},
        {"State",2},
        {"City",3},
        {"Enrolled Status",4},
        {"Contact for incentive",5}
    }
)

2. Use the following code to create a measure.

M_Row Num = 
VAR _SELECTVALUE =
    SELECTEDVALUE ( 'Select Column'[Order] )
VAR _RANKX1 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Name] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX2 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[State] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX3 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[City] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX4 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Enrolled Status] ) ),
        ,
        ASC,
        DENSE
    )
VAR _RANKX5 =
    RANKX (
        ALLSELECTED ( 'Table' ),
        CALCULATE ( MAX ( 'Table'[Contact for incentive] ) ),
        ,
        ASC,
        DENSE
    )
RETURN
    SWITCH (
        _SELECTVALUE,
        1, _RANKX1,
        2, _RANKX2,
        3, _RANKX3,
        4, _RANKX4,
        5, _RANKX5,
        _RANKX1
    )

3. Put the corresponding field into the visual object and do the following.

vweiyan1msft_0-1703675296774.png

Result is as below.

vweiyan1msft_1-1703675335312.png

 

Best Regards,
Yulia Yan

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

Thank you very much for your response!!

ThxAlot
Super User
Super User

ThxAlot_0-1703020723020.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Hi,

Is this to answer my question?

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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