Find Min and Max value from list

1
Hi, I would like to find 5 max data and 5 min data from a list contains of 30 data. After I completed filter the min and max value, I would like to calculate the avg, min and max from the 20 data that has been filter. Does anyone know how to solve this problem?     Just  like below :
asked
5 answers
2

There are probably several way to do that, but I’d try this:

- you have your list with 30 objects, sort it on the value you’re calculating with and call that list30

- create a new empty list, let’s call that list20

- create an integer variable counter with value = 0

- loop through list30, add 1 to counter, if counter <= 5, continue, if counter > 20, break, else add iteratorObject to list20

- after the loop, you have your 20 objects in list 20 and you can do max, min and avg with the aggregate list action

answered
3

Hi Muahmmad,

          *To find maximum of 5 data, create microflow and retrieve desired entity. While retrieving data kept range as custom and in amount give 5 and in sorting choose the data attribute and sort it in descending and return the value.

         *To find minimum of 5 data, follow the above steps in sort tab alone give Ascending.

         *To calculate Average, retrieve all maximum and minimum data from the appropriate entity and then create a list.

          *create two integer variable with initial value as 0 and in the loop take max retrieve list and iterate the loop, put decision check if the value is greater than or equal to 5 then add the iterator value to created list else just increase the variable by 1. Follow same procedure for minimum add the iterator value in same created list.

         *using aggregate list action count the created list. To find total create a variable and initiate value as 0 and kept a loop inside that add the value and store in variable. Then divide (total value /count ) you will get average.

answered
1

Hi Muahmmad,

Have a look at this module this will help you out: https://marketplace.mendix.com/link/component/117075

 

  1. Do a Descending sort using List Operation activity  on this list that you have . Then use the module above to Take the top 5 from the list and take the bottom 5 data from the list. The module has 2 Java actions that does the work. 

Then you can use Default Activities to perform the other operations.

I am not able to see the image ( it broken ) 

ATB

answered
1

You’re using v8 which might require some utilities from the marketplace to complete the task like other answers have said.

 

For anyone using the latest LTS who comes across an issue like this again, with 9.24.0:

  1. Sort your list ascending (ascList) and sort it decending (decList).
  2. Use the built in list operation Range to get the first 5 from each asc/desc list (top5 / bottom5)
  3. Create a new list
  4. Add your top5 and bottom5 to the new list
  5. Use List Aggregation activity to Sum, Avg, Min, Max
answered
-1

Hi Muhammad, I believe there are Java-actions that can achieve what you are describing. They can take a specified number of items from the top of a sorted list. Alternatively you could loop an ascending list for the min values where you remove the top item from the list for each iteration. Do the same for a descending sorted list for the value to remove the max values. You are then left with the 20 remaining middle values.

answered