cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lana
Helper II
Helper II

Add the values in the number field

I have a field(field type is number) in my SharePoint list called "HowManyDays". I want to add all the number in the field for all the items.

 

ID HowManyDays

1       5

2       7

3        4

 

I want to calculate the total 16 in my variable.

 

Lana_0-1595870354889.png

 

What is wrong with my formula?

 

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Power Participant
Power Participant

Nono, it's all good, plus I should've assumed that you knew that ... it just wasn't mentioned is all.

 

And you're right, it's just a bit of an arse, and because I couldn't be bothered to over think an elegant solution, here's how I did it:

could not be bothered 2.jpg

 

 

I'm sure you could slim that down.

 

Essentially, though, the addition couldn't go in the setting of its own value, and there's no increment using the basic functions, so we needed to separate out with an extra variable.

add(variables('howManyDaysVAR'), int(items('Apply_to_each')?['HowManyDays']))

Oh, and because I hadn't locked down the decimals in the SharePoint list Power Automate read the SP value as a float, instead of an integer. So that " int() " that's around the SharePoint call is me making up for my mistake by using the expression that converts a value to an integer. 😉

 

All good. 🙂

View solution in original post

7 REPLIES 7
eliotcole
Power Participant
Power Participant

Hi, @Lana , I think it's because you're not running it in an Apply to each action.

 

You need to do the same thing for each item that the flow reads from the SharePoint list.

 

Will edit in pictures if needed once I've done a demo, but I think you'll get the point. 🙂

 

Yeah I figured I am missing Apply to each. 

 

But still looking into how I will store the previous value and add it to the next item value. 

 

Sorry a newbie to Power Automate 😄

eliotcole
Power Participant
Power Participant

Nono, it's all good, plus I should've assumed that you knew that ... it just wasn't mentioned is all.

 

And you're right, it's just a bit of an arse, and because I couldn't be bothered to over think an elegant solution, here's how I did it:

could not be bothered 2.jpg

 

 

I'm sure you could slim that down.

 

Essentially, though, the addition couldn't go in the setting of its own value, and there's no increment using the basic functions, so we needed to separate out with an extra variable.

add(variables('howManyDaysVAR'), int(items('Apply_to_each')?['HowManyDays']))

Oh, and because I hadn't locked down the decimals in the SharePoint list Power Automate read the SP value as a float, instead of an integer. So that " int() " that's around the SharePoint call is me making up for my mistake by using the expression that converts a value to an integer. 😉

 

All good. 🙂

View solution in original post

Thank you for the logic.

 

I still can't figure out what is wrong in my flow. Can you take a look?

 

Lana_0-1595875266278.png

 

 

Lana_1-1595875327973.png

 

eliotcole
Power Participant
Power Participant

Looking at the error it's telling you what it's being passed can't be converted to an integer, so it looks like all is fine, it's just what's going in there isn't.

 

Taking a closer look, hang on.

 

I actually have to run off, but if you separate out the logic, and create the integer outside of that addition step, then you can remove it from there, and chase the error.

 

My guess is that you maybe have to get the value yourself, instead of typing out my code (not assuming you are ... just a stab in the dark) ...

You need to cut that item that's in your Compose there, and paste it into your int() formula ... 

 

Will check back with you later. 🙂

 

Here's a quick video that I made (with a flow done for this issue here) to show you how to easily steal the right reference values, and I even externalised the int() in that one, too. 😉

https://youtu.be/ClN6Tci38qk

That's a very cool trick. I learnt something new today!

 

I was able to fix my issue too. Thank you so much for all your help.

eliotcole
Power Participant
Power Participant

My pleasure, mate! Enjoy!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,328)