Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a calculated value from smart values formatted as a percentage

Michael Beatty November 17, 2021

I have an automation that creates a percentage by dividing one value by the other.  Right now, I'm multiplying that by 100 to get a "Percentage"

{{#=}}({{issue.Story point estimate}} / {{issue.Story Points}}) * 100 {{/}}

...this works, but the result is somewhat undesierable as it displayes as "33.333"

I would like it to display as a simple percentage, preferably "33.3%"

I see there is a smart value math function documented ".asPercentage".... But I can't figure out how to implement it.  

What I've tried
{{#=}}({{issue.Story point estimate}} / {{issue.Story Points}}).asPercentage {{/}}

{{#=}}{{issue.Story point estimate}} / {{issue.Story Points}}).asPercentage {{/}}

{{#=}}({{issue.Story point estimate}} / {{issue.Story Points}}) * 100 {{/}}.asPercentage

I've also tried to do it in 2 different tasks.  First the math, then a second task to do 

{{issue.percentDone.asPercentage}} - this also doesn't work.

I don't know what else to try.

Thank you for your time.

1 answer

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2021

Hi @Michael Beatty 

You cannot combine the math expression and function format like that.  Instead you could try this: {{issue.Story point estimate.divide(issue.Story Points).asPercentage}}

If you want better control on the display digits, please also take a look at format()

Of note, and a hypothesis: I see you are using both Story point estimate and Story Points, which are the two different fields used for team-managed and company-managed projects, respectively.  These may not be intended to both contain values.  At some point Atlassian may realize the error of their design choice and "fix the glitch", so take care in using both fields.

Kind regards,
Bill

Michael Beatty November 18, 2021

Thank you for the reply Bill.

Your suggestion for the .asPercentage didn't work.  But it did change the error message in the log, it's now saying it "could not convert the field value to a number".  I'm guessing this is because "PercentDone" is a numeric field and the percent symbol the .asPercentage is putting into it is technically alphanumeric?  Any ideas how to get around this.

As to your comment about my usage of Story points.  What I'm doing is using the Story Points as a field to judge how many Story points the task is.  The Story point estimate is the developers estimate as to how may of those story points they have completed.  The math then provides a Percent Done for the task itself.  I could not figure a different way to do this, but if there is a way, I'd love to know.

Thank you again for the reply.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2021

Would you please post images of your complete rule, including details of the variables or math sections?  That may provide some context for that error message.

As for the field errors, if you are trying math on a text (string) field, it can help to add asNumber before doing the math.

For example, if you want to keep that percentage value as number (without the symbol) you could strip it off with .remove("%") before setting the value to the field:

https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields/#Smartvaluestextfields-remove-Stringremove-

Michael Beatty November 18, 2021

Attached is a screen shot.Screen Shot 2021-11-18 at 12.58.04 PM.pngScreen Shot 2021-11-18 at 12.59.56 PM.png

 

Thank you

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2021

Yup, as I suggested the result of asPercentage is text, so to set it to the PercentDone numeric field you will need:

{{issue.Story point estimate.divide(issue.Story Points).asPercentage.remove("%").asNumber}}

Or...you could multiple and round to get an integer value:

{{issue.Story point estimate.divide(issue.Story Points).multiply(100).round}}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events