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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to count # of occu...
Power Automate
Unanswered

How to count # of occurrences of a character inside a string in Flow?

(0) ShareShare
ReportReport
Posted on by

Hi everyone, 

 

I am trying to make a fun what-personality-are-you-quiz by using Forms, SharePoint and Flow and I've run into a problem. 

 

Each question in Forms has four options and every option is equivalent to a letter value in a SharePoint List (e.g. "a", "b", "c" or "d") and after using an ODATA filter to get the right letters depending on answers from Forms and a Compose i get a string with the values:

 

a, a, b, a, c, a, c, d,

 

And noooooow, I would like be able to count how many occurances "a", "b", "c" and "d" has, to then check which letter has the most occurances. I am looking for a function like CountIf or something similar but can't find it in Flow?

 

Categories:
I have the same question (0)
  • abm abm Profile Picture
    32,858 Most Valuable Professional on at
    Re: How to count # of occurrences of a character inside a string in Flow?

    Hi @Anonymous 

     

    There is no such count function in Flow expressions. You could try using the split expression and find the count using the length.

     

    See below expression.

     

    length(split(variables('Text'),'a'))
     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

     

    Thanks

  • Community Power Platform Member Profile Picture
    on at
    Re: How to count # of occurrences of a character inside a string in Flow?

    Hi @abm,

     

    Thank you for your swift response! I tried it but seem to get 1 to many? For example "a,a,b" shows "3". Any clue why? 🙂

     

    Thank you!

  • Verified answer
    abm abm Profile Picture
    32,858 Most Valuable Professional on at
    Re: How to count # of occurrences of a character inside a string in Flow?

    Hi @Anonymous 

     

    I should have mentioned earlier that you need length - 1. So in your case for a,a,b it is going to split as follows.

     

    [
    "",
    ",",
    ",b"
    ]
     
    Total three array cells.  Try to use
    sub(length(split(variables('Text'),'a')), 1)
     
    If there are no matches this will return zero.
     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

     

    Thanks

     
  • Community Power Platform Member Profile Picture
    on at
    Re: How to count # of occurrences of a character inside a string in Flow?

    Hi again @abm,

     

    Thank you - it works like a charm! Well done 🙂 However, I just can seem to understand what exactly the lenght() function is counting? Smiley LOL I have tried breaking it done function by function, but still don't understand how works.

     

    Anyhow, thanks again!

  • jelittle Profile Picture
    15 on at
    Re: How to count # of occurrences of a character inside a string in Flow?

    the Split function splits the string into different elements of an array, so split("hello-World", "-"), would be equal too ["hello","World"], length counts the number of elements in the array so length(["hello", "world"]) is 2, which means there are n-1 instances of "-"

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard