Get the percentage of the Dataset Column using Script Transform

Your numberFormat function doesn't work and if it did it wouldn't do anything because you haven't assigned it to anything (with an = operator).

Try this:

sum = value[0][1] / val
return "{:.2%}".format(sum)

Or simplify it down to one line:

return "{:.2%}".format(value[0][1] / val)

The funky Python notation tells it to format with 2 digits after the decimal point and show as a percentage. It will then automatically multiply by 100 for you.

Tips:
Post code - not pictures of code (unless you need to show the context of the code). See Wiki - how to post code on this forum.
Leave a little air in your expressions. So, compare,
sum = (value[0][1]/val)*100
sum = (value[0][1] / val) * 100
It's a personal preference but I consider the mathematical operators as separate words and so should have a space each side.

2 Likes