cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Get the 3 highest numbers for every object of the same category out of an array

Hi Guys.

 

I have a Excel-List with Orders for Products of different Supermarkets. The Supermarkets have their own ID "M01", "M02", "S23" etc... And there is a column with Order-Numbers. 

My task now is to filter the List in a way, that it will only return the 3 highest Order numbers per Supermarket.

 

Inputfile (Excel):

[
{
"MarketID":"M001",
"Product": "Jumping-Rope",
"Orders": 128
},
{
"MarketID":"P01",
"Product": "Sausage",
"Orders": 47
},
{
"MarketID":"M001",
"Product": "Gym-Clothing",
"Orders": 512
},
{
"MarketID":"P01",
"Product": "Corndogs",
"Orders": 125
},
{
"MarketID":"M001",
"Product": "Training Weights",
"Orders": 11
},
{
"MarketID":"M001",
"Product": "Boxing Gloves",
"Orders": 250
},
{
"MarketID":"P01",
"Product": "Cheese",
"Orders": 12
},
{
"MarketID":"P01",
"Product": "Bacon",
"Orders": 25
},
{
"MarketID":"P01",
"Product": "Chocolate",
"Orders": 32
}
]

 

 

desired Result:

[
{
"MarketID":"M001",
"Product": "Gym-Clothing",
"Orders": 512
},
{
"MarketID":"M001",
"Product": "Boxing Gloves",
"Orders": 250
},
{
"MarketID":"M001",
"Product": "Jumping-Rope",
"Orders": 128
},
{
"MarketID":"P01",
"Product": "Corndogs",
"Orders": 125
},
{
"MarketID":"P01",
"Product": "Sausage",
"Orders": 47
},
{
"MarketID":"P01",
"Product": "Chocolate",
"Orders": 32
}
]

 

I already successfully tried to sort all the objects with their order number but that is not what I want... I want a JSON with only THREE products PER MarketID with the THREE HIGHEST Orders.

 

Any help is very appreciated! 

Thank you for your help in advance! 

Best Regards Justus

1 REPLY 1
Highlighted
Super User II
Super User II

Re: Get the 3 highest numbers for every object of the same category out of an array

@jukulu1337 

 

Power Automate does not have an easy way to sort the array of objects. 

You can cast your vote for the desired feature @ https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Sort-Array/idi-p/312043

 

As you are reading the data from Excel, you can use "List Rows present in a table" action as described in the below post:

https://sharepains.com/2020/03/05/sort-an-array-in-power-automate/

 

Note: You need to apply proper filter, sort column and top column fields in the "List Rows Present in a table"

 

Give a try and post your questions.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (7,544)