question

JulieLin avatar image
0 Likes"
JulieLin asked Jeanette F commented

Calculated From List

My list contains products and records their Types.
I want to determine which Type has the highest count in the list and return the Type value.
How should I do this?

FlexSim 25.0.1
listquery
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered

You could use the following (only works if the list is global and not partitioned). It creates a table that contains all types and how often they appear on the list in descending order. Thus, if the result table is not empty, the first cell contains the most commen type.

  1. Table result = Table.query("SELECT Type, COUNT(Type) AS NumOfType FROM List1 GROUP BY Type ORDER BY NumOfType DESC");
  2. if(result.numRows > 0) {
  3.     return result[1][1];
  4. }
  5. return 0;
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.