# Calculating Total user stories based on epics fields

**URL:** <https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735>\
**Category:** Questions & Answers\
**Tags:** calculatedmembers\
**Created:** [June 23, 2020, 10:55am UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735 "2020-06-23T10:55:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![janis.plume](https://community.eazybi.com/user_avatar/community.eazybi.com/janis.plume/32/8826_2.png) [@janis.plume](https://community.eazybi.com/u/janis.plume)\
**Post date:** [July 1, 2020, 6:38am UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/2 "2020-07-01T06:38:58Z")

</div>

Hi,

The formula is generally correct for counting the Stories having the Target PI of grandparent matching the PI from the report context. You are also right that this approach has a significant risk of performance problems.

There are a couple of techniques to make such calculations more efficient. First, it is possible to define a new [Javascript calculated custom field](https://docs.eazybi.com/eazybijira/data-import/custom-fields/javascript-calculated-custom-fields) that would inherit down the Target PI from the upper level of the hierarchy down to the User stories. This approach is limited to work with the single value custom fields in Jira.

You can add to the [advanced settings](https://docs.eazybi.com/eazybijira/data-import/custom-fields/advanced-settings-for-custom-fields) of eazyBI the lines like this:

```
[jira.customfield_cf_inherited]
name = "Target PI Inherited"
data_type = "string"
dimension = true
javascript_code='''
if (issue.fields.customfield_NNNNN ) {
  issue.fields.customfield_cf_inherited=issue.fields.customfield_NNNNN
}
'''
update_from_issue_key = "epic_key" ## use the correct id of the upper hierarchy level

```

You need to use the custom field ID instead of NNNNN and the correct name of the level ID instead of the “epic\_key”. Once you import this field as a dimension, the simple filtering in the report pages should do the count (you may also add the Issue type filter in the report).

In the case of the Labels, it is possible to create a similar construction using the [Issue link field dimension](https://docs.eazybi.com/eazybijira/data-import/advanced-data-import-options/issue-link-field-dimensions).  
You can see a similar example of configuration here:  
[https://docs.eazybi.com/eazybijira/data-import/advanced-data-import-options/issue-link-field-dimensions#Issuelinkfielddimensions-FeatureLabel](https://docs.eazybi.com/eazybijira/data-import/advanced-data-import-options/issue-link-field-dimensions#Issuelinkfielddimensions-FeatureLabel)

Kindly,  
Janis, eazyBI support

---

_[View the full topic](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735)._
