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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Milagros
Helper I
Helper I

Giving a number as an identifier of all text strings between two irregularly recurring text strings

Hi, I have a column of data, that repeats text "a" at irregular inervals, I need to give a number to every "a" and the same number for every other text between "a" and the next "a", see below. The value of "a" should increase by 1 at every instance of "a". Hopefully there is a simple solution, which I am missing! 🙂 I tried creating a index, then using DAX, but haven't been able to solve it. 

Col               Number 

a                   1

b                   1

a                   2

b                   2

c                   2

a                   3

b                   3                

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@Milagros 

create an index column. then use below DAX to create another column

Count = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Column1]=EARLIER('Table'[Column1])&&'Table'[Index]<=EARLIER('Table'[Index])))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

v-rzhou-msft
Community Support
Community Support

Hi @Milagros 

You can try to use rankx function to build a calculated column.

Add an index column in Power Query Editor by index function.

Then build a number column.

Number = 
RANKX(FILTER('Table','Table'[Col]=EARLIER('Table'[Col])),'Table'[Index],,ASC)

Result is as below.

1.png

You can download the pbix file from this link: File

 

Best Regards,

Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Milagros 

You can try to use rankx function to build a calculated column.

Add an index column in Power Query Editor by index function.

Then build a number column.

Number = 
RANKX(FILTER('Table','Table'[Col]=EARLIER('Table'[Col])),'Table'[Index],,ASC)

Result is as below.

1.png

You can download the pbix file from this link: File

 

Best Regards,

Rico Zhou

 

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

ryan_mayu
Super User
Super User

@Milagros 

create an index column. then use below DAX to create another column

Count = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Column1]=EARLIER('Table'[Column1])&&'Table'[Index]<=EARLIER('Table'[Index])))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors