简体   繁体   English

在Excel中使用OLAP多维数据集; 确定较大日期范围内的月度值?

[英]Working with an OLAP Cube in Excel; determine monthly values within a larger date range?

I've been working in an OLAP cube as a pivottable in excel for a while now, but more recently I'm trying to integrate some calculated measures to streamline some things, and I've hit a wall. 我已经在OLAP多维数据集中作为excel中的数据透视表工作了一段时间,但是最近我试图集成一些计算出的度量以简化某些事情,并且碰壁了。

The cube has date filters set up that specify the month & year (they get more specific, but finer levels aren't used). 多维数据集具有设置日期和年份的日期筛选器(它们变得更具体,但未使用更精细的级别)。

The rows will list individual projects, and the values can reflect 2 measures: one that reflects the average score for the date range, and another that reflects the number of observations the average is based on. 这些行将列出各个项目,其值可以反映两种度量:一种反映日期范围的平均得分,另一种反映该平均值所基于的观察次数。

I would like to create a calculated measure that will display the average score for each project as long as 2 criteria are met: 我想创建一个计算的度量,只要满足2个条件,它就会显示每个项目的平均分数:

  1. There is a minimum of 100 observations for the whole date range 在整个日期范围内至少有100个观测值
  2. there are no months with zero observations across the date range specified in the pivottable. 在数据透视表中指定的日期范围内没有零观测值的月份。

I should also clarify that the date ranges I use will vary and length, and will not always end with the most recent month, but they will always be in increments of whole months. 我还需要澄清的是,我使用的日期范围会有所不同,并且会有所不同,并且不会总是以最近的一个月结尾,但是它们总是以整个月为增量。

I'm part of the way there, as a calculated measure based on this will provide me with the average only if there are enough observations for the date range: 我参与其中,因为只有在日期范围内有足够的观测值时,基于此的计算量度才会为我提供平均值:

IIF([Measures].[OBSERVATIONS]>=100,[Measures].[AVERAGE],"^^")

Now, I need to add the criteria of no months with zero observations. 现在,我需要添加零观察值为零的标准。

I have attempted to use COUNT(), but in this form it ignores the date range set in the pivottable and returns a count of all of the months there is any value for the project, including zeros. 我尝试使用COUNT(),但是以这种形式,它忽略了数据透视表中设置的日期范围,并返回该项目有任何值(包括零)的所有月份的计数。

COUNT(([Calendar].[Calendar].[Month],[Measures].[OBSERVATIONS]),EXCLUDEEMPTY)

I tried determining the lowest number of observations in a month using this expression, but again it ignores the date range, and does not reflect empty cells: 我尝试使用此表达式确定一个月中的最少观察次数,但再次忽略了日期范围,并且不反映空单元格:

MIN([Calendar].[Calendar].[Month],[Measures].[OBSERVATIONS])

I think CurrentMember is what I need to include, but I can't get it to work for me. 我认为CurrentMember是我需要包括的内容,但是我无法让它为我工作。

Assuming it's relevant, and I'm not sure the best way to explain the calendar hierarchy, so this reflects what I have: 假设它是相关的,并且我不确定解释日历层次结构的最佳方法,所以这反映了我的知识:

OLAP多维数据集日历

The first calendar listing is the one used to filter the pivot table data, and it is also pulled into the mdx expressions above. 第一个日历清单是用于过滤数据透视表数据的清单,它也被拉入上面的mdx表达式中。

EDIT: 编辑:

Thanks @SouravA for the reply. 感谢@SouravA的回复。 I tried a few things, and given that formatting in comments is limited, here's a rundown of what I did. 我尝试了一些操作,鉴于注释的格式是有限的,所以这是我所做工作的简要说明。

I'm getting an error message that says "Query(1,35) Parser: The syntax for 'WITH' is incorrect" 我收到一条错误消息,内容为“ Query(1,35)Parser:'WITH'的语法不正确”

to make sure I'm using this correctly: 确保我正确使用了这个:

After making the changes below, I pasted the whole thing into the MDX: window from the 'calculated measures' tool in Excel. 在进行以下更改之后,我将整个内容从Excel中的“计算的度量”工具粘贴到了MDX:窗口中。

I of course changed OBSERVATIONS and AVERAGE to the variable names in my cube. 我当然将OBSERVATIONS和AVERAGE更改为多维数据集中的变量名称。

I changed '[Project].[ProjectCode]' to '[Project].[ProjectName]', which is how my cube is set up. 我将“ [Project]。[ProjectCode]”更改为“ [Project]。[ProjectName]”,这是设置多维数据集的方式。

On '[NewMeasure]' I changed it to the name I am using for the calculated measure. 在“ [NewMeasure]”上,我将其更改为用于计算度量的名称。

on '[your cube]' I've tried a couple different things; 在“ [您的立方体]”上,我尝试了几种不同的方法; the cube reference I use in the cube formulas in excel looks like this: 'Cubename NormativeCube', so I tried pasting that in the brackets with and without quotes, leaving the NormativeCube part off, and doing all that without the brackets. 我在excel的多维数据集公式中使用的多维数据集引用如下所示:'Cubename NormativeCube',因此我尝试将其粘贴在带引号和不带引号的方括号中,将NormativeCube部分保留下来,并在不使用方括号的情况下进行所有操作。

I also modified the last line after 'WHERE' to reflect date ranges like this: '[Calendar].[Calendar].[Month].& 1 &[2015]:[Calendar].[Calendar].[Month].&[12]&[2015]' 我还修改了'WHERE'之后的最后一行以反映如下日期范围:'[Calendar]。[Calendar]。[Month]。& 1 &[2015]:[Calendar]。[Calendar]。[Month]。& [12]&[2015]”

I've also set that as '[Calendar].[Month].[Month].& 1 :[Calendar].[Month].[Month].&[12]' 我也将其设置为“ [日历]。[月]。[月]。& 1 :[日历]。[月]。[月]。&[12]”

Also, one more question; 另外,还有一个问题; will this work for any date range, or is it intended to be specified in the MDX? 它将在任何日期范围内工作,还是打算在MDX中指定? I need it to function based on the date range set by the cube filters. 我需要它根据多维数据集筛选器设置的日期范围运行。

EDIT 2: 编辑2:

I just needed to tweak this a tad by changing the '> 0' to '= 0', as the original solution only showed the average for those that did not have data for each month in the date range, and adjust one of the calendar set expressions or whatever. 我只需要通过将“> 0”更改为“ = 0”来调整一点,因为原始解决方案仅显示日期范围内每个月没有数据的平均值,并调整其中一个日历设置表达式或其他内容。

IIF
 (
  [Measures].[OBSERVATIONS]>=100 
  AND 
  COUNT
    (
     FILTER
        (
        EXISTS
            (
            [Calendar].[Calendar].[Month].MEMBERS
            ,EXISTING [Calendar].[Calendar].[Month].MEMBERS
            )
        ,[Measures].[OBSERVATIONS] = 0
        )
    ) = 0
  ,[Measures].[AVERAGE]
  ,"^^"
 )

EDIT 3: 编辑3:

Found a limitation; 发现局限性;

the measure only works if the date range defined for the cube is in a whole increment of the calendar hierarchy; 仅当为多维数据集定义的日期范围是日历层次结构的整个增量时,此度量才有效; ie a single month, a single quarter, or a single year. 即一个月,一个季度或一年。 doing 2 months, 2 quarters, 2 years, or breaking across 2 quarters or years will return the False outcome from the IIF() expression. 如果执行2个月,2个季度,2年或中断2个季度或2年,则会从IIF()表达式返回False结果。

I played around with a few different ways to set it up, but can't get it to work. 我尝试了几种不同的设置方法,但无法使其正常工作。

EDIT 4: 编辑4:

Re: calendar hierarchy 回复:日历层次结构

Looking underneath [calendar].[calendar] there are 4 options: Year, Quarter, Month, & Date Key. 在[calendar]。[calendar]下面查看,有4个选项:Year,Quarter,Month和Date Key。

looking at the members under Year, Quarter, & Month, you can drill down all the way to the individual day. 查看“年”,“季度”和“月”下的成员,您可以一直追溯到一天。

The member properties under those 3 lists just the next level up the hierarchy 这3个成员下的成员属性仅列出层次结构的下一层

On Date Key, the member properties are as follows: Month Name Month of Year Time Calcs (this doesn't do much to my knowledge) Week of Year Week 在日期键上,成员属性如下:月份名称年份月份时间计算(据我所知,这没有多大作用)

EDIT 5: 编辑5:

So this is what worked (finally). 所以这才是最终的结果。 I must have messed something up at some point, and editing the original formula caused the secondary issue I was having. 我一定在某种程度上搞砸了,编辑原始公式会导致我遇到第二个问题。 Here's what worked for me. 这对我有用。

IIF
 (
  [Measures].[OBSERVATIONS]>=100 
  AND 
  COUNT
    (
     FILTER
        (
        EXISTS
            (
            [Calendar].[Calendar].[Month].Members
            ,EXISTING [Calendar].[Calendar].Members
            )
        ,[Measures].[OBSERVATIONS] = 0
        )
    ) > 0
  ,[Measures].[AVERAGE]
  ,"^^"
 )

Using the EXISTING clause comes in handy at times when you want your calculation to recognize a certain selection(context). 当您希望您的计算能够识别某个选择(上下文)时,使用EXISTING子句会很方便。 Following code is self explanatory. 以下代码不言自明。 Let me know if it works. 让我知道它是否有效。

WITH SET ZeroObservationMonths AS
FILTER
    (
    EXISTS
        (
        [Calendar].[Calendar].[Month].MEMBERS
        ,EXISTING [Calendar].[Calendar].[Date].MEMBERS
        )
     ,[Measures].[OBSERVATIONS] = 0
     )


MEMBER Measures.NewMeasure AS
IIF
 (
  [Measures].[OBSERVATIONS]>=100 AND COUNT(ZeroObservationMonths) > 0
  ,[Measures].[AVERAGE]
  ,"^^"
 )

SELECT [Project].[ProjectCode].MEMBERS ON 1,
Measures.[NewMeasure] ON 0
FROM [YourCube]
WHERE ({[Calendar].[Calendar].[Date].&D1: [Calendar].[Calendar].[Date].&D2})

EDIT: If you're planning on creating the measure inside excel, just have the below MDX code in the text box for "New calculated measure" 编辑:如果您打算在excel中创建度量,则只需在“新计算的度量”文本框中输入以下MDX代码

IIF
 (
  [Measures].[OBSERVATIONS]>=100 
  AND 
  COUNT
    (
     FILTER
        (
        EXISTS
            (
            [Calendar].[Calendar].[Month].MEMBERS
            ,EXISTING [Calendar].[Calendar].[Date].MEMBERS
            )
        ,[Measures].[OBSERVATIONS] = 0
        )
    ) > 0
  ,[Measures].[AVERAGE]
  ,"^^"
 )

EDIT 2: If the filtering can happen on any attribute, not just dates, replace EXISTING [Calendar].[Calendar].[Date].MEMBERS with EXISTING [Calendar].[Calendar].MEMBERS in the script above. 编辑2:如果可以对任何属性(而不只是日期EXISTING [Calendar].[Calendar].MEMBERS ,则在上面的脚本EXISTING [Calendar].[Calendar].MEMBERS EXISTING [Calendar].[Calendar].[Date].MEMBERSEXISTING [Calendar].[Calendar].MEMBERS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM