Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register 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?
User | Count |
---|---|
84 | |
76 | |
75 | |
43 | |
36 |
User | Count |
---|---|
109 | |
56 | |
52 | |
48 | |
43 |