# 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:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karim\_Masarweh](https://community.eazybi.com/user_avatar/community.eazybi.com/karim_masarweh/32/3248_2.png) [@Karim\_Masarweh](https://community.eazybi.com/u/Karim_Masarweh)\
**Post date:** [June 23, 2020, 10:55am UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/1 "2020-06-23T10:55:00Z")

</div>

Hi there

We are using eazyBI with JIRA. Our Epics have features, and features have user stories.  
I need to calculate the number of USs that exist under epics which have specific values that are being selected in the page section.  
The filters include the following 2 dimensions: [Target PI] and [Label]

I have written the following measure to check based on selected Target PI but it’s taking ages to execute (I guess it’s because it’s going through all USs in the system):  
Count(  
Filter(  
Descendants([Issue.SAFe].CurrentHierarchyMember, [Issue.SAFe].[User Story]),  
[Issue].CurrentHierarchyMember.Parent.Parent.get(‘Target PI’) = [Target PI].CurrentMember.Name  
)  
)  
Is it correct to write it this way? Can you advise how to make this more efficient?  
And how can I add a condition to filter the epics so to only those that have Label “XYZ” ?

Thanks a million

---

<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

---

<div class="post-metadata">

**Author:** ![Karim\_Masarweh](https://community.eazybi.com/user_avatar/community.eazybi.com/karim_masarweh/32/3248_2.png) [@Karim\_Masarweh](https://community.eazybi.com/u/Karim_Masarweh)\
**Post date:** [July 23, 2020, 6:41am UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/3 "2020-07-23T06:41:30Z")

</div>

Thank you very much for this suggestion.  
We’ll definitely try it as it’s not possible to work with the current performance.

---

<div class="post-metadata">

**Author:** ![galitkl](https://community.eazybi.com/letter_avatar_proxy/v4/letter/g/67e7ee/32.png) [@galitkl](https://community.eazybi.com/u/galitkl)\
**Post date:** [July 23, 2020, 12:40pm UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/4 "2020-07-23T12:40:12Z")

</div>

Hi, I have used this code and I get an error.  
code:  
[jira.customfield\_commitment\_inherited]

name = “Commitment Level Inherited”

data\_type = “string”

dimension = true

javascript\_code=’’’

if (issue.fields.customfield\_17500 && issue.fields.customfield\_17500.value) {

issue.fields.customfield\_commitment\_inherited=issue.fields.customfield\_17500.value;

}

‘’’

update\_from\_issue\_key = “epic\_key” ## use the correct id of the upper hierarchy level

[jira.customfield\_technical\_epic\_inherited]

name = “Technical Epic Inherited”

data\_type = “string”

dimension = true

javascript\_code=’’’

if (issue.fields.customfield\_17726 && issue.fields.customfield\_17726.value) {

issue.fields.customfield\_ technical\_epic\_inherited=issue.fields.customfield\_17726.value;

}

‘’’

update\_from\_issue\_key = “epic\_key” ## use the correct id of the upper hierarchy level

Error:  
JavaScript code raised the following error:  
missing ; before statement

Can you please advice what did I do wrong?  
My intention is inheriting the customize data on the epic (Commitment Level and Technical Epic) to all children (stories, tasks, sub-tasks)

---

<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 24, 2020, 2:02pm UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/5 "2020-07-24T14:02:32Z")

</div>

Please, send the details to support email for more detailed checking.  
An additional screenshot of where the settings are added would be helpful.

Kindly,  
Janis, eazyBI

---

<div class="post-metadata">

**Author:** ![ivera](https://community.eazybi.com/user_avatar/community.eazybi.com/ivera/32/6583_2.png) [@ivera](https://community.eazybi.com/u/ivera)\
**Post date:** [March 3, 2022, 8:19pm UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/6 "2022-03-03T20:19:17Z")

</div>

Hi! I’m having problems with this script

```auto
[jira.customfield_mpc_e]
name = "Epic MPC Type name" 
data_type = "string"
dimension = true
update_from_issue_key = "epic_key"
javascript_code = '''
if(issue.fields.customfield_17704 ) {
   issue.fields.customfield_mpc_e = issue.fields.customfield_17704;
}
'''

```

error: Execution of custom JavaScript code raised the following error:  
unterminated string literal

Anyone knows why?

---

<div class="post-metadata">

**Author:** ![Emanuela\_Bauleo](https://community.eazybi.com/user_avatar/community.eazybi.com/emanuela_bauleo/32/12274_2.png) [@Emanuela\_Bauleo](https://community.eazybi.com/u/Emanuela_Bauleo)\
**Post date:** [September 30, 2024, 3:22pm UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/7 "2024-09-30T15:22:33Z")

</div>

> [@janis.plume](#):
>
> 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:
> 
> ```auto
> [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
> 
> ```

Hello @janis.plume ,

I tried using the code you provided to inherit Epic Labels, but it didn’t work. When I test with an Issue, I get the labels of the current issue and not the labels related to the parent epic :

 ![Screenshot_2](https://community.eazybi.com/uploads/default/original/2X/c/c7eca37779578f36fbb8fd817390147203efcb4d.png)

In my example, I get empty set while the Epic label is set to “MC14”.

For context, I am using a new calculated field in the import settings since I do not have admin rights to change eazyBI advanced settings.

Thanks in advance for your help.

Best regards,  
Emanuela

---

<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:** [October 8, 2024, 8:30am UTC](https://community.eazybi.com/t/calculating-total-user-stories-based-on-epics-fields/4735/8 "2024-10-08T08:30:14Z")

</div>

Hi,

This solution cannot be fully visible in the testing form.  
The update form issue key process runs after the main data import is completed, so, please run the data import in eazyBI and check the results in the report.

Kindly,  
Janis, eazyBI support
