官术网_书友最值得收藏!

Embedding filters inside metrics

Filters can be used in reports to restrict the result of the entire grid, or can be embedded into a metric to restrict only one particular number. For example, when you want to compare sales during holiday season against the whole year or the margin of one category of product as compared to another category.

If you put a holiday season filter on the report, all the metrics values would be restricted by the WHERE clause; whereas if you put the filter inside one single metric, only those specific values would be filtered, while the rest of the numbers won't be affected.

Getting ready

We need to add a new dimension table and create the Promotion attribute. From the Warehouse Catalog window, add the table DimPromotion, click on Save and Close, and create a new attribute with these columns:

  • ID: The PromotionKey column in the tables DimPromotion (lookup) and FactResellerSales
  • DESC: The EnglishPromotionName column in the table DimPromotion (lookup)

Save the attribute as Promotion and update the schema.

How to do it...

Next we create a filter:

  1. Go to Public Objects | Filters and create a new empty filter.
  2. In the Filter Editor, from Attributes double-click on Promotion, when the Attribute Qualification panel appears, click on the Add button next to Element List.
  3. In the shopping cart move Touring-1000 Promotion to the right and click on OK.
  4. Click on OK again and on Save and Close. Name the filter Touring-1000 Promotion only.
  5. Now go to the Metrics folder and double-click on Sum SalesAmount from FactResellerSales to open the Metric Editor.
  6. In the upper-right pane, click on a line that says Condition = (nothing).
  7. The editor automatically shows the available filters, double-click on Touring-1000 Promotion, see that it gets added to the right Selected condition pane.
  8. Click on File | Save As and give a different name: Sum SalesAmount from FactResellerSales (Touring-1000 Promotion). Save and close the editor window.
  9. In My Reports folder, create a new blank report. From the Public Objects | Metric folder, double-click on Sum SalesAmount from FactResellerSales and Sum SalesAmount from FactResellerSales (Touring-1000 Promotion), adding the two metrics on the grid.
  10. Go to Grid View and look at the result: the first metric is the total SalesAmount, while the second is filtered and showing only the SalesAmount during Touring-1000 Promotion.
  11. Close the report and save it as 14 Reseller SalesAmount during Touring-1000 Promotion.

How it works...

If you look at the SQL view, you'll notice two SELECT statements, both retrieve sum(a11.SalesAmount), the first with no restriction, and the second with a WHERE a11.PromotionKey in (14). The two numbers are then displayed on the grid. There is no GROUP BY clause because we do not have any attribute on the report.

There's more...

The last SELECT statement is a CROSS JOIN between the two temporary tables. It's OK; they both have one row so the result is correct.

Exercise 21

Add the Year attribute to this last report, to have the SalesAmount aggregated by year: what happens to the numbers? Can you spot the error?

Note

You can watch a screencast of this operation at:

主站蜘蛛池模板: 弥勒县| 阿克苏市| 峨边| 嘉鱼县| 南华县| 沅江市| 邛崃市| 南康市| 麻阳| 胶南市| 卓尼县| 汝城县| 洱源县| 平乡县| 内乡县| 偏关县| 梓潼县| 武陟县| 南和县| 昆山市| 新宁县| 麟游县| 确山县| 湖南省| 普定县| 行唐县| 黑山县| 剑河县| 衡阳县| 巴林左旗| 巴塘县| 土默特右旗| 徐水县| 宿州市| 泌阳县| 大冶市| 四子王旗| 莫力| 白沙| 临洮县| 乌海市|