web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Counting Amount of Cer...
Power Apps
Answered

Counting Amount of Certain Character in a String

(0) ShareShare
ReportReport
Posted on by

I feel like this has to have a really simple solution that I'm overlooking, but I just can't figure it out. I'm looking for a way to count how many times a letter occurs in a string; for example, "animal" would return "2", if I was counting the letter A.

Categories:
I have the same question (0)
  • Verified answer
    cmitchener Profile Picture
    on at

    I figured a solution out, and since I haven't seen a great resource on it yet here's what I've found:

    CountIf(Split(textSOURCE ""), Lower(Value) = CHARACTER_SEARCH)
     
    Here's an example:
     
    CountIf(Split(TextLabel1, ""), Lower(Value) = "a")
  • Verified answer
    CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @cmitchener  This code will give the result seen below,

    ClearCollect(colCharacterCount,
     DropColumns(
     AddColumns(
     GroupBy(
     Split("animal", ""),
     "Value",
     "GroupedValues"
     )
     ,
     "Count", CountRows(GroupedValues)
     ), "GroupedValues"
     )
    )

     

    CNT_0-1704483052155.png

     

    Please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • cmitchener Profile Picture
    on at

    I like your way better, there's less code to reference it later on. Thanks!

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @cmitchener 

    Glad to help!

  • jQuery Profile Picture
    10 on at

    What if I wanted to just count the numbers in a text field?  For example - phone number is 123-456-7890.  I want the count of the numbers, not the dashes.

  • cmitchener Profile Picture
    on at

    Something like this may work for that:

     

    cmitchener_0-1707239728208.png

     

  • jQuery Profile Picture
    10 on at

    Thanks for the help.  I need the numbers - not the dashes - but I figured out with your help.  Thanks again.

  • cmitchener Profile Picture
    on at

    Ah, I see now that I did the result backwards lol. Glad you got the answer!

  • jQuery Profile Picture
    10 on at

    Would you be able to solve for the number counts as well?  Wondering if there is an eaiser way.

    What I did was to use the total length of the string minus the number of dashes your code found.

  • cmitchener Profile Picture
    on at

    I got it:

    cmitchener_0-1707316827438.png

     

     

    Here's the code to copy:

    CountIf(Split(TEXT_FIELD, ""), Len(Value(ThisRecord.Value)) > 0)

     

     

    Here's what it does:

    1. The TEXT_FIELD that you want to search for numbers is split by each character

    2. Each record's value (in this case, every character) is converted into a number

         a. If it's already a number, this will return the character

         b. If it's any character other than a number, it will be a blank record

    3. The length of each character as a value is checked. If it's a number, this will return a 1. If it was another character that is now a blank record, this will return a 0.

    4. Every 1 in this list is counted, returning you the number of numbers in your text field

     

     

    My explanation might be a little confusing, but if you plug in the Split code into a list box it will help it make sense.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 505

#2
WarrenBelz Profile Picture

WarrenBelz 502 Most Valuable Professional

#3
Haque Profile Picture

Haque 324

Last 30 days Overall leaderboard