phantastes Posted December 16, 2010 Share Posted December 16, 2010 Hi,Would anyone know how to achieve the following in iReport: Row Value1 111112 222223 333334 44444Group Total: 11111,22222,33333,44444 I need to take the value in each record and concatenate this value to the previous value, creating a comma separated list that will be displayed at the bottom of the group. Is this even possible. I'm guessing I need to handle this with a Variable somehow.Any ideas or suggestions are very welcome!Thank you Link to comment Share on other sites More sharing options...
cbarlow3 Posted December 16, 2010 Share Posted December 16, 2010 I had a little success with creating a string variable that concatenates a string value from each detail. Here's my mostly useless SQL command I used to generate the test data without having to worry about connecting to any real data in my database:WITH sampleValues (value) AS (Values ('11111'), ('22222'), ('33333'), ('44444'))SELECT sampleValues.value as valueFROM sampleValuesI then created a variable called $V{AllDetails} as data type String with a value expression of $V{AllDetails}+$F{VALUE}+','I dragged that variable onto the summary band and got:11111,22222,33333,44444,The final comma is annoying, of course, but my first few attempts to get rid of the final comma were unsuccessful. I thought of a few approaches, but can't get them to work without more tinkering.Carl Link to comment Share on other sites More sharing options...
phantastes Posted December 16, 2010 Author Share Posted December 16, 2010 Hi Carl,Thank you for that quick reply!Would you be able to expand a bit on what you set the other Variable properties to, such as the calculation etc. All the best,Magnus Link to comment Share on other sites More sharing options...
cbarlow3 Posted December 16, 2010 Share Posted December 16, 2010 Sorry, I was originally going to post the JRXML, but that might be overkill in this case. I set Variable class to java.lang.String, Calculation to Nothing, Rest type to Report, Increment type to None, Variable Expression to $V{AllDetails}+$F{VALUE}+',', and Initial Expression to "" (two double quotes next to each other with no space in between). I find that if I don't initialize it, it outputs:null11111,22222,33333,44444,Carl Link to comment Share on other sites More sharing options...
phantastes Posted December 16, 2010 Author Share Posted December 16, 2010 Thanks,I'll give that at try after this meeting. Link to comment Share on other sites More sharing options...
phantastes Posted December 16, 2010 Author Share Posted December 16, 2010 That's awesome! It worked.I also added a check to make sure not to add duplicate numbers, plus making sure there is no comma at the end: Thank you so much for you help!Magnus Code:$V{idList}.equalsIgnoreCase("")?$V{idList}.contains($F{id}+"") ? $V{idList}:$V{idList}+$F{id}:$V{idList}.contains($F{id}+"") ? $V{idList}:$V{idList}+","+$F{id} Link to comment Share on other sites More sharing options...
srkr Posted March 5, 2015 Share Posted March 5, 2015 Used the below code.. it will elimates the duplicates.. ($F{Id} == null || $F{Id}.equalsIgnoreCase("")) ? $V{Idlist} : $V{Idlist}.equalsIgnoreCase("") ? $V{Idlist}+$F{Id}+"," : ($V{Idlist}.contains($F{Id}+","))? $V{Idlist} : ($V{Idlist}+$F{Id}+",") Also to remove comma at end we can change the Text Field expression to $V{Idlist}.substring( 0, $V{Idlist}.length() -1) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now