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

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
Super User
Super User

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 😄

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. 🙂

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

 

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.

My pleasure, mate! Enjoy!

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

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

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,059)