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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Character Frequency / Count the No of times a pattern is repeated in a cell

Hi Everyone,

 

Looking for a way to count the number of times a pattern exists in a cell.

E.g. How many times does "aa" exist in the below data? Answer: 6

 

AADAD

DASSAA

42CAA8

DFGSKD

FWAABJFAAKDH

UQTEHS

KDSAAR

 

And do special characters have any significance? e.g. What if I were to count the number of times "?" or ";" or "!" exists

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

To create measures as below.

 

Measure 2 = var co =MAX(Table1[Column1])
var len =
LEN(co)-LEN(SUBSTITUTE(co,"AA",""))
return
len/2
Measure 3 = SUMX(Table1,[Measure 2])

len.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To create a measure as below.

 

Measure = 
CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER ( Table1, SEARCH ( "AA", Table1[Column1],, BLANK () ) <> BLANK () )
)

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks v-frfei-msft.

 

This would counts the number of rows, what about number of occurrences?

e.g. FWAABJFAAKDH should have value 2 and not consider it as a single row (Will add this to the examples list)

Hi @Anonymous ,

 

To create measures as below.

 

Measure 2 = var co =MAX(Table1[Column1])
var len =
LEN(co)-LEN(SUBSTITUTE(co,"AA",""))
return
len/2
Measure 3 = SUMX(Table1,[Measure 2])

len.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks a lot, @v-frfei-msft 🙂

 

One clarification: 

len/2

is because the pattern is two digits long i.e. "AA" right? For three digits e.g. "AAA", the formula would change to

len/3

 

Hi @Anonymous,

 

Yes, you are right.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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