Pentaho Lab
Pentaho Lab
New Report − If you choose this option, then you can create customized reports based on your requirement.
Pentaho has a set of sample reports to help you figure out how to use a certain Report Designer. The following
screenshot shows the welcome page of Pentaho.
The Palette
The palette contains all the elements that you can use to build a report. To add an element, click on a layout band to
select it, then drag and drop an element from the palette to the selected band. We have explained the role of each of
the report elements in the following table.
Element icon Element name Description
Resource-Field Dynamic text string that maps to a resource bundle, allowing you to
localize any database field.
Resource - Message Dynamic text string that concatenates data from multiple types, and
dynamically maps to a resource bundle.
Take a look at the following screenshot; the highlighted box on the left side is the palette of reporting elements.
Follow the steps given below to create a report from scratch without using Report Design Wizard.
Step 1 : Create a New Report
You can create a new report definition file by clicking "new report" on the welcome pane or go to "File → new".
In the Data tab, right-click on the Data Sets and select JDBC to add a data source. Generally, in the list of options, you
can select any other option based on the requirement. It means, if you have an XML file as your data source, then
choose XML option from the list. Take a look at the following screenshot. Here we are selecting the JDBC option to
add a database as data source.
After having selected the JDBC option as the data source, you will find a dialog box as shown in the following
screenshot.
We have already chosen MySQL database for the data source, therefore we have to select the SampleData
(MySQL) option in the left-side panel of the dialog box (marked as pointer "1") in the given screenshot. Pointer "2" is
meant for editing the connection statement and URL to interact with the database.
The following screenshot shows a dialog box where you can define your connection statement and the URL for the
database. We need to carry out four operations on the following screen (which are highlighted using pointers).
In the connection type list, select MySQL − We have already chosen MySQL as the database (data source).
In the Access list, select Native (JDBC) − Through JDBC connection, we can access the database.
In the Settings section, we must mention the Host Name (localhost), Database name (employeedb), port number
(3306), username (root), and the password (as per you system).
Test the connection statement by clicking the Test button.
Finally, click the OK button to confirm the database connection.
While clicking the “+” button, you can create a query by editing a name on the Query Name block
as select_all_records and use the following query statement in the Query block.
SELECT
employee.id,
employee.name,
employee.designation,
employee.department,
employee.age
FROM
employee
LIMIT
15
After adding the query, you should get the following dialogue box. Click the preview button.
After clicking the preview button, you will find all the employee table records in a separate dialog box as shown in the
following screenshot. Click the close button.
Then, click the OK button to submit the query. After submitting the query, you will find all the table field names and
their datatypes under the query name on the right-side structure pane, as shown in the following screenshot. Here, the
maximized box is the structure pane which is placed on the right side of the screen.
After adding the query to the Reporting designer, the resultant fields appear in the data pane, as shown in the
following screenshot.
Now, drag the required fields (fields you want to display in the report) from the Structure Pane into the Details Band at
the center of the main workspace.
Take a look at the following screenshot. It shows the direction to drag the age field from the structure pane.
Now, if you want to go back to the design mode, then click the Design symbol marked as “1” in the following
screenshot.
The page footer tab is used to present some attributes and functions. For example, you can use the page footer tab
to print the max value of the age field at the bottom of the page. The reporting engine allows these features by
using reporting functions.
Take a look at the following screenshot. Here the Data tab in the structure pane includes a symbol fx (marked as “1”).
It is the add function button. Click this button to add different functions into the report.
Then, you will find a dialog box with different functions segregated into different groups. To print the maximum age of
an employee at the page footer, we should choose the Maximum function in the Summary group which is marked as
“1” in the following screenshot. Select it and click OK.
Once you click the Ok button, the function will be added to the Functions label in the Structure Pane which is placed at
the right side of the screen.
Once you select the added function (i.e. Maximum), you will find another pane below the structure pane containing the
properties of that function.
Take a look at the following screen. The maximized box contains two pointers (Pointer 1 and Pointer 2).
Pointer 1 − Select the function in the data tab of the structure pane.
Pointer 2 − Edit the Field name in the properties section by selecting the age field from the dropdown list. It is
because we have to print the maximum age of an employee.
Now, the function is ready with the customized properties. Now you can use that function in your report as a page
footer attribute.
Take a look at the following screenshot. Again, it contains two pointers (Pointer 1 and Pointer 2).
Pointer 1 − Select and drag the Maximum function from the Structure pane to the page footer band in the
workspace, as shown in the following screenshot. Now the design of your report is ready.
Pointer 2 − Select the Preview button on the left side of the screen.
Take a look at the following screen. It shows the preview of the report. The maximum age of an employee is marked
and shown in a maximized box.
Pentaho - Groups
Pentaho offers various functionalities and features to convert raw data into meaningful information. Here, we will learn
how to use one such feature Groups. You can use this feature to segregate raw row-set data into groups so that the
user can easily understand the report.
Grouping is a great way to divide long lists of data along meaningful separators.
With groups, you can keep similar items together and visually separate these items from other groups of items.
You will also need groups to perform various aggregations over the data, like printing the number of items in a
group or calculating sums or averages.
We already have a report based on the employee data. Here the query is to group all employee records according to
"department". Follow the procedure given below to fulfill the given requirement.
First of all, you start the process by clicking the Add group button on the Structure pane. The Add group button is
marked as "1" in the following screenshot.
You will get a list of options by clicking the Add group button. Then, click the Add group option from the list.
After clicking Add Group, you will find a dialogue box using which you can add a group field from the given available
fields.
After adding the group, you will find it in the Structure tab of the Structure pane. And you will find the Group
Header and Group Footer bands in the workspace.
Take a look at the following screenshot. Add a static label to your report by dragging the label icon from the palette on
the left side of the Report Designer into the group header (in the screenshot, this activity has been marked as “1”).
By double-clicking the label, you can edit it and change the name to Department. By using the Formatting Toolbar or
the Formatting Palette (marked as "3" and "4" respectively), you can change the format of the label.
Let us now proceed further. Switch the Structure pane to Data tab. Select and drag the department field from the
Structure pane to the Group Header (this activity is marked as “1” in the following screenshot). To see a preview of
your report, click the preview button on the left side of the screen which is highlighted and marked as “2” in the
following screenshot.
After clicking the preview button, you will find the result report as shown in the following screenshot. You will find the
records have now been grouped together according to department.
The report does not look very appealing at this stage. You can add a touch of color and make the heading more
effective using the Formatting Toolbar or the Formatting Palette.
You are now ready to generate different types of reports using Pentaho. Just follow the steps discussed so far and try
to use all the features and options available in Pentaho.
Fiat 1 3 5 5
Audi 5 6 10 4
Ford 4 2 3 6
First of all, create a table named car based on the given table data. We are using MySQL database as the data
source. Add that (data source) to the Pentaho Reporting Designer. We have already discussed how to add a data
source and a query to the Pentaho Reporting Designer in the chapter "Pentaho – Data Sources and Queries".
The Details tab presents only the field values. Add those respective heading Labels to the Report Header tab by
selecting the label field from the palette.
Add an image taken from the palette and place it on the Page Header Tab. Add another label in the Page
Header for Report Heading and use a suitable heading, for example CAR – CHART, for effective presentation.
Double-click on the image element – you will find a dialogue box called Edit Content.
You have two options to insert an image. Either link the image URL to the report or embed the image into the
report. We chose to embed the image by selecting the option “Embed in Report”.
Download some sample car image from the internet to put into the Page Header. Click on the button to locate
the sample car image with the location URL. Click the OK button to confirm.
There are three sections in the Primary Data Source − Common, Series, and Group. Here, we don’t require to add
anything on the Groups section because we are not using any Groups in our query.
Common − There are two fields in this section − category-column and value-column. We already filled the
category-column value with the name field in the above section. The second one is value-column.
Click on the empty value; you will find a dialogue box as shown in the following screenshot. There are two activities (1
and 2) marked in it.
Click the (+) button to add the value fields in the column.
By clicking on the empty value, you will find a dropdown list from where you need to select the speed field.
Repeat the above two activities to add user_rating, mileage, and safety fields into the column. After adding all these
fields, the screen will appear as shown below. Click OK to confirm.
The next column in the Primary Data source section is the Series section.
Series − In the Series field, click the series-by-value option. You will find a dialogue box as shown in the following
screenshot. There are two markers (1 and 2) in it.
After adding all the sections, you will get the Edit Chart dialogue box as shown in the following screenshot. The Bar
Chart pane contains different properties which are used for changing the chart format.
In the General section of the Bar Chart, we have changed the 3-D value as true (marked as "1"). Click OK to confirm
the chart properties.
Click on the Preview button on the Formatting Toolbar to see a preview of the report. It will appear as shown in the following
screenshot −
You can implement different types of charts in your report by using different types of data models and by providing
different values to the chart properties. Pentaho provides almost 18 types of charts in the report designer.