cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tupues
Level: Powered On

Count certain items in list and add them

I have a sharepoint list from which I need to create a flow to generate an Email containing the amount of times the person that the Email is being being sent to is on the list. Additionally one column contains a number which is attributed to that person. This number needs to be added to every subsequent number attributed to that person.

 

I.e. the list below should result in an email stating: "37466 You had a WDO 2 times with a total number 4 days"

 

Screen Shot 2019-10-05 at 11.33.29.png

 

I am looking forward to your help!

 

Many thanks,

 

Tom

16 REPLIES 16
Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

You can follow the below screenshots:se1.PNG

Initialise an array variable to get all the unique staff ids, another one to store the counted days and then get items from the sharepoint list. 

se2.PNG

For each returned value check if the staff ID already exists in the array and if not, add it to the array.se3.PNG

 

For each staff id, get the items and check the number of items returned, add the days to the variable for every item. 

Expressions: 

length(body('Get_items_2')?['value'])

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

very many thanks for your help!

 

I followed your instructions step by step. However I am not confronted with the following error message:

 

Screen Shot 2019-10-06 at 10.36.34.png

 

Also I am not entierly sure how to add the output of it all to an Email as seen below:

 

Screen Shot 2019-10-06 at 10.38.59.png

 

Very many thanks again for you patience and your help!

 

Tom

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

First, in the icrement variable you need to add the int() function for the increment variable action input. Just put the cursor in the increment variable value and in the expression editor type int(). Within the bracket select the integer column from the dynamic selector. 

 

Next, within the apply to each of the array itself, you will have to add the send email action and you can use all the dynamic selector outputs for that. 

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

Hi @yashag2255 

 

Now we're getting somewhere. However there seems to be an issue with the calculation.

 

Based on this list Screen Shot 2019-10-06 at 13.28.30.png

 

the flow sent me an Email with this content: 
"Dear StaffID 12345 you have helped us with Working Days Off 36 times"

 

Obviously it should be 4 times... i think there must be a mistake in the calculations somewhere... Any ideas?

 

Thanks again for your help!

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

This looks like some action is getting nested in the apply to each loop. Can you share the full screeshot of the entire flow so that we can better understand whats going on?

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

This is the entire flow as it stands at the moment.

Screen Shot 2019-10-07 at 14.09.37.png

 

Screen Shot 2019-10-07 at 14.10.14.png

top box is get items

 

Screen Shot 2019-10-07 at 14.09.47.pngScreen Shot 2019-10-07 at 14.10.08.pngScreen Shot 2019-10-07 at 14.10.24.png

 

Hope this helps. Many thanks!

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

Can you expand the increment variable action and check what is there in the value? Can you confirm that it contains the Days from the Get Items 2 action. Also, the Value in the apply to each 3 is from the Get Items 2 action?

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

this is the the details:

 

Screen Shot 2019-10-07 at 15.41.54.pngScreen Shot 2019-10-07 at 15.46.03.png

 

I hope this helps.

 

Many thanks!

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

Can you try updating the expression as: 

 

int(items('Apply_to_each_3')?['Days'])

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Highlighted
tupues
Level: Powered On

Re: Count certain items in list and add them

Ok, so looking at it in test mode, the output of the increment variable seems to be working properly. Its only when it is added to the emai body that things go wrong somehow.

 

I think it is the Compose 4 thats causing an issue here...

 

Screen Shot 2019-10-07 at 14.10.24.png

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

Yep! Looks like that to me too. Can you simply pass the variable in the email and see if it is working as expected?

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

tried that, results in this error sady:

 

'The inputs of template action 'Send_an_email_(V2)_2' at line '1 and column '1718' is invalid. Action 'Apply_to_each_3' must be a parent 'foreach' scope of action 'Send_an_email_(V2)_2' to be referenced by 'repeatItems' or 'items' functions.'.
Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

Can you share a screenshot?

 

 

tupues
Level: Powered On

Re: Count certain items in list and add them

sure:

 

this is how I insert the variable into the Email to be composed

Screen Shot 2019-10-08 at 14.32.31.png

 

This is the resulting error

 

Screen Shot 2019-10-08 at 14.34.04.png

Dual Super User
Dual Super User

Re: Count certain items in list and add them

Hey @tupues 

 

In the screenshot I can see you have added the Days sp column from the dynamic selector. remove that and in that place select the variable that we initialised in the eginning to store the sum of the days. 

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

tupues
Level: Powered On

Re: Count certain items in list and add them

Okay, did that but the number output I am getting is still completely wrong. For a person with just "1" as an item on the sp table as days I get "328" days in the EMail. It seems perhaps that it is adding all the other numbers on the table as well (although there is nowhere near 328 individuals on the table).... am just not sure if I am on the right track.

All we need is to add the numbers in a sp column of a certain individual and count the amount of times (number of instances) that individual appears on the sp table.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (6,027)