Pentaho用户控制台中Pentaho动态加载月份名称

时间:2015-04-20 08:54:14

标签: console pentaho mondrian

在我的维度表中,我有月份字段,其编号表示月份1 ... 12,但在此表中我没有该月份的名称(1月,2月等等)。在mondrian文件中,我使用它像时间维度。

<Dimension type="TimeDimension" visible="true" highCardinality="false" name="timedimension" caption="Datetime">
    <Hierarchy visible="true" hasAll="true" primaryKey="id_date">
      <Table name="dim_date" schema="dbo">
      </Table>
      <Level name="year" visible="true" column="year4" type="String" uniqueMembers="false" levelType="TimeYears" hideMemberIf="Never" caption="year">
        <Annotations>
          <Annotation name="AnalyzerDateFormat">
            <![CDATA[[yyyy]]]>
          </Annotation>
        </Annotations>
      </Level>
      <Level name="month" visible="true" column="month" ordinalColumn="month" type="String" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never" caption="month">
        <Annotations>
          <Annotation name="AnalyzerDateFormat">
            <![CDATA[[yyyy].['Q'q].[M]]]>
          </Annotation>
        </Annotations>
      </Level>
    </Hierarchy>
  </Dimension>

当我在Pentaho用户控制台中显示此维度时,我想在Anylyzer报告中显示这些月份的名称而不是数字。如果没有将这些月份的名称添加到维度表中,这是否可行。是否存在一些内部函数用于显示该属性文件或内部字典,以便在mondrian文件中使用该属性或某些属性?我希望本月的名称取决于Pentaho用户控制台中的选定语言。

1 个答案:

答案 0 :(得分:2)

如果在dim表中创建一个列不是一个选项(虽然这是推荐的方法),你可以通过在Level表达式中添加一个KeyExpression元素来实现:

<Level name="month" visible="true" ordinalColumn="month" type="String" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never">
  <KeyExpression>
    <SQL dialect="generic">
      CASE 
        WHEN month = 1 THEN 'Jan'
        WHEN month = 2 THEN 'Feb'
        (...)
        WHEN month = 12 THEN 'Dec'
      END
    </SQL>
  </KeyExpression>
  <Annotations>
    <Annotation name="AnalyzerDateFormat">
      <![CDATA[[yyyy].['Q'q].[MMM]]]>
    </Annotation>
  </Annotations>
</Level>

请注意,我删除了columncaption属性。另请注意AnalyzerDateFormat值的更改(如果您需要完整的月份名称,则必须使用MMMM而不是MMM)。