Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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 Num | Name | State | City | Enrolled Status | Contact for incentive |
| 1 | Carl | CA | Orange | Yes | Yes |
| 2 | Ellen | TX | Austin | No | No |
| 3 | Ray | PA | Phila | Pending | Yes |
Now, when sorting by State:
| Row Num | Name | State | City | Enrolled Status | Contact for incentive |
| 1 | Carl | CA | Orange | Yes | Yes |
| 2 | Ray | PA | Phila | Pending | Yes |
| 3 | Ellen | TX | Austin | No | No |
Now, when sorting by Enrolled Status:
| Row Num | Name | State | City | Enrolled Status | Contact for incentive |
| 1 | Ellen | TX | Austin | No | No |
| 2 | Ray | PA | Phila | Pending | Yes |
| 3 | Carl | CA | Orange | Yes | Yes |
Solved! Go to Solution.
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.
Result is as below.
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.
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.
Result is as below.
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!!
Hi,
Is this to answer my question?
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.