简体   繁体   English

SSAS测量平均值与范围值相关

[英]SSAS Measure average related to range values

I have Sales data provided weekly and Lookup data provided quarterly. 我每周都会提供销售数据,每季度提供一次查询数据。 In the SSAS data cube I have pre-calculated average of sales data for each period of time and what I need to do is to get related record from LookupTable for next calculations, where: LookupTable.Min < Sales Average < LookupTable.Max 在SSAS数据立方体中,我预先计算了每个时间段的销售数据的平均值,我需要做的是从LookupTable获取相关记录以进行下一次计算,其中: LookupTable.Min <Sales Average <LookupTable.Max

Example: 例:

Sales = 297 + 33 + 311 = 641 销售额= 297 + 33 + 311 = 641

SalesAverage = 213.66 SalesAverage = 213.66

LookupRecordShrinkageIndicator = Min < SalesAverage < Max = 0 < 213.66 < 9000 = 0.007 LookupRecordShrinkageIndicator = Min <SalesAverage <Max = 0 <213.66 <9000 = 0.007

CREATE TABLE dbo.SalesData
(
    Id int,
    Sales decimal(18, 2)    )


CREATE TABLE dbo.LookupTable
(
    Id int,
    Min int,
    Max int,
    Shrinkage decimal(10, 5),
    Wages decimal(10, 5),
    Waste decimal(10, 5)
 )

INSERT [dbo].[SalesData] ([Id], [Sales]) VALUES (1, 297)
INSERT [dbo].[SalesData] ([Id], [Sales]) VALUES (2, 33)
INSERT [dbo].[SalesData] ([Id], [Sales]) VALUES (3, 311)

INSERT [dbo].[LookupTable] ([Id], [Min], [Max], [Shrinkage], [Wages], [Waste]) VALUES (1, 0, 9000, 0.00700, 0.12700, 0.00300)
INSERT [dbo].[LookupTable] ([Id], [Min], [Max], [Shrinkage], [Wages], [Waste]) VALUES (2, 9000, 9250, 0.00700, 0.12700, 0.00300)
INSERT [dbo].[LookupTable] ([Id], [Min], [Max], [Shrinkage], [Wages], [Waste]) VALUES (3, 9250, 9500, 0.00700, 0.12300, 0.00300)

I need to create calculated member based on sales average which contains indicators from lookup table for next calculations. 我需要根据销售平均值创建计算成员,其中包含查找表中的指标以供下次计算。

To solve this issue I had to use my LookupTable as dimension and as measures, let's see how I did this. 要解决这个问题,我必须使用LookupTable作为维度和度量,让我们看看我是如何做到这一点的。

  1. Create dimension based on LookupTable: 基于LookupTable创建维度:

  2. Add Lookup measures do the cube and add Lookup dimension to the cube as well. 添加查找度量执行多维数据集并将查找维度添加到多维数据集。 立方体设计视图

  3. Create Fact relationship between Lookup dimension and Lookup measures group 在Lookup维度和Lookup度量值组之间创建事实关系

That's all: 就这样:

Let's see mdx example: 我们来看看mdx示例:

SELECT 
{
    FILTER([Lookup Table].[Id].AllMembers ,  [Measures].[Min] <= 213 AND [Measures].[Max] > 213 )
}
ON COLUMNS,
{
    [Measures].[Shrinkage - Lookup Table], [Measures].[Wages - Lookup Table], [Measures].[Waste - Lookup Table]

} ON ROWS
FROM
[MyCube]

And result: 结果:

MDX查询结果

I hope this example will be useful 我希望这个例子很有用

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

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