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 : 7kw7cSgpodejbixevHz/5y
Power Automate - Power Automate Desktop
Answered

Get Mode or Frequents value in a List

Like (0) ShareShare
ReportReport
Posted on 16 Oct 2023 03:03:59 by 136

Greetings, I would like to ask for assistance on a matter.

 

I have a List that contains 8 sets of integers. I would like to get the Mode or the most Frequent integers from that List. Is there any way to do this ?

 

E.G. Lets say the List are as follows: 

 

0. 12

1. 14

2. 23

3. 44

4. 12

5. 12

6. 16

7. 12

 

So, I would like to get the value '12' from the List.

 

I appreciate any kind of advice and suggestions.

 

Regards,

I have the same question (0)
  • RookAils1 Profile Picture
    136 on 17 Oct 2023 at 09:47:30
    Re: Get Mode or Frequents value in a List

    Thank you so much @Agnius !!!  I did made an attempt on using VBScript first but to no avail. I did exactly as you instructed and it works. I truly appreciate the extensive explanation on how it works and all. 

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on 16 Oct 2023 at 07:12:58
    Re: Get Mode or Frequents value in a List

    There is no function to do it natively in PAD. You could use a Python or C# script to do it.

    A very simple way to do it in Python without importing any modules (because PAD supports Python 2 only, and does not actually support most libraries of Python 3 and later) is doing this:

    def most_frequent(List):
     return max(set(List), key = List.count)
     
    List = "%JoinedText%".split()
    print(most_frequent(List))

     

    This uses a variable passed in from PAD as %JoinedText% that is the result of using Join text on the list (because the list syntax in PAD is not exactly the same as in Python).

    The entire flow should look somewhat like this:

    Agnius_0-1697439642050.png

     

    You can also copy the following code and paste it into PAD to get the actions generated for you:

    SET List TO [12, 14, 23, 44, 12, 12, 16, 12]
    Text.JoinText.JoinWithDelimiter List: List StandardDelimiter: Text.StandardDelimiter.Space DelimiterTimes: 1 Result=> JoinedText
    Scripting.RunPythonScript PythonCode: $'''def most_frequent(List):
     return max(set(List), key = List.count)
     
    List = \"%JoinedText%\".split()
    print(most_frequent(List))''' ScriptOutput=> PythonScriptOutput ScriptError=> ScriptError
    Text.Trim Text: PythonScriptOutput TrimOption: Text.TrimOption.Both TrimmedText=> TrimmedText

     

    Note that Trim text at the end is needed, because using Run Python script with a print command will result in an extra newline being added to the string that is printed. So, if you want to use the output in your flow in any way, you need to trim it. Also, if you want to use it as a numeric value, you will also need to use Convert text to number to have it converted by PAD. The output of the Python script will in fact be a string until you convert it.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

     

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…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2