Please or Register to create posts and topics.

Display subreport data in columns, not rows

Hi,

this problem first looked like a crosstab solution to me, but not quite: I would like to display data that is currently in a subreport (1 row per subdata set) to be "transposed" so that each subdata set is in a separate column, see sections highlighted in yellow in the screenshots.

There is no fixed number of subdata sets, but up to now there is a maximum of 6 per data set.

The report will be optimized for Excel output only, so page width is not really an issue.

Thanks for any ideas!

Uploaded files:
  • Current.PNG
  • New.PNG
Gustaf Folger has reacted to this post.
Gustaf Folger

Hello lekrof,

Could you specify what kind of data source you are using? Also, will your columns always contain a fixed number of rows or can they vary?

Hi Gustav,

It's an Oracle database, one table for product characteristics, another one for the substance properties. Primary key is a substance code in both tables.

... at the moments, there is a fixed maximum number of rows = substances per product, but there may be more in the future.

Alright, there's a few possible solutions here. You could derived table using a subquery and create a field for each value in each column.  You can use print when statements to check for null values to not include columns.

I'm attaching an example of what this could look like. This could be a lot of manual labour but if the final product looks like your example then it should be manageable. If your tables grow then you will need to manually add more rows to your query.

Given you are using oracle it should also be possible to use a pivot query but I don't have a test database currently so I can't really show an example currently.

The best solution would likely still be a crosstab though. How come that doesn't work for you?

Uploaded files:
  • 2025-08-11-15_14_42-DBeaver-25.0.0-_foodmart-db_-Script-4.png

Hi lekrof.

I moved that issue to "standard Jasperreports Questions"...

Regarding your question: why exactly does a Crosstab not work for you? That would be an interesting question to be answered, before searching for alternate solutions in SQL or report structure, which are propably all not easy nor dynamic...

Thanks in advance,

Thomas

@ Gustaf and Thomas: Thanks a lot!

I will try the crosstab option first and report back asap..