everyone!
Following the "Pentaho Analizer Cookbook" PDF, I tried to stablish a level-based measure.
My cube has a single dimension hierarchy: Clients that have Projects that have Buildings that have Phases that have Costlines level 0 that have Costlines level 1.
So, there let be samples for both fact and dimensions:
DROP TABLE IF EXISTS TMP_DEBUG_OLAP_13_FACTS;
CREATE TABLE TMP_DEBUG_OLAP_13_FACTS AS
SELECT 1 AS client_id,1 as project_id,1 as building_id,'1_1_1_1' as phase_id,'1_1_1_1_1' as costs_line_level_0_id,'1_1_1_1_1_1' as costs_line_level_1_id,10 as amount
UNION ALL SELECT 1 AS client_id,1 as project_id,1 as building_id,'1_1_1_1' as phase_id,'1_1_1_1_2' as costs_line_level_0_id,'1_1_1_1_2_1' as costs_line_level_1_id,20 as amount
UNION ALL SELECT 1 AS client_id,1 as project_id,1 as building_id,'1_1_1_2' as phase_id,'1_1_1_2_1' as costs_line_level_0_id,'1_1_1_2_1_1' as costs_line_level_1_id,30 as amount
UNION ALL SELECT 1 AS client_id,1 as project_id,2 as building_id,'1_1_2_1' AS phase_id,'1_1_2_1_1' as costs_line_level_0_id,'1_1_2_1_1_1' as costs_line_level_1_id,40 as amount
UNION ALL SELECT 1 AS client_id,2 as project_id,3 as building_id,'1_2_3_1' AS phase_id,'1_2_3_1_1' as costs_line_level_0_id,'1_2_3_1_1_1' as costs_line_level_1_id,50 as amount
UNION ALL SELECT 1 AS client_id,2 as project_id,4 as building_id,'1_2_4_1' AS phase_id,'1_2_4_1_1' as costs_line_level_0_id,'1_2_4_1_1_1' as costs_line_level_1_id,60 as amount
UNION ALL SELECT 2 AS client_id,3 as project_id,5 as building_id,'2_3_5_1' AS phase_id,'2_3_5_1_1' as costs_line_level_0_id,'2_3_5_1_1_-1' as costs_line_level_1_id,70 as amount
;
DROP TABLE IF EXISTS TMP_DEBUG_OLAP_13_DIMENSIONS;
CREATE TABLE TMP_DEBUG_OLAP_13_DIMENSIONS AS
SELECT 1 AS client_id,'Client 1 name' AS client_name,1 as project_id,'Project 1' as project_name,1 as building_id,'Building 1' as building_name,'1_1_1_1' as phase_id,'Phase 1' as phase_name,'1_1_1_1_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'1_1_1_1_1_1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
UNION ALL SELECT 1 AS client_id,'Client 1 name' AS client_name,1 as project_id,'Project 1' as project_name,1 as building_id,'Building 1' as building_name,'1_1_1_1' as phase_id,'Phase 1' as phase_name,'1_1_1_1_2' as costs_line_level_0_id,'2 blah' AS costs_line_level_0_name,'1_1_1_1_2_1' AS costs_line_level_1_id,'2.1 blah' as costs_line_level_1_name
UNION ALL SELECT 1 AS client_id,'Client 1 name' AS client_name,1 as project_id,'Project 1' as project_name,1 as building_id,'Building 1' as building_name,'1_1_1_2' as phase_id,'Phase 2' as phase_name,'1_1_1_2_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'1_1_1_2_1_1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
UNION ALL SELECT 1 AS client_id,'Client 1 name' AS client_name,1 as project_id,'Project 1' as project_name,2 as building_id,'Building 2' as building_name,'1_1_2_1' as phase_id,'Phase 1' as phase_name,'1_1_2_1_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'1_1_2_1_1_1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
UNION ALL SELECT 1 AS client_id,'Client 1 name' AS client_name,2 as project_id,'Project 2' as project_name,3 as building_id,'Building 3' as building_name,'1_2_3_1' as phase_id,'Phase 1' as phase_name,'1_2_3_1_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'1_2_3_1_1_1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
UNION ALL SELECT 1 AS client_id,'Client 1 name' AS client_name,2 as project_id,'Project 2' as project_name,4 as building_id,'Building 4' as building_name,'1_2_4_1' as phase_id,'Phase 1' as phase_name,'1_2_4_1_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'1_2_4_1_1_1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
UNION ALL SELECT 2 AS client_id,'Client 2 name' AS client_name,3 as project_id,'Project 3' as project_name,5 as building_id,'Building 5' as building_name,'2_3_5_1' as phase_id,'Phase 1' as phase_name,'2_3_5_1_1' as costs_line_level_0_id,'1 blah' AS costs_line_level_0_name,'2_3_5_1_1_-1' AS costs_line_level_1_id,'1.1 blah' as costs_line_level_1_name
--non-crosing dimentions
UNION ALL SELECT 2 AS client_id,'Client 2 name' AS client_name,3 as project_id,'Project 3' as project_name,5 as building_id,'Building 5' as building_name,'2_3_5_1' as phase_id,'Phase 1' as phase_name,'2_3_5_1_2' as costs_line_level_0_id,'2 blah' AS costs_line_level_0_name,'2_3_5_1_2_1' AS costs_line_level_1_id,'2.1 blah' as costs_line_level_1_name
UNION ALL SELECT 2 AS client_id,'Client 2 name' AS client_name,3 as project_id,'Project 3' as project_name,5 as building_id,'Building 5' as building_name,'2_3_5_1' as phase_id,'Phase 1' as phase_name,'2_3_5_1_3' as costs_line_level_0_id,'3 blah' AS costs_line_level_0_name,'2_3_5_1_3_1' AS costs_line_level_1_id,'3.1 blah' as costs_line_level_1_name
UNION ALL SELECT 2 AS client_id,'Client 2 name' AS client_name,3 as project_id,'Project 3' as project_name,5 as building_id,'Building 5' as building_name,'2_3_5_1' as phase_id,'Phase 1' as phase_name,'2_3_5_1_4' as costs_line_level_0_id,'4 blah' AS costs_line_level_0_name,NULL AS costs_line_level_1_id,'4.1 blah' as costs_line_level_1_name
;
And my calculated measure is such as
([Measures].[My measure] , Ancestor([Dimensions].CurrentMember , [Dimensions].[Building]) )
The whole cube's xml (Mondrian) is as follows:
<Schema name="level_based_measure_unit_test">
<Dimension type="StandardDimension" visible="true" name="Dimensions">
<Hierarchy name="Dimensions hierarchy" visible="true" hasAll="true" primaryKey="costs_line_level_1_id">
<Table name="tmp_debug_olap_13_dimensions" schema="public" alias="">
</Table>
<Level name="Clients" visible="true" column="client_id" nameColumn="client_name" uniqueMembers="false">
</Level>
<Level name="Project" visible="true" column="project_id" nameColumn="project_name" uniqueMembers="false">
</Level>
<Level name="Building" visible="true" column="building_id" nameColumn="building_name" uniqueMembers="false">
</Level>
<Level name="Phase" visible="true" column="phase_id" nameColumn="phase_name" uniqueMembers="false">
</Level>
<Level name="Cost lines level 0" visible="true" column="costs_line_level_0_id" nameColumn="costs_line_level_0_name" uniqueMembers="false">
</Level>
<Level name="Cost lines level 1" visible="true" column="costs_line_level_1_id" nameColumn="costs_line_level_1_name" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Cube name="My cube" visible="true" cache="true" enabled="true">
<Table name="tmp_debug_olap_13_facts" schema="public" alias="">
</Table>
<DimensionUsage source="Dimensions" name="Dimensions" visible="true" foreignKey="costs_line_level_1_id">
</DimensionUsage>
<Measure name="My measure" column="amount" aggregator="sum" visible="true">
</Measure>
<CalculatedMember name="My leveled measure" formatString="" formula="([Measures].[My measure] , Ancestor([Dimensions].CurrentMember , [Dimensions].[Building]) )" dimension="Measures" visible="true">
</CalculatedMember>
</Cube>
</Schema>
I have 1 problem with that formula:
It displays a value at building level, but drillind-down, it keeps its value.
Picture of what I mean:
Does anyone know how should I change my calculated member, so it displays the measure [My measure] but only on Building level and below?
Thank you so much!
As the Pentaho Analizer Cookbook specifies, that Formula is for pinning a Measure
to a certain level.
It is: if you drill-down, you'll get the value as the drill-up.
If what you need (if I understood correctly) is to just display nothing for upper-levels, then user the next Formula:
IIF([Dimensions].CurrentMember.Level.Ordinal < 3 , NULL , [Measures].[My measure] )