Hello,
I would like to add paranthesis () to the negative values in my field.
Regards,
Sam
Hello,
I would like to add paranthesis () to the negative values in my field.
Regards,
Sam
Within a calculated element, using the following code would give you something similar to what you are looking for. Data Type is 'String'.
Anyone else who knows a better way of doing this?
if ($TestNumber$ < 0)
{
return "(" + $TestNumber$ + ")";
}
else
{
return $TestNumber$;
}
Thanks Jian, for example if my value is for x = -2, I would like to have it as (2). I tried out the solution you posted below to see if I could get brackets, but it gave blanks for my negative values.
Regards,
Sam
OK, I see. I tired the following calculated element in Dundas cube and it gave me brackets for negative values. Data type for TestNumber here is Int32.
Data preview.
Rather than writing script, you can simply format your text using standard .NET formats.
You may achieve this, by editing your measure in the Data Analysis Panel and changing the format in “Configure Metric Set Element” panel.
For instance, to show “-1,400.00” to (-1,400) you may use this format : #,0;(-#,0)
Or, to show -1,400.00 like (1,400) you can use #,0;(#,0) .
Also, you can find further information about .NET formats on this link:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings
one more point to add - if you format your data to show a currency (i.e. use the format C0) it will automatcially show negative currencies in paranthesis.
Thanks every one for the bunch of solutions. When I tried using C0 my currency symbol shifted to left side. When using #,0;(#,0) it got positioned exactly where I wanted.
Regards,
Sam
That is because the symbol placement in currency formatting is defined based on the culture settings of the user. If you are interested in some more information about formatting text, check out the Formatting Text article.