简体   繁体   English

MDX计算量度

[英]MDX Calculated Measure

Below is my requirement in the picture 以下是我对图片的要求

样本数据

The 1st table is at least granularity.The avg is calculated by Date + Place .So the avg is 565 = (2865/5) . 第一张表至少是粒度表565 = (2865/5)Date + Place计算得出,因此avg为565 = (2865/5)

Coming to the second table.The avg for place 702 is 114 which is right and for 704 it is 866 which is also right.But the final ans is the same as the avg for all 5 records. 进入第二张表。位置702的平均平均值是114,是正确的,而704的平均值是866同样也是正确的,但最终的ans与所有5条记录的平均值相同。

But my output should be like avg at Date + Place level for single Date + Place but when two places are selected it should avg at place level but sum at the total output..the final value should be 980 (sum(114+866)) 但我的输出应该是这样的,在平均Date + Place级别单Date + Place ,但是当两个地方都选择了它应该在的地方水平,但总和平均在总output..the终值应该是980(总和(114 + 866) )

Can someone have a solution for this? 有人可以为此解决方案吗?

As with any average in SSAS Multidimensional you will need to create two physical measures. 与SSAS多维中的任何平均值一样,您将需要创建两个物理度量。 The first is a Sum of A which is AggregateFunction=Sum. 第一个是A的总和,即AggregateFunction = Sum。 The second is a Count of Rows which is AggregateFunction=Count. 第二个是行数,即AggregateFunction = Count。

The quicker way to implement your calculation is with this calculated measure: 实施计算的更快方法是使用以下计算得出的度量值:

SUM(
 EXISTING [Place].[Place].[Place].Members,
 DIVIDE( [Measures].[Sum of A], [Measures].[Count of Rows] )
)

However if you want to get better performance and properly handle multi-select filters then create a physical measure called Avg A which is AggregateFunction=Sum off a new column in your SQL table which is always 0. Then overwrite the values in that measure with the following scope statement: 但是,如果要获得更好的性能并正确处理多选过滤器,请创建一个称为Avg A的物理度量,该度量为AggregateFunction = Sum减去SQL表中始终为0的新列。然后使用以下范围声明:

SCOPE([Place].[Place].[Place].Members);
     [Measures].[Avg A] = DIVIDE( [Measures].[Sum of A], [Measures].[Count of Rows] );
END SCOPE;

Try this: 尝试这个:

AvgA = SUMX(SUMMARIZE(Table2, Table2[Place], "A", AVERAGE(Table2[A])), [A])

This will take the average A grouping by each Place and then sum them up for the subtotal. 这将按照每个Place的平均A分组,然后Place它们相加得出小计。

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

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