gpt4 book ai didi

sql-server - SSAS 测量与范围值相关的平均值

转载 作者:行者123 更新时间:2023-12-03 17:44:09 25 4
gpt4 key购买 nike

我每周提供销售数据,每季度提供查找数据。
在 SSAS 数据立方体中,我预先计算了每个时间段的销售数据平均值,我需要做的是从 LookupTable 中获取相关记录以进行下一步计算,其中: LookupTable.Min < 平均销售额 < LookupTable.Max

例子:

销售额 = 297 + 33 + 311 = 641

平均销售额 = 213.66

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)

我需要根据销售平均值创建计算成员,其中包含查找表中的指标以供下一次计算。

最佳答案

为了解决这个问题,我不得不使用我的 LookupTable 作为维度和度量,让我们看看我是如何做到的。

  • 基于 LookupTable 创建维度:
  • 添加查找度量执行多维数据集并将查找维度添加到多维数据集。
    Cube design view
  • 在查找维度和查找度量组之间创建事实关系

  • 就这样:

    让我们看看 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]

    结果:

    MDX Query result

    我希望这个例子会有用

    关于sql-server - SSAS 测量与范围值相关的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19421964/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com