Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Counting Amount of Certain Character in a String

Like (0) ShareShare
ReportReport
Posted on 5 Jan 2024 18:52:53 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:
  • cmitchener Profile Picture
    on 07 Feb 2024 at 14:51:01
    Re: Counting Amount of Certain Character in a String

    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.

  • jQuery Profile Picture
    8 on 07 Feb 2024 at 01:34:17
    Re: Counting Amount of Certain Character in a String

    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 06 Feb 2024 at 17:44:35
    Re: Counting Amount of Certain Character in a String

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

  • jQuery Profile Picture
    8 on 06 Feb 2024 at 17:36:02
    Re: Counting Amount of Certain Character in a String

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

  • cmitchener Profile Picture
    on 06 Feb 2024 at 17:17:17
    Re: Counting Amount of Certain Character in a String

    Something like this may work for that:

     

    cmitchener_0-1707239728208.png

     

  • jQuery Profile Picture
    8 on 06 Feb 2024 at 17:01:55
    Re: Counting Amount of Certain Character in a String

    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.

  • CNT Profile Picture
    10,919 Super User 2025 Season 1 on 05 Jan 2024 at 19:42:37
    Re: Counting Amount of Certain Character in a String

    @cmitchener 

    Glad to help!

  • cmitchener Profile Picture
    on 05 Jan 2024 at 19:40:14
    Re: Counting Amount of Certain Character in a String

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

  • Verified answer
    CNT Profile Picture
    10,919 Super User 2025 Season 1 on 05 Jan 2024 at 19:31:31
    Re: Counting Amount of Certain Character in a String

    @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.

     

  • Verified answer
    cmitchener Profile Picture
    on 05 Jan 2024 at 19:29:04
    Re: Counting Amount of Certain Character in a String

    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")

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard