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

Notifications

Announcements

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
    8 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
    8 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
    8 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard