## Comments

7 comments

Hi Steeve,

in your calculation field type: @sum of NameOfTheDurationField

Than select the token from the list which pops up.

Rainer

It works !

Thank you for your Help Rainer.

Hi Rainer,

I am already using this "formula". Is it possible to calculate this duration but in a specific time?

So to know for example the duration of the 2016 projects (without erasing the current ones); make something like:

@sum of NameOfTheDurationField - @sum of NameOfTheDurationField [01/01/2015 - 31/12/2015]

To calculate just the duration of this year's projects. It is this possible? Do you know the "formula"

Thanks

Roger

Hi Roger,

yes that's possible -  if you have a date field in your app where the duration field is in. But you can't do it with `@sum of` . What exactly do you want to be shown in your calculation field? Do you need the result for further calculations?

The code for getting the sum of durations for one specific year is:

`var dur = @All of Duration;var date = @All of date field;`
`var sum2015 = 0;for(var i = 0; i < dur.length; i++){if(moment(date[i]).format("YYYY") == "2015"){sum2015 +=dur[i];}};sum2015`

That code would show the sum for 2015 in number format (helpful if you need the number for further calculations).

The following code woud show the sums for both years as text:

`var dur = @All of Duration;var date = @All of date field;`
`var sum2015 = 0;for(var i = 0; i < dur.length; i++){if(moment(date[i]).format("YYYY") == "2015"){sum2015 +=dur[i];}};var sum2016 = 0;or(var i = 0; i < dur.length; i++){if(moment(date[i]).format("YYYY") == "2016"){sum2016 +=dur[i];}};`
`"Sum 2015: " + sum2015 + " hrs \n" +"Sum 2016: " + sum2016 + " hrs\n" +"**Total: "  + (sum2016+sum2015) + " hrs**"`

You would see this:

Sum 2015: 1000  hrs
Sum 2016: 80 hrs
Total: 1080 hrs

It's also possible to select on the fly what you want to see in the calculation field. You could add a catogory field "Show Year" before the calculation field with the options: 2015, 2016, both. And then in the code you could define what happens if an option is selected.

Hi Rainer,

About your last comment, is it possible to achieve the same calculation using the automatic "CreatedOn" field? I mean, without an explicit date field? If so, can you please provide an example about using CreatedOn?

Thank you

Adrià

Hi Adria,

yes you can. Create a calculation field in the related app, enter @created on, pick the token so it becomes blue. Then give that field a name e.g. "Created on".

Then take my calculation example and enter

var date = @all of created on

That's it.

Exactly what I needed.

Thank you so much

Please sign in to leave a comment.