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 Automate - Building Flows
Answered

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?

 

I have the same question (0)
  • abm abm Profile Picture
    32,585 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,585 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 691 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 431 Moderator

#3
developerAJ Profile Picture

developerAJ 266

Last 30 days Overall leaderboard