# Ember.computed.sum

**URL:** https://discuss.emberjs.com/t/ember-computed-sum/9786
**Category:** Ember Data
**Created:** [February 15, 2016, 10:59pm UTC](https://discuss.emberjs.com/t/ember-computed-sum/9786 "2016-02-15T22:59:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![canop](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@canop](https://discuss.emberjs.com/u/canop)
#### Post date: [February 15, 2016, 10:59pm UTC](https://discuss.emberjs.com/t/ember-computed-sum/9786/1 "2016-02-15T22:59:26Z")

</div>

Let’s have models:

Model: **basket**

```
export default DS.Model.extend({
  fruits: DS.hasMany('fruit', { async: true }),

  fruitCountArray: Ember.computed.mapBy('fruits', 'count'),
  totalFruitCount: Ember.computed.sum('fruitCountArray')
});

```

Model: **Fruit**

```
export default DS.Model.extend({
  name: DS.attr('string'),
  count: DS.attr('number')
});

```

[Jsbin with working example](http://emberjs.jsbin.com/zukeci/edit?html,js,output). Can someone explain why `totalFruitCount` shows correct amount when page loads, but incorrect when value is updated by using given `{{input}}`. Is it because I’m missing something or it’s just how it works?

As far as I can tell, its something with incorrect type, after value modification `totalFruitCount` show appended array values of `fruitCountArray`. I can easily fix it by implementing my own computed property with **explicit parseInt** (doing exactly same as demo if parseInt isn’t used) such as:

```
totalFruitCount: Ember.computed('fruits,@each.count', function() {
  let sum = 0;
  this.get('fruits').forEach(fruit => {
     sum += parseInt(fruit.get('hours'));
  });
  return sum;
})

```

But it feels wrong to me when there is already computed property just for this use-case. I’m using `Ember 2.3.0` and `Ember Data 2.3.0`.

---

<div class="post-metadata">

### Author: ![Sarath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/sarath/32/12009_2.png) [@Sarath](https://discuss.emberjs.com/u/Sarath)
#### Post date: [February 16, 2016, 6:34am UTC](https://discuss.emberjs.com/t/ember-computed-sum/9786/2 "2016-02-16T06:34:41Z")

</div>

the problem is due to the array construction at

> [@canop](#):
>
> fruitCountArray: Ember.computed.mapBy(‘fruits’, ‘count’),

Find a suitable way to construct a numerical array or do it on your own
