加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

用分析服务SSAS解决占比、同比和环比问题

发布时间:2020-12-14 04:07:34 所属栏目:大数据 来源:网络整理
导读:本文将介绍用分析服务SSAS如何解决占比、同比和环比三个指标。 首先理解一下这三个指标的基本概念: 占比 是指当前成员的值与该成员父级的值的比率,意思是在总数中所占的比重,比如某水果商店总销售额为14,其中苹果的销售额为2,占比就是14.3%。 同比 是

本文将介绍用分析服务SSAS如何解决占比、同比和环比三个指标。

首先理解一下这三个指标的基本概念:

占比是指当前成员的值与该成员父级的值的比率,意思是在总数中所占的比重,比如某水果商店总销售额为14,其中苹果的销售额为2,占比就是14.3%。

同比是指在一个期间内的值与以前某个期间的值进行比较,并用以前期间值的百分比来表示,比如将今年的数据与去年的数据比较或将今年八月的数据与去年八月的数据比较。

环比是指当前成员的值与前一个成员的值的比率,比如将今年的下半年数据与上半年数据比较或将今年的八月的数据与七月的数据比较。

其中占比一般不会运用在时间维度上,而占比和同比均是运用在时间维度上。

那么在分析服务中是如何解决这三个指标的呢?一般情况下,多维数据集中的每一个维度都会有层次结构,比如时间维度的层次结构,年-半年-季度-月-日或年-周-日,其中同比和环比正是在这个层次结构中进行比较。分析服务利用计算成员可以方便的解决以上三个指标,而且分析服务提供了相应的模板。

第一、占比。

MDX语句定义如下:

CREATE MEMBER CURRENTCUBE.[Measures].[销售数量在父级销售单位的占比]
AS 
Case
// Test to avoid division by zero.
When IsEmpty
     ( 
        [Measures].[Sell Num]
     ) 
Then Null
// Test for current coordinate being on the (All) member.
When [Dim Unit].[省-市-区-单位].CurrentMember.Level Is
     [Dim Unit].[省-市-区-单位].[(All)]
Then 1
Else ( [Dim Unit].[省-市-区-单位].CurrentMember,[Measures].[Sell Num] ) 
     /
     ( [Dim Unit].[省-市-区-单位].CurrentMember.Parent,[Measures].[Sell Num] )
End,FORMAT_STRING = "Percent";


第二、同比。

MDX语句定义如下:

CREATE MEMBER CURRENTCUBE.[Measures].[销售数量期间增长率]
AS 
Case
// Test for current coordinate being on (All) member.
When [Dim Date].[年-半年-季度-月-日].CurrentMember.Level Is
     [Dim Date].[年-半年-季度-月-日].[(All)]
Then "NA"
// Test to avoid division by zero.
When IsEmpty(
    (
	  [Measures].[Sell Num],ParallelPeriod(
	  [Dim Date].[年-半年-季度-月-日].[Yearly SK],1,[Dim Date].[年-半年-季度-月-日].CurrentMember
	  )
    )
) 
Then Null
Else ( 
       (([Dim Date].[年-半年-季度-月-日].CurrentMember,[Measures].[Sell Num]) 
	   -(
		[Measures].[Sell Num],ParallelPeriod(
		[Dim Date].[年-半年-季度-月-日].[Yearly SK],[Dim Date].[年-半年-季度-月-日].CurrentMember
		)))
	 /
     (
	[Measures].[Sell Num],ParallelPeriod(
	[Dim Date].[年-半年-季度-月-日].[Yearly SK],[Dim Date].[年-半年-季度-月-日].CurrentMember
	)))
End
// This expression evaluates the difference between the value of the numeric
// expression in the previous period and that of the current period,as a
// percentage of the previous period's value.
FORMAT_STRING = "Percent";

第三、环比。

MDX语句定义如下:

CREATE MEMBER CURRENTCUBE.[Measures].[销售数量环比]
AS 
Case
// Test for current coordinate being on (All) member.
When [Dim Date].[年-半年-季度-月-日].CurrentMember.Level Is
     [Dim Date].[年-半年-季度-月-日].[(All)]
Then "NA"
// Test to avoid division by zero.
When IsEmpty(
    (
   [Measures].[Sell Num],[Dim Date].[年-半年-季度-月-日].CurrentMember.PrevMember
    )
) 
Then Null
Else ( 
       (([Dim Date].[年-半年-季度-月-日].CurrentMember,[Measures].[Sell Num]) 
    -(
  [Measures].[Sell Num],[Dim Date].[年-半年-季度-月-日].CurrentMember.PrevMember)
   )
  /
     (
   [Measures].[Sell Num],[Dim Date].[年-半年-季度-月-日].CurrentMember.PrevMember))
End,FORMAT_STRING = "Percent";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读