Setting up an "All" Parameter

Setting up an "All" Parameter

This short tutorial is fairly similar to the last one, let's say it's an improved version:

We work again with Pentaho Report Designer 3.5. Imagine you want to give your users the possibility to choose either one of the parameter values or all. So how can we implement this with a MySQL query? 

The approach is as follows:

Set up the query to for the parameter values like this:

SELECT

"All Countries" AS country_name

UNION

SELECT

country_name

FROM

table

;

We do the same for the channels query. Please keep in mind that UNION will remove any duplicates. If you are sure that you have no duplicates, you can use UNION ALL to improve the performance.

Set up a new parameter called "country_name", tick "mandatory", choose the above query as the source, set the type to string.

Now change the main query that feeds the report like this:

SELECT

[...]

WHERE

(cc.channel_name = ${channel_name} OR "All Channels" = ${channel_name}) AND

(country_name = ${country_name} OR "All Countries" = ${country_name}) AND

the_date >= ${start_date} AND

the_date <= ${end_date}

GROUP BY 1,2,3,4

;

Save everything and run the report ... you should see the all options now in your pull down menu:

As some of you might use Oracle as well, a user named "zulu" from the pentaho forum pointed out that:

"Not sure if this helps you now, but depending on your SQL dialect, a

NULL (meaning nothing) is treated differently to a "NULL" string.

In Oracle your predicate could be: 

WHERE (${media} IS NULL OR media=${media}). 

Oracle applies "lazy" logic, so if your Media parameter is not

completed by the user (meaning it "IS NULL"), the condition will not

even check the "media=${media}" part."

Just a remark from my side: My original post included a query like this one "(media = ${media} OR 'All Media' = ${media})"

You can find the original post here.

Update 2012-05-30: Somebody asked me how to achieve the same with mulitselect parameters. Here is the approach that works for me (It's a different dataset, but you get the idea):

SELECT

     `city_sales`.`date`,

     `city_sales`.`continent`,

     `city_sales`.`country`,

     `city_sales`.`city`,

     `city_sales`.`revenue`

FROM

     `city_sales`

WHERE

(city IN (${CITY}) OR "All cities" IN (${CITY}))

Note: I defined the CITY parameter as type STRING.

转自:http://diethardsteiner.blogspot.jp/2009/10/setting-up-parameter.html

猜你喜欢

转载自qq85609655.iteye.com/blog/2290791