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

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

Like (0) ShareShare
ReportReport
Posted on 15 Oct 2019 11:37:52 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)
  • jelittle Profile Picture
    15 on 10 Mar 2023 at 22:08:45
    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 "-"

  • Community Power Platform Member Profile Picture
    on 15 Oct 2019 at 15:54:34
    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!

  • Verified answer
    abm abm Profile Picture
    32,575 Most Valuable Professional on 15 Oct 2019 at 15:18:19
    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 15 Oct 2019 at 13:13:32
    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!

  • abm abm Profile Picture
    32,575 Most Valuable Professional on 15 Oct 2019 at 12:22:54
    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

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…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 707 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 499 Moderator

#3
chiaraalina Profile Picture

chiaraalina 312

Last 30 days Overall leaderboard
Loading complete