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,
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.
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:
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.
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2