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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
JofrainVisda
Advocate I
Advocate I

Row Number

Hi Friends,

I would like to achieve this. Is this possible with DAX? I would like to put a row number for each occurence of the column 1. Thank you in advance!

JofrainVisda_0-1708065264801.png

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @JofrainVisda ,

 

I think you can achieve this if you are able to add a column to your table that acts as a ro identifier:

image.png

Then you can add the below DAX to create the column you are looking for:

Column = 
ROWNUMBER(
    SUMMARIZE(
        ALLSELECTED( 'Table')
        , 'Table'[item]
        , 'Table'[rowindex]
    )
    , ORDERBY( 'Table'[rowindex])
    , DEFAULT
    , PARTITIONBY( 'Table'[item] )
)

RANKX will not work because of

  • you have to partition by the single occurences and
  • you have to consider the ties, RANKX will never provide consecutive numbers for the same value.

Hopefully, this helps to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
JofrainVisda
Advocate I
Advocate I

Hi bro,

 

Thank you for your answer but Tom Martens is correct. I did not get the correct output. Appreciate you man

TomMartens
Super User
Super User

Hey @JofrainVisda ,

 

I think you can achieve this if you are able to add a column to your table that acts as a ro identifier:

image.png

Then you can add the below DAX to create the column you are looking for:

Column = 
ROWNUMBER(
    SUMMARIZE(
        ALLSELECTED( 'Table')
        , 'Table'[item]
        , 'Table'[rowindex]
    )
    , ORDERBY( 'Table'[rowindex])
    , DEFAULT
    , PARTITIONBY( 'Table'[item] )
)

RANKX will not work because of

  • you have to partition by the single occurences and
  • you have to consider the ties, RANKX will never provide consecutive numbers for the same value.

Hopefully, this helps to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thank you Tom! Your solution worked. I will accept this as the solutions.

Could I also add a parameter in this solution? like if I have a column 2 and it has a value of 1 and 2. So what I want to add is to count the sequence of Column 1 who's Column 2 is equal to 1. Then another sequence for Column 2 is equal to 2.

Hey @JofrainVisda ,

 

I have to admit that I have no idea what your requirement is and please open a thread.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
123abc
Community Champion
Community Champion

Yes, you can achieve this using DAX (Data Analysis Expressions) in Power BI or other tools that support DAX. You can use the RANKX function to assign a row number to each occurrence of values in Column 1. Here's a sample DAX expression you can use:

 

Row Number =
RANKX(
ALL('YourTableName'[Column1]), // Replace 'YourTableName' with the name of your table and 'Column1' with the name of your column
'YourTableName'[Column1], // Replace 'YourTableName' with the name of your table and 'Column1' with the name of your column
, ,
ASC,
Dense
)

 

This DAX expression will generate a row number for each occurrence of values in 'Column1'. Replace 'YourTableName' with the actual name of your table and 'Column1' with the name of your column.

You can add this DAX expression as a new calculated column in your Power BI table or use it in a measure, depending on your requirements.

 
 
 
 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.