tags:

views:

791

answers:

4

Hi,

A newbie question which I could not find an answer to.

I have a report containing a table holding several items that have a "Time" Column. I would like to group the items by time so that all items of the same month will be grouped together.

To do this I have to extract the month/year out of the "Time" String (format is "17:22 19/07/09") and use that for grouping. I know how to do all this in Java and I think BIRT offers several ways to do this but I couldn't manage to find an easy way to do this.

If there's a good tutorial on this I'd love to check it out.

Thanks!!

A: 

Does the report parameters bit here which includes datetime parsing help you?

http://www.eclipse.org/birt/phoenix/deploy/viewerUsage.php#parameters

Paul McMillan
A: 

I have a sample report on the BIRT Exchange DevShare that does this exact thing. YOu supply it a Regular expression (as simple or complex as you need) and it will use the match of the RegEx to create groups.

http://www.birt-exchange.org/devshare/designing-birt-reports/746-create-a-dynamic-group-by-extracting-a-substring/#description

Good Luck!

MystikSpiral
+1  A: 

We've done it as follows. In our SQL query for the data set, we select both (for example) "char(my_date,iso)" and "left(char(date,iso),7)" (for 2009-01-05 and 2009-01 respectively), something like:

select
    left(char(my_date,iso),7) as isoyyyymm,
    char(my_date,iso) as isodate,
    otherfield as value
from tbl
order by my_date

Then, when you create your table in the report, column 1 should be the grouping column based on isoyyyymm and blank out for that column in the table:

  • the heading,
  • the group data line; and
  • the detail data line.

So you end up with, in the designer:

+--------------------------------+-----------+-----------------+
| <Header row>                   | Date      | Value           |
+--------------------------------+-----------+-----------------+
| <Group header row (isoyyyymm)> |           |                 |
+--------------------------------+-----------+-----------------+
| <Detail row>                   | [isodate] | [value]         |
+--------------------------------+-----------+-----------------+
| <Group footer row (isoyyyymm)> |           | Total.sum(      |
|                                |           |   row["value"], |
|                                |           |   null,         |
|                                |           |  "Grp1")        |
+--------------------------------+-----------+-----------------+

The report table will still group on the month but the displayed detail lines will all contain the full date:

Date         Value
----------   -----

2009-01-01       7
2009-01-08       2
2009-01-15       1
2009-01-22       4
             -----
                14

2009-02-05       2
2009-02-12       0
2009-02-19       0
2009-02-26       1
             -----
                 5

You can group on intervals if you want to do it that way but we've opted for the simplest approach for those situations where we can use simple strings. Obviously, if your interval is a week (or something else not amenable to simple string analysis), you'll need to use the interval grouping built into BIRT.

The best tutorial for this (in my opinion), is on page 187 (in chapter 12) of BIRT, A Field Guide to Reporting. That, and Integrating and Extending BIRT are must-haves for any serious BIRT user.

This first is absolutely vital to any report designer. The second covers much more advanced topics such as embedded Java and Javascript, the report object model and the underlying architecture of BIRT. This is required if you want your reports to be truly spectacular.

paxdiablo
A: 

This can be done with the group setting in the table itself. How to create groups is described in http://www.eclipse.org/birt/phoenix/tutorial/basic/basic06.php (btw., searching for 'birt table group' in Google gices this as the first hit). In this case you can do it like that:

  • Right-click on the row header for the state group header and a context menu will be displayed.
  • From the context menu choose Insert Group→Below. The Group Details dialog appears.
  • Chose the "Time" column in the Group On field and type Time in the Name field.
  • Select 'month' in the Interval combobox
  • Click OK.

This creates a grouped table without any SQL or JS fiddling.

Eyck Jentzsch