Pages

Monday, January 20, 2014

Exporting PRPT from saiku adhoc Reporting.

As we all know saiku is a thin client plugin tool which we use to generate Analysis and Adhoc Reports on the top of BI server.

When we create saiku ad-hoc reports using ad-hoc plugin there is an option of exporting PRPT file to BI server so that we can save the adhoc report for the future use. But when we click on export button eventually we come to know that we are unable to save the report.

When I did some R&D, I came to know that there is a missing jar in WEB-INF/lib in tomcat folder under pentaho BI server. so simply copy jar "pentaho-reporting-engine-classic-extensions-cda-5.0.1-stable.jar" from Pentaho report designer's lib folder and paste it to WEB-INF/lib folder and then restart the server, now u will be able to save/export the report. :)

Thursday, January 16, 2014

How to conditionally hide the column in pentaho report designer

The requirement is to hide a column and it's label if data in that column is null.

Contional hide of report element:-
To hide report elements based on certain conditions, we can define a formula under 'Style' -> 'visible'.
One interesting use case is to hide the labels of the report if no data is returned.
For example, to hide all labels of the report if the field 'field1' has a null value:
  • Add a sub-band on the report and insert the labels that you want to hide in the sub-band. Thus we will not have to define the same formula for each label, but rather only for the sub-band.
  • Highlight the sub-band and go to 'Style' -> 'visible' properties.
  • Add the following formula
    =IF(ISNA([field1]);"False";"True")
We could also hide the report elements based on whether we have entered a value for a user parameter or not.

  • Highlight the report element and go to 'Style' -> 'visible' properties
  • Enter the below formula
    =IF(LEN([param1])=0;"False"; "True")
    where param1 is the parameter name.

How to call stored procedure in pentaho report designer.

How to call stored procedure/kettle files in Pentaho designer?

There are two ways of running the stored procedures
If the procedure returns a resultset, then you can use the result like any other query in the report-designer by calling it via
"CALL procedure(${parameter1},${parameter2})"
However, if your procedure just returns a single value and you want to combine that value with results from other procedures or queries, then you have to use Pentaho Data Integration.

Using Message Field and Formatting Date field in message as required

Using message fields

Message Fields let you mix dynamic and static text, sort of like a combined Label and Text Field. Here's an example:

The date is $(report.date, date, d MMMM yyyy)
This will show in the report as:

The date is 6 November 2008
The first part ("The date is") is static. The variable afterwards has three sections:

  1. The field to use. Here we are using the internal function 'report.date' to give the current date, but you could also use a field from the database query.
  2. The data type. This data is of type 'date'.
  3. The format in which to display the data.

Calculate Date Example

Sometimes it is very useful to use a calculated earlier date (e.g. yesterday, a month ago) as a default parameter value on a report. For example, if you want a report to run every day for the previous day, you might want to add a calculation of 'yesterday' for the default value of the parameter.

Implementation Steps

To calculate 'yesterday' in the report designer use the following formula in the 'default value formula' or 'post processing formula' of the parameter:

=DATEVALUE(DATE(YEAR(TODAY()-1);MONTH(TODAY()-1);DAY(TODAY()-1)))
To calculate '12 month ago' in the report designer use the following formula in the 'default value formula' or 'post processing formula' of the parameter:

=DATEVALUE(DATE(YEAR(TODAY());MONTH(TODAY())-12;DAY(TODAY())))
 
Here is the oiginal Post
1 Format Date with Date Picker
#startfloatingbox()
*Contents:* \\
#toc("2" "6" "false")
#endfloatingbox()
The default date picker in the Pentaho Report Designer, displays the date in the date-time format 'yyyy-MM-dd HH:mm:ss:SSS' by default. If you would like to change the way the selected date is displayed in the date picker, use 'Data Format' under the parameter definition. You can define, for example dd/MM/yyyy.
This will only change the display format on the date picker when the user makes a selection but not the value of the selected parameter.
Often, you will need to format the value of the parameter to match with the format in your database to be able to use the parameter in your SQL query. Here is one way to do it.
1.1 Implementation Steps
* Create another parameter (e.g. $Formatted)
* If you do not want this parameter to be displayed to the user, tick the box 'hidden'.
* Define the 'Post-Processing Formula'. You can use any formula expression there. For the given use case, we recommend to use the MESSAGE() function.
Here is a sample code that will format the date from 'yyyy-MM-dd HH:mm:ss:SSS' (defined in the parameter $today) to 'yyyy-MM-dd'.
{code:none}
=MESSAGE("{0,date,yyyy-MM-dd}"; [$today])
{code}
You can download a sample prpt file {attach:here|demoDateFormatting.prpt}
This is how your $Formatted parameter can be defined:
{image:Screenshot.png}

1.1  Download Sample
*You can download a sample prpt file {attach:here|demoDateFormatting.prpt}.*
1.1 Resources
* [Pentaho wiki>http://wiki.pentaho.com/display/COM/February+3%2C+2010+-+Pentaho+Reporting+3.6+overview+and+demo>_blank] - some videos on Report Designer

Friday, May 10, 2013

how to use the logged in user in query with report designer and show user specific report.

Many times we need to design the reports which consist of data according to the user logged in. One can not show whole information to everyone, what we need to do is show the report accordingly. So here I am going to describe how to generate the report as per the user logged in.

         For getting information of user logged in we need ENVIRONMENT variable which are available from the release PRD 3.6. with the help of Environment variable we can get many information like Role, username, pentaho base url, server base url and so on. For more details on ENV variable available in PRD you can refer to these blog http://www.on-reporting.com/blog/access-session-and-environment/ and
and you can also refer to this video to get to know other details of Latest feature of PRD 3.6

Now I will take you through the details of how to use ENV variable env::username. First of all we need a database schema to make the report. I have made the schema usermaster having 3 tables:-
  1. user 
  2. products
  3. user_product_consumption
I am also providing you the create and insert MySQL query so that you will get the example easily without taking care of designing your own table.

create database usermaster;
use usermaster;

create table sampledata.user(userid int primary key,username varchar(45));

create table sampledata.products(productid int primary key,productname varchar(45));

create table usermaster.user_product_consumtion(id int primary key, userid int, productid int, foreign key (userid) references user(userid),foreign key (productid) references products(productid));

-- Insert user value

insert into usermaster.user values(1,'joe');
insert into usermaster.user values(2,'suzy');

--insert products value

insert into products values(1,'Milk');
insert into products values(2,'Coffee');
insert into products values(3,'Sugar');

insert user_product_consumption value

INSERT INTO `usermaster`.`user_product_consumption` (`id`,userid, `productid`) VALUES (1, (select userid from user where username='joe'), (select productid from products where productname='milk'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (2, (select userid from user where username='joe'), (select productid from products where productname='coffee'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (3, (select userid from user where username='joe'), (select productid from products where productname='sugar'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (4, (select userid from user where username='suzy'), (select productid from products where productname='coffee'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (5, (select userid from user where username='suzy'), (select productid from products where productname='sugar'));

Please note that for using env::username and to show the report according to the user logged in you should maintain the username same as available in Pentaho i.e. 'joe', 'suzy' etc. you can add your own username and give them different roles from Pentaho Administration Console as required. for details you can visit to the following link

Now back to the business, we will design report by 3 tables I have described above. First of all we will define the report query which is as follows :-
SELECT
     `user`.`userid`,
     `user`.`username`,
     `products`.`productid`,
     `products`.`productname`,
     `user_product_consumption`.`id`,
     `user_product_consumption`.`userid`,
     `user_product_consumption`.`productid`
FROM
     `user` INNER JOIN `user_product_consumption` ON `user`.`userid` = `user_product_consumption`.`userid`
     INNER JOIN `products` ON `user_product_consumption`.`productid` = `products`.`productid`
After Defining the query add  the parameter and give the values to the windows that appeared like parameter name, type, Default value formula, check the Hidden value and define the display type of parameter as Text box.
Default value formula should be like this ENV("username"). after doing this press ok, now you are done with defining parameter now rectify the query to use the parameter value. Add where clause to the report query and your final query should be like this:- 

SELECT
     `user`.`userid`,
     `user`.`username`,
     `user_product_consumption`.`id`,
     `user_product_consumption`.`userid`,
     `user_product_consumption`.`productid`,
     `products`.`productid`,
     `products`.`productname`
FROM
     `user` INNER JOIN `user_product_consumption` ON `user`.`userid` = `user_product_consumption`.`userid`
     INNER JOIN `products` ON `user_product_consumption`.`productid` = `products`.`productid`
     WHERE user.username= ${username}

After defining the query design the layout as required and save the report as "envdemo1.prpt". Now publish the report to the BI server by giving it the admin credential and launch the report from PRD and logged in as joe and then you will be able to view the joe's data only because you have logged in as joe.
              
            Now notice that if you will logged in as suzy you won't be able to view any data because suzy has no permission to access it. So log in as admin joe in PAC or PUC and right click on share and give all the rights to that user suzy by check the box all permission, now log in again as suzy and you will see the data of suzy.

For your better understanding follow the below video. :)