Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Conditional Formatting Issue in BIRT
aglass
I am trying to put a condition on a table in BIRT Report Designer Professional that can hide the last 5 characters of the measurename if they are equal to a certain code.
I.e. if I have two measures one called 'Alpha' and one called 'Alpha (AA)' I would like to have the ' (AA)' hidden in the output reports.
Is this possible using the functionality in BIRT or is it easier to just create some script? My script knowledge is very limitied so any help would be appreciated.
Find more posts tagged with
Comments
jhelbling
Hello aglass,
You can probably adapt the following script to your need :
"""
if (dataSetRow["COUNTRY"] == "USA")
{
BirtStr.left(dataSetRow["COUNTRY"],2)
}
"""
This script reads the data coming from the Dataset, if the country = USA ... then only US will be displayed ...
I hope it helps you.
mwilliams
Hi aglass,
Can you exlain this a little further? Where will the code "Alpha" come from that you'll compare to the header name? And yes, script is most likely going to be the place where you change this. Let me know more about what you're comparing and a little about what your data looks like and I'll try to help!
aglass
<blockquote class='ipsBlockquote' data-author="'jhelbling'" data-cid="69645" data-time="1287758291" data-date="22 October 2010 - 07:38 AM"><p>
Hello aglass,<br />
<br />
You can probably adapt the following script to your need :<br />
<br />
"""<br />
if (dataSetRow["COUNTRY"] == "USA")<br />
{<br />
BirtStr.left(dataSetRow["COUNTRY"],2)<br />
}<br />
"""<br />
<br />
This script reads the data coming from the Dataset, if the country = USA ... then only US will be displayed ...<br />
<br />
I hope it helps you.<br /></p></blockquote>
<br />
<br />
Hi jhelbing,<br />
<br />
That does look very close to what I actually need in terms of script but I really need it to not show the last 5 characters rather than the first 2 as this script seems to suggest. This is because the different measures (ie COUNTRY) will be different lengths (like having England and USA)<br />
<br />
@ MWilliams The data is coming from a data set which has been built using an SQL database. I am not comparing to the header row I just need the code on the end of 'Alpha (AA)' for maintenance purposes but for users of the final report I want them only to see 'Alpha' as the name of the measure.
jhelbling
Hi aglass,
In this case the following should work in order to keep the last 5 characters :
""
if (dataSetRow["COUNTRY"] == "USA")
{
BirtStr.right(dataSetRow["COUNTRY"],5)
}
""
aglass
Hi jhelbling
Thanks for the above. However I am trying to NOT keep the last 5 characters if they happen to equal ' (AA)'
If they don't exist (as is the case for some of the measures) then I don't want anything to the name.
As an example -
If 2 measures are present - Alpha and Alpha (AA) then the final output report should show:
Alpha
Alpha
Hope this makes things clear and you can still help me?
jhelbling
Hi aglass,
Ok if you want to remove the last 5 characters you will need to do something similar to :
""
if (dataSetRow["COUNTRY"] == "USA")
{
BirtStr.left(dataSetRow["COUNTRY"],BirtStr.charLength(dataSetRow["COUNTRY"])-5)
}
""
The charLength function returns the number of characters in a string. In the code above, if you have the following string : "abcdefgh" ... you will get :
abcdefgh = 8 chars -> 8-5=3 -> only the first 3 chars will be displayed.
Of course you will maybe need to adapt the 'if' condition in order to ensure you modify the right strings.
I hope it helps.
aglass
thanks jhelbling this seems to be exactly what I want.
aglass
Hi jhelbling,
I just had one more question regarding the if function as as I said earlier my script writing really isn't upto much.
I want the script to say:
if (dataSetRow["COUNTRY"] last 5 characters = " (AA)")
{
BirtStr.left(dataSetRow["COUNTRY"],BirtStr.charLength(dataSetRow["COUNTRY"])-5)
}
if not (dataSetRow["COUNTRY"] == "USA")
What would I need to replace 'last 5 characters = " (AA)") with on the first line of the script?
Many thanks for your help
jhelbling
Hi aglass,
The following should do the trick :
""
if (BirtStr.right(dataSetRow["COUNTRY"],5) == "AA")
""
aglass
Thanks again jhelbling you have solved my problem perfectly
aglass
Hi jhelbling,
I have had another request regarding this data and now have multiple codes on the end the names (I.e. " AA", " BB", " CC", etc. I want to edit the code below so that if any of the codes are displayed it will not show the last 5 characters. How would I go about editing this script to show this?
I want the system to look to see if " AA" OR " BB" OR " CC" is present and if so follow the script on line 3 and if not do nothing to it.
1 if (BirtStr.right(dataSetRow["COUNTRY"],5) == " AA")
2 {
3 BirtStr.left(dataSetRow["COUNTRY"],BirtStr.charLength(dataSetRow["COUNTRY"])-5)
4 }
Any help you can offer will be greatly appreciated,
Tony
jhelbling
Hello aglass,
The following should work :
"""
if (BirtStr.right(dataSetRow["COUNTRY"],5) == " AA" || BirtStr.right(dataSetRow["COUNTRY"],5) == " BB" || BirtStr.right(dataSetRow["COUNTRY"],5) == " CC")
{
BirtStr.left(dataSetRow["COUNTRY"],BirtStr.charLength(dataSetRow["COUNTRY"])-5)
}
"""
The || is the OR operator, if you need an AND operator, you can use && .
I hope it works.