cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SylvieLet17
Responsive Resident
Responsive Resident

Count Duplicates in Array

This should be simple but I just can't get around it. 

 

I have an array that lists a bunch of users' departments. Only the department names, so it looks like:

Human Resources
Finance
Operations
Human Resources

 etc.

Naturally there are duplicates, since some users in this list are from the same department. 

I want to count the duplicates. 

Basically I want a final list like:

12 users from: Human Resources

1 user from: Operations

2 Users from: Logistics

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

@SylvieLet17 try this flow, very simple. Produces this output, but can easily be adjusted to be formed however you like:

[
  {
    "Department": "HR",
    "Count": 12
  },
  {
    "Department": "Ops",
    "Count": 1
  },
  {
    "Department": "Logistics",
    "Count": 2
  }
]

Fewer steps so less complicated https://ibb.co/54KZH4R (Easier to view on link):

CountDuplicates.png

Code for the append to results for you to copy and paste is:

{  
  "Department": @{item()},
  "Count":@{length(body('Filter_array'))}
}

 

See how you get on.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

View solution in original post

6 REPLIES 6
krootz
Solution Supplier
Solution Supplier

@SylvieLet17 

here's a sample flow and the output:

flow1.pngflow2.pngflow3.pngoutput.png

SylvieLet17
Responsive Resident
Responsive Resident

Thanks @krootz, I replicated your flow, but it seems to be timing out on the Each Dept action, with only 20 items in the array to loop through.  

Paulie78
Super User
Super User

@SylvieLet17 try this flow, very simple. Produces this output, but can easily be adjusted to be formed however you like:

[
  {
    "Department": "HR",
    "Count": 12
  },
  {
    "Department": "Ops",
    "Count": 1
  },
  {
    "Department": "Logistics",
    "Count": 2
  }
]

Fewer steps so less complicated https://ibb.co/54KZH4R (Easier to view on link):

CountDuplicates.png

Code for the append to results for you to copy and paste is:

{  
  "Department": @{item()},
  "Count":@{length(body('Filter_array'))}
}

 

See how you get on.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

@SylvieLet17 hmmm it only takes 10 secs for me to run it. 😅

krootz
Solution Supplier
Solution Supplier

@Paulie78 I like this, it's simpler! 🙂

Paulie78
Super User
Super User

@krootz thank you. You have been making some really neat solutions. Have learned quite a bit from your posts.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,802)