<?xml version="1.0"?>
<Schema name="FoodMart">
<!--
  == This software is subject to the terms of the Eclipse Public License v1.0
  == Agreement, available at the following URL:
  == http://www.eclipse.org/legal/epl-v10.html.
  == You must accept the terms of that agreement to use this software.
  ==
  == Copyright (C) 2000-2005 Julian Hyde
  == Copyright (C) 2005-2011 Pentaho and others
  == All Rights Reserved.
  -->

<!-- Shared dimensions -->

  <Dimension name="Store">
    <Hierarchy hasAll="true" primaryKey="store_id">
      <Table name="store"/>
      <Level name="Store Country" column="store_country" uniqueMembers="true"/>
      <Level name="Store State" column="store_state" uniqueMembers="true"/>
      <Level name="Store City" column="store_city" uniqueMembers="false"/>
      <Level name="Store Name" column="store_name" uniqueMembers="true">
        <Property name="Store Type" column="store_type"/>
        <Property name="Store Manager" column="store_manager"/>
        <Property name="Store Sqft" column="store_sqft" type="Numeric"/>
        <Property name="Grocery Sqft" column="grocery_sqft" type="Numeric"/>
        <Property name="Frozen Sqft" column="frozen_sqft" type="Numeric"/>
        <Property name="Meat Sqft" column="meat_sqft" type="Numeric"/>
        <Property name="Has coffee bar" column="coffee_bar" type="Boolean"/>
        <Property name="Street address" column="store_street_address" type="String"/>
      </Level>
    </Hierarchy>
  </Dimension>

  <Dimension name="Store Size in SQFT">
    <Hierarchy hasAll="true" primaryKey="store_id">
      <Table name="store"/>
      <Level name="Store Sqft" column="store_sqft" type="Numeric" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Store Type">
    <Hierarchy hasAll="true" primaryKey="store_id">
      <Table name="store"/>
      <Level name="Store Type" column="store_type" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Time" type="TimeDimension">
    <Hierarchy hasAll="false" primaryKey="time_id">
      <Table name="time_by_day"/>
      <Level name="Year" column="the_year" type="Numeric" uniqueMembers="true"
          levelType="TimeYears"/>
      <Level name="Quarter" column="quarter" uniqueMembers="false"
          levelType="TimeQuarters"/>
      <Level name="Month" column="month_of_year" uniqueMembers="false" type="Numeric"
          levelType="TimeMonths"/>
    </Hierarchy>
    <Hierarchy hasAll="true" name="Weekly" primaryKey="time_id">
      <Table name="time_by_day"/>
      <Level name="Year" column="the_year" type="Numeric" uniqueMembers="true"
          levelType="TimeYears"/>
      <Level name="Week" column="week_of_year" type="Numeric" uniqueMembers="false"
          levelType="TimeWeeks"/>
      <Level name="Day" column="day_of_month" uniqueMembers="false" type="Numeric"
          levelType="TimeDays"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Product">
    <Hierarchy hasAll="true" primaryKey="product_id" primaryKeyTable="product">
      <Join leftKey="product_class_id" rightKey="product_class_id">
        <Table name="product"/>
        <Table name="product_class"/>
      </Join>
<!--
      <Query>
        <SQL dialect="generic">
SELECT *
FROM "product", "product_class"
WHERE "product"."product_class_id" = "product_class"."product_class_id"
        </SQL>
      </Query>
      <Level name="Product Family" column="product_family" uniqueMembers="true"/>
      <Level name="Product Department" column="product_department" uniqueMembers="false"/>
      <Level name="Product Category" column="product_category" uniqueMembers="false"/>
      <Level name="Product Subcategory" column="product_subcategory" uniqueMembers="false"/>
      <Level name="Brand Name" column="brand_name" uniqueMembers="false"/>
      <Level name="Product Name" column="product_name" uniqueMembers="true"/>
-->
      <Level name="Product Family" table="product_class" column="product_family"
          uniqueMembers="true"/>
      <Level name="Product Department" table="product_class" column="product_department"
          uniqueMembers="false"/>
      <Level name="Product Category" table="product_class" column="product_category"
          uniqueMembers="false"/>
      <Level name="Product Subcategory" table="product_class" column="product_subcategory"
          uniqueMembers="false"/>
      <Level name="Brand Name" table="product" column="brand_name" uniqueMembers="false"/>
      <Level name="Product Name" table="product" column="product_name"
          uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Warehouse">
    <Hierarchy hasAll="true" primaryKey="warehouse_id">
      <Table name="warehouse"/>
      <Level name="Country" column="warehouse_country" uniqueMembers="true"/>
      <Level name="State Province" column="warehouse_state_province"
          uniqueMembers="true"/>
      <Level name="City" column="warehouse_city" uniqueMembers="false"/>
      <Level name="Warehouse Name" column="warehouse_name" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

<!-- Sales -->
<Cube name="Sales" defaultMeasure="Unit Sales">
  <!-- Use annotations to provide translations of this cube's caption and
       description into German and French. Use of annotations in this manner is
       experimental and unsupported; just for testing right now. -->
  <Annotations>
    <Annotation name="caption.de_DE">Verkaufen</Annotation>
    <Annotation name="caption.fr_FR">Ventes</Annotation>
    <Annotation name="description.fr_FR">Cube des ventes</Annotation>
    <Annotation name="description.de">Cube Verkaufen</Annotation>
    <Annotation name="description.de_AT">Cube den Verkaufen</Annotation>
  </Annotations>
  <Table name="sales_fact_1997">
<!--
    <AggExclude name="agg_l_03_sales_fact_1997" />
    <AggExclude name="agg_ll_01_sales_fact_1997" />
    <AggExclude name="agg_pl_01_sales_fact_1997" />
    <AggExclude name="agg_l_05_sales_fact_1997" />
-->
    <AggExclude name="agg_c_special_sales_fact_1997" />
<!--
    <AggExclude name="agg_c_14_sales_fact_1997" />
-->
    <AggExclude name="agg_lc_100_sales_fact_1997" />
    <AggExclude name="agg_lc_10_sales_fact_1997" />
    <AggExclude name="agg_pc_10_sales_fact_1997" />
    <AggName name="agg_c_special_sales_fact_1997">
        <AggFactCount column="FACT_COUNT"/>
        <AggIgnoreColumn column="foo"/>
        <AggIgnoreColumn column="bar"/>
        <AggForeignKey factColumn="product_id" aggColumn="PRODUCT_ID" />
        <AggForeignKey factColumn="customer_id" aggColumn="CUSTOMER_ID" />
        <AggForeignKey factColumn="promotion_id" aggColumn="PROMOTION_ID" />
        <AggForeignKey factColumn="store_id" aggColumn="STORE_ID" />
<!--
        <AggMeasure name="[Measures].[Avg Unit Sales]" column="UNIT_SALES_AVG"/>
-->
        <AggMeasure name="[Measures].[Unit Sales]" column="UNIT_SALES_SUM" />
        <AggMeasure name="[Measures].[Store Cost]" column="STORE_COST_SUM" />
        <AggMeasure name="[Measures].[Store Sales]" column="STORE_SALES_SUM" />
        <AggLevel name="[Time].[Year]" column="TIME_YEAR" />
        <AggLevel name="[Time].[Quarter]" column="TIME_QUARTER" />
        <AggLevel name="[Time].[Month]" column="TIME_MONTH" />
    </AggName>
  </Table>

  <DimensionUsage name="Store" source="Store" foreignKey="store_id"/>
  <DimensionUsage name="Store Size in SQFT" source="Store Size in SQFT"
      foreignKey="store_id"/>
  <DimensionUsage name="Store Type" source="Store Type" foreignKey="store_id"/>
  <DimensionUsage name="Time" source="Time" foreignKey="time_id"/>
  <DimensionUsage name="Product" source="Product" foreignKey="product_id"/>
  <Dimension name="Promotion Media" foreignKey="promotion_id">
    <Hierarchy hasAll="true" allMemberName="All Media" primaryKey="promotion_id" defaultMember="All Media">
      <Table name="promotion"/>
      <Level name="Media Type" column="media_type" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Promotions" foreignKey="promotion_id">
    <Hierarchy hasAll="true" allMemberName="All Promotions" primaryKey="promotion_id" defaultMember="[All Promotions]">
      <Table name="promotion"/>
      <Level name="Promotion Name" column="promotion_name" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Customers" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Customers" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Country" column="country" uniqueMembers="true"/>
      <Level name="State Province" column="state_province" uniqueMembers="true"/>
      <Level name="City" column="city" uniqueMembers="false"/>
      <Level name="Name" column="customer_id" type="Numeric" uniqueMembers="true">
        <NameExpression>
          <SQL dialect="oracle">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="hive">
`customer`.`fullname`
          </SQL>
          <SQL dialect="hsqldb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="access">
fname + ' ' + lname
          </SQL>
          <SQL dialect="postgres">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="mysql">
CONCAT(`customer`.`fname`, ' ', `customer`.`lname`)
          </SQL>
          <SQL dialect="mssql">
fname + ' ' + lname
          </SQL>
          <SQL dialect="derby">
"customer"."fullname"
          </SQL>
          <SQL dialect="db2">
CONCAT(CONCAT("customer"."fname", ' '), "customer"."lname")
          </SQL>
          <SQL dialect="luciddb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="neoview">
"customer"."fullname"
          </SQL>
          <SQL dialect="teradata">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="generic">
fullname
          </SQL>
        </NameExpression>
        <OrdinalExpression>
          <SQL dialect="oracle">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="hsqldb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="access">
fname + ' ' + lname
          </SQL>
          <SQL dialect="postgres">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="mysql">
CONCAT(`customer`.`fname`, ' ', `customer`.`lname`)
          </SQL>
          <SQL dialect="mssql">
fname + ' ' + lname
          </SQL>
          <SQL dialect="neoview">
"customer"."fullname"
          </SQL>
          <SQL dialect="derby">
"customer"."fullname"
          </SQL>
          <SQL dialect="db2">
CONCAT(CONCAT("customer"."fname", ' '), "customer"."lname")
          </SQL>
          <SQL dialect="luciddb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="generic">
fullname
          </SQL>
        </OrdinalExpression>
        <Property name="Gender" column="gender"/>
        <Property name="Marital Status" column="marital_status"/>
        <Property name="Education" column="education"/>
        <Property name="Yearly Income" column="yearly_income"/>
      </Level>
    </Hierarchy>
  </Dimension>
  <Dimension name="Education Level" foreignKey="customer_id">
    <Hierarchy hasAll="true" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Education Level" column="education" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Gender" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Gender" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Gender" column="gender" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Marital Status" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Marital Status" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Marital Status" column="marital_status" uniqueMembers="true" approxRowCount="111"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Yearly Income" foreignKey="customer_id">
    <Hierarchy hasAll="true" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Yearly Income" column="yearly_income" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Measure name="Unit Sales" column="unit_sales" aggregator="sum"
      formatString="Standard"/>
  <Measure name="Store Cost" column="store_cost" aggregator="sum"
      formatString="#,###.00"/>
  <Measure name="Store Sales" column="store_sales" aggregator="sum"
      formatString="#,###.00"/>
  <Measure name="Sales Count" column="product_id" aggregator="count"
      formatString="#,###"/>
  <Measure name="Customer Count" column="customer_id"
      aggregator="distinct-count" formatString="#,###"/>
  <Measure name="Promotion Sales" aggregator="sum" formatString="#,###.00">
    <MeasureExpression>
      <SQL dialect="access">
Iif("sales_fact_1997"."promotion_id" = 0, 0, "sales_fact_1997"."store_sales")
      </SQL>
      <SQL dialect="oracle">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="hsqldb">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="postgres">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="mysql">
(case when `sales_fact_1997`.`promotion_id` = 0 then 0 else `sales_fact_1997`.`store_sales` end)
      </SQL>
      <!-- Workaround the fact that Infobright does not have a CASE operator.
           The simpler expression gives wrong results, so some tests are
           disabled. -->
      <SQL dialect="neoview">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="infobright">
`sales_fact_1997`.`store_sales`
      </SQL>
      <SQL dialect="derby">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="luciddb">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="db2">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="nuodb">
(case when "sales_fact_1997"."promotion_id" = 0 then 0 else "sales_fact_1997"."store_sales" end)
      </SQL>
      <SQL dialect="generic">
(case when sales_fact_1997.promotion_id = 0 then 0 else sales_fact_1997.store_sales end)
      </SQL>
    </MeasureExpression>
  </Measure>
  <CalculatedMember
      name="Profit"
      dimension="Measures">
    <Formula>[Measures].[Store Sales] - [Measures].[Store Cost]</Formula>
    <CalculatedMemberProperty name="FORMAT_STRING" value="$#,##0.00"/>
  </CalculatedMember>
  <CalculatedMember
      name="Profit last Period"
      dimension="Measures"
      formula="COALESCEEMPTY((Measures.[Profit], [Time].[Time].PREVMEMBER),    Measures.[Profit])"
      visible="false">
    <CalculatedMemberProperty name="FORMAT_STRING" value="$#,##0.00"/>
    <CalculatedMemberProperty name="MEMBER_ORDINAL" value="18"/>
  </CalculatedMember>
  <CalculatedMember
      name="Profit Growth"
      dimension="Measures"
      formula="([Measures].[Profit] - [Measures].[Profit last Period]) / [Measures].[Profit last Period]"
      visible="true"
      caption="Gewinn-Wachstum">
    <CalculatedMemberProperty name="FORMAT_STRING" value="0.0%"/>
  </CalculatedMember>
</Cube>

<Cube name="Warehouse">
  <Table name="inventory_fact_1997"/>

  <DimensionUsage name="Store" source="Store" foreignKey="store_id"/>
  <DimensionUsage name="Store Size in SQFT" source="Store Size in SQFT"
      foreignKey="store_id"/>
  <DimensionUsage name="Store Type" source="Store Type" foreignKey="store_id"/>
  <DimensionUsage name="Time" source="Time" foreignKey="time_id"/>
  <DimensionUsage name="Product" source="Product" foreignKey="product_id"/>
  <DimensionUsage name="Warehouse" source="Warehouse" foreignKey="warehouse_id"/>

  <Measure name="Store Invoice" column="store_invoice" aggregator="sum"/>
  <Measure name="Supply Time" column="supply_time" aggregator="sum"/>
  <Measure name="Warehouse Cost" column="warehouse_cost" aggregator="sum"/>
  <Measure name="Warehouse Sales" column="warehouse_sales" aggregator="sum"/>
  <Measure name="Units Shipped" column="units_shipped" aggregator="sum" formatString="#.0"/>
  <Measure name="Units Ordered" column="units_ordered" aggregator="sum" formatString="#.0"/>
  <Measure name="Warehouse Profit" aggregator="sum">
    <MeasureExpression>
      <SQL dialect="mysql">
`warehouse_sales` - `inventory_fact_1997`.`warehouse_cost`
      </SQL>
      <SQL dialect="infobright">
`warehouse_sales` - `inventory_fact_1997`.`warehouse_cost`
      </SQL>
      <SQL dialect="generic">
&quot;warehouse_sales&quot; - &quot;inventory_fact_1997&quot;.&quot;warehouse_cost&quot;
      </SQL>
    </MeasureExpression>
  </Measure>
  <CalculatedMember
      name="Average Warehouse Sale"
      dimension="Measures">
    <Formula>[Measures].[Warehouse Sales] / [Measures].[Warehouse Cost]</Formula>
    <CalculatedMemberProperty name="FORMAT_STRING" value="$#,##0.00"/>
  </CalculatedMember>
  <NamedSet name="Top Sellers">
    <Formula>TopCount([Warehouse].[Warehouse Name].MEMBERS, 5, [Measures].[Warehouse Sales])</Formula>
  </NamedSet>    
</Cube>

<!-- Test a cube based upon a single table. -->
<Cube name="Store">
  <Table name="store"/>
  <!-- We could have used the shared dimension "Store Type", but we
     want to test private dimensions without primary key. -->
  <Dimension name="Store Type">
    <Hierarchy hasAll="true">
      <Level name="Store Type" column="store_type" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <!-- We don't have to specify primary key or foreign key since the shared
     dimension "Store" has the same underlying table as the cube. -->
  <DimensionUsage name="Store" source="Store"/>

  <Dimension name="Has coffee bar">
    <Hierarchy hasAll="true">
      <Level name="Has coffee bar" column="coffee_bar" uniqueMembers="true"
          type="Boolean"/>
    </Hierarchy>
  </Dimension>

  <Measure name="Store Sqft" column="store_sqft" aggregator="sum"
      formatString="#,###"/>
  <Measure name="Grocery Sqft" column="grocery_sqft" aggregator="sum"
      formatString="#,###"/>

</Cube>

<Cube name="HR">
  <Table name="salary"/>
  <!-- Use private "Time" dimension because key is different than public
     "Time" dimension. -->
  <Dimension name="Time" type="TimeDimension" foreignKey="pay_date">
    <Hierarchy hasAll="false" primaryKey="the_date">
      <Table name="time_by_day"/>
      <Level name="Year" column="the_year" type="Numeric" uniqueMembers="true"
          levelType="TimeYears"/>
      <Level name="Quarter" column="quarter" uniqueMembers="false"
          levelType="TimeQuarters"/>
      <!-- Use the_month as source for the name, so members look like
           [Time].[1997].[Q1].[Jan] rather than [Time].[1997].[Q1].[1]. -->
      <Level name="Month" column="month_of_year" nameColumn="the_month"
          uniqueMembers="false" type="Numeric" levelType="TimeMonths"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Store" foreignKey="employee_id" >
    <Hierarchy hasAll="true" primaryKey="employee_id"
        primaryKeyTable="employee">
      <Join leftKey="store_id" rightKey="store_id">
        <Table name="employee"/>
        <Table name="store"/>
      </Join>
      <Level name="Store Country" table="store" column="store_country"
          uniqueMembers="true"/>
      <Level name="Store State" table="store" column="store_state"
          uniqueMembers="true"/>
      <Level name="Store City" table="store" column="store_city"
          uniqueMembers="false"/>
      <Level name="Store Name" table="store" column="store_name"
          uniqueMembers="true">
        <Property name="Store Type" column="store_type"/>
        <Property name="Store Manager" column="store_manager"/>
        <Property name="Store Sqft" column="store_sqft" type="Numeric"/>
        <Property name="Grocery Sqft" column="grocery_sqft" type="Numeric"/>
        <Property name="Frozen Sqft" column="frozen_sqft" type="Numeric"/>
        <Property name="Meat Sqft" column="meat_sqft" type="Numeric"/>
        <Property name="Has coffee bar" column="coffee_bar" type="Boolean"/>
        <Property name="Street address" column="store_street_address"
            type="String"/>
      </Level>
    </Hierarchy>
  </Dimension>

  <Dimension name="Pay Type" foreignKey="employee_id">
    <Hierarchy hasAll="true" primaryKey="employee_id"
        primaryKeyTable="employee">
      <Join leftKey="position_id" rightKey="position_id">
        <Table name="employee"/>
        <Table name="position"/>
      </Join>
      <Level name="Pay Type" table="position" column="pay_type"
          uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Store Type" foreignKey="employee_id">
    <Hierarchy hasAll="true" primaryKeyTable="employee" primaryKey="employee_id">
      <Join leftKey="store_id" rightKey="store_id">
        <Table name="employee"/>
        <Table name="store"/>
      </Join>
      <Level name="Store Type" table="store" column="store_type"
          uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Position" foreignKey="employee_id">
    <Hierarchy hasAll="true" allMemberName="All Position"
        primaryKey="employee_id">
      <Table name="employee"/>
      <Level name="Management Role" uniqueMembers="true"
          column="management_role"/>
      <Level name="Position Title" uniqueMembers="false"
          column="position_title" ordinalColumn="position_id"/>
    </Hierarchy>
  </Dimension>

  <Dimension name="Department" foreignKey="department_id">
    <Hierarchy hasAll="true" primaryKey="department_id">
      <Table name="department"/>
      <Level name="Department Description" type="Numeric" uniqueMembers="true"
          column="department_id"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Employees" foreignKey="employee_id">
    <Hierarchy hasAll="true" allMemberName="All Employees"
        primaryKey="employee_id">
      <Table name="employee"/>
      <Level name="Employee Id" type="Numeric" uniqueMembers="true"
          column="employee_id" parentColumn="supervisor_id"
          nameColumn="full_name" nullParentValue="0">
        <Closure parentColumn="supervisor_id" childColumn="employee_id">
          <Table name="employee_closure"/>
        </Closure>
        <Property name="Marital Status" column="marital_status"/>
        <Property name="Position Title" column="position_title"/>
        <Property name="Gender" column="gender"/>
        <Property name="Salary" column="salary"/>
        <Property name="Education Level" column="education_level"/>
        <Property name="Management Role" column="management_role"/>
      </Level>
    </Hierarchy>
  </Dimension>

  <Measure name="Org Salary" column="salary_paid" aggregator="sum"
      formatString="Currency"/>
  <Measure name="Count" column="employee_id" aggregator="count"
      formatString="#,#"/>
  <Measure name="Number of Employees" column="employee_id"
      aggregator="distinct-count" formatString="#,#"/>
  <CalculatedMember name="Employee Salary" dimension="Measures"
      formatString="Currency"
      formula="([Employees].currentmember.datamember, [Measures].[Org Salary])"/>
  <CalculatedMember name="Avg Salary" dimension="Measures"
      formatString="Currency"
      formula="[Measures].[Org Salary]/[Measures].[Number of Employees]"/>
</Cube>

<!-- Cube with one ragged hierarchy (otherwise the same as the "Sales"
   cube). -->
<Cube name="Sales Ragged">
  <Table name="sales_fact_1997">
    <AggExclude name="agg_pc_10_sales_fact_1997"/>
    <AggExclude name="agg_lc_10_sales_fact_1997"/>
  </Table>
  <Dimension name="Store" foreignKey="store_id">
    <Hierarchy hasAll="true" primaryKey="store_id">
      <Table name="store_ragged"/>
      <Level name="Store Country" column="store_country" uniqueMembers="true"
          hideMemberIf="Never"/>
      <Level name="Store State" column="store_state" uniqueMembers="true"
          hideMemberIf="IfParentsName"/>
      <Level name="Store City" column="store_city" uniqueMembers="false"
          hideMemberIf="IfBlankName"/>
      <Level name="Store Name" column="store_name" uniqueMembers="true"
          hideMemberIf="Never">
        <Property name="Store Type" column="store_type"/>
        <Property name="Store Manager" column="store_manager"/>
        <Property name="Store Sqft" column="store_sqft" type="Numeric"/>
        <Property name="Grocery Sqft" column="grocery_sqft" type="Numeric"/>
        <Property name="Frozen Sqft" column="frozen_sqft" type="Numeric"/>
        <Property name="Meat Sqft" column="meat_sqft" type="Numeric"/>
        <Property name="Has coffee bar" column="coffee_bar" type="Boolean"/>
        <Property name="Street address" column="store_street_address" type="String"/>
      </Level>
    </Hierarchy>
  </Dimension>

  <Dimension name="Geography" foreignKey="store_id">
    <Hierarchy hasAll="true" primaryKey="store_id">
      <Table name="store_ragged"/>
      <Level name="Country" column="store_country" uniqueMembers="true"
          hideMemberIf="Never"/>
      <Level name="State" column="store_state" uniqueMembers="true"
          hideMemberIf="IfParentsName"/>
      <Level name="City" column="store_city" uniqueMembers="false"
          hideMemberIf="IfBlankName"/>
    </Hierarchy>
  </Dimension>

  <DimensionUsage name="Store Size in SQFT" source="Store Size in SQFT"
      foreignKey="store_id"/>
  <DimensionUsage name="Store Type" source="Store Type" foreignKey="store_id"/>
  <DimensionUsage name="Time" source="Time" foreignKey="time_id"/>
  <DimensionUsage name="Product" source="Product" foreignKey="product_id"/>
  <Dimension name="Promotion Media" foreignKey="promotion_id">
    <Hierarchy hasAll="true" allMemberName="All Media" primaryKey="promotion_id">
      <Table name="promotion"/>
      <Level name="Media Type" column="media_type" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Promotions" foreignKey="promotion_id">
    <Hierarchy hasAll="true" allMemberName="All Promotions" primaryKey="promotion_id">
      <Table name="promotion"/>
      <Level name="Promotion Name" column="promotion_name" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Customers" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Customers" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Country" column="country" uniqueMembers="true"/>
      <Level name="State Province" column="state_province" uniqueMembers="true"/>
      <Level name="City" column="city" uniqueMembers="false"/>
      <Level name="Name" uniqueMembers="true">
        <KeyExpression>
          <SQL dialect="oracle">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="hsqldb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="access">
fname + ' ' + lname
          </SQL>
          <SQL dialect="postgres">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="mysql">
CONCAT(`customer`.`fname`, ' ', `customer`.`lname`)
          </SQL>
          <SQL dialect="mssql">
fname + ' ' + lname
          </SQL>
          <SQL dialect="derby">
"customer"."fullname"
          </SQL>
          <SQL dialect="db2">
CONCAT(CONCAT("customer"."fname", ' '), "customer"."lname")
          </SQL>
          <SQL dialect="luciddb">
"fname" || ' ' || "lname"
          </SQL>
          <SQL dialect="neoview">
"customer"."fullname"
          </SQL>
          <SQL dialect="generic">
fullname
          </SQL>
        </KeyExpression>
        <Property name="Gender" column="gender"/>
        <Property name="Marital Status" column="marital_status"/>
        <Property name="Education" column="education"/>
        <Property name="Yearly Income" column="yearly_income"/>
      </Level>
    </Hierarchy>
  </Dimension>
  <Dimension name="Education Level" foreignKey="customer_id">
    <Hierarchy hasAll="true" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Education Level" column="education" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Gender" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Gender" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Gender" column="gender" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Marital Status" foreignKey="customer_id">
    <Hierarchy hasAll="true" allMemberName="All Marital Status" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Marital Status" column="marital_status" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Dimension name="Yearly Income" foreignKey="customer_id">
    <Hierarchy hasAll="true" primaryKey="customer_id">
      <Table name="customer"/>
      <Level name="Yearly Income" column="yearly_income" uniqueMembers="true"/>
    </Hierarchy>
  </Dimension>
  <Measure name="Unit Sales" column="unit_sales" aggregator="sum"
      formatString="Standard"/>
  <Measure name="Store Cost" column="store_cost" aggregator="sum"
      formatString="#,###.00"/>
  <Measure name="Store Sales" column="store_sales" aggregator="sum"
      formatString="#,###.00"/>
  <Measure name="Sales Count" column="product_id" aggregator="count"
      formatString="#,###"/>
  <Measure name="Customer Count" column="customer_id" aggregator="distinct-count"
      formatString="#,###"/>
</Cube>

<!-- a simpler version of "Sales" (with MEMBER_ORDINAL-properties) -->
<Cube name="Sales 2">
   <Table name="sales_fact_1997"/>

   <DimensionUsage name="Time" source="Time" foreignKey="time_id"/>
   <DimensionUsage name="Product" source="Product" foreignKey="product_id"/>

   <Dimension name="Gender" foreignKey="customer_id">
     <Hierarchy hasAll="true" allMemberName="All Gender" primaryKey="customer_id">
       <Table name="customer"/>
       <Level name="Gender" column="gender" uniqueMembers="true"/>
     </Hierarchy>
   </Dimension>

   <Measure name="Sales Count" column="product_id" aggregator="count" formatString="#,###">
     <CalculatedMemberProperty name="MEMBER_ORDINAL" value="1"/>
   </Measure>

   <Measure name="Unit Sales" column="unit_sales" aggregator="sum"    formatString="Standard">
     <CalculatedMemberProperty name="MEMBER_ORDINAL" value="2"/>
   </Measure>

   <Measure name="Store Sales" column="store_sales" aggregator="sum"  formatString="#,###.00">
      <CalculatedMemberProperty name="MEMBER_ORDINAL" value="3"/>
    </Measure>

   <Measure name="Store Cost" column="store_cost" aggregator="sum"    formatString="#,###.00">
      <CalculatedMemberProperty name="MEMBER_ORDINAL" value="6"/>
    </Measure>

   <Measure name="Customer Count" column="customer_id" aggregator="distinct-count" formatString="#,###">
      <CalculatedMemberProperty name="MEMBER_ORDINAL" value="7"/>
    </Measure>

   <CalculatedMember
       name="Profit"
       dimension="Measures">
     <Formula>[Measures].[Store Sales] - [Measures].[Store Cost]</Formula>
     <CalculatedMemberProperty name="FORMAT_STRING" value="$#,##0.00"/>
     <CalculatedMemberProperty name="MEMBER_ORDINAL" value="4"/>
   </CalculatedMember>

   <CalculatedMember
       name="Profit last Period"
       dimension="Measures"
       formula="COALESCEEMPTY((Measures.[Profit], [Time].[Time].PREVMEMBER),    Measures.[Profit])"
       visible="false">
      <CalculatedMemberProperty name="MEMBER_ORDINAL" value="5"/>
   </CalculatedMember>
</Cube>

<VirtualCube name="Warehouse and Sales" defaultMeasure="Store Sales">
  <VirtualCubeDimension cubeName="Sales" name="Customers"/>
  <VirtualCubeDimension cubeName="Sales" name="Education Level"/>
  <VirtualCubeDimension cubeName="Sales" name="Gender"/>
  <VirtualCubeDimension cubeName="Sales" name="Marital Status"/>
  <VirtualCubeDimension name="Product"/>
  <VirtualCubeDimension cubeName="Sales" name="Promotion Media"/>
  <VirtualCubeDimension cubeName="Sales" name="Promotions"/>
  <VirtualCubeDimension name="Store"/>
  <VirtualCubeDimension name="Time"/>
  <VirtualCubeDimension cubeName="Sales" name="Yearly Income"/>
  <VirtualCubeDimension cubeName="Warehouse" name="Warehouse"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Sales Count]"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Store Cost]"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Store Sales]"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Unit Sales]"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Profit]"/>
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Profit Growth]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Store Invoice]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Supply Time]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Units Ordered]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Units Shipped]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Warehouse Cost]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Warehouse Profit]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Warehouse Sales]"/>
  <VirtualCubeMeasure cubeName="Warehouse" name="[Measures].[Average Warehouse Sale]"/>
  <!--
  <VirtualCubeMeasure cubeName="Sales" name="[Measures].[Store Sales Net]"/>
  -->
  <CalculatedMember name="Profit Per Unit Shipped" dimension="Measures">
    <Formula>[Measures].[Profit] / [Measures].[Units Shipped]</Formula>
  </CalculatedMember>
</VirtualCube>

<!-- A California manager can only see customers and stores in California.
     They cannot drill down on Gender. -->
<Role name="California manager">
  <SchemaGrant access="none">
    <CubeGrant cube="Sales" access="all">
      <HierarchyGrant hierarchy="[Store]" access="custom"
          topLevel="[Store].[Store Country]">
        <MemberGrant member="[Store].[USA].[CA]" access="all"/>
        <MemberGrant member="[Store].[USA].[CA].[Los Angeles]" access="none"/>
      </HierarchyGrant>
      <HierarchyGrant hierarchy="[Customers]" access="custom"
          topLevel="[Customers].[State Province]" bottomLevel="[Customers].[City]">
        <MemberGrant member="[Customers].[USA].[CA]" access="all"/>
        <MemberGrant member="[Customers].[USA].[CA].[Los Angeles]" access="none"/>
      </HierarchyGrant>
      <HierarchyGrant hierarchy="[Gender]" access="none"/>
    </CubeGrant>
  </SchemaGrant>
</Role>

<Role name="No HR Cube">
  <SchemaGrant access="all">
    <CubeGrant cube="HR" access="none"/>
  </SchemaGrant>
</Role>

</Schema>
