SQL Server 2008 Analysis Services(OLAP) - 环比、同比
2010-07-25 17:21
288 查看
--- 同期比较 Cousin
登记日期不连续,存在空缺 ===>
登记日期维度:每月/每天都存在,尽管在事实表中不存在的“天”
Case
When IsEmpty
(
(
Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),
[Measures].[Sfzh Distinct Count]
)
)
Then Null
Else (
( [Dim Djrq].[YearMonthDay].CurrentMember,[Measures].[Sfzh Distinct Count] )
-
( Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),[Measures].[Sfzh Distinct Count] )
)
/
( Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),[Measures].[Sfzh Distinct Count])
End
--- 同期比较 parallelperiod
--- 同期比较 Generate/DOWSet
With Member [Measures].[PrevWeekSales] as
([Measures].[Sales Amount],
Generate(
{[Date].[Date].CurrentMember,Exists([Date].[Date].[Date].Members,[Date].[Day of Week].CurrentMember) as DOWSet}.Item(0),
DOWSet.Item(Rank([Date].[Date].CurrentMember,DOWSet) - 2)).Item(0)
), FORMAT_STRING = "Currency"
select {[Measures].[Sales Amount], [Measures].[PrevWeekSales]} on 0,
{[Date].[Date].&[20010701]:[Date].[Date].&[20010714]} on 1
from [Adventure Works]
--- 环比
Case
When [Dim Djrq].[YearMonthDay].CurrentMember.Level.Ordinal = 0
Then Null
When IsEmpty
(
(
[Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,
[Measures].[Sfzh Distinct Count]
)
)
Then Null
When IsEmpty
(
(
[Dim Djrq].[YearMonthDay].CurrentMember,
[Measures].[Sfzh Distinct Count]
)
)
Then Null
Else (
( [Dim Djrq].[YearMonthDay].CurrentMember,[Measures].[Sfzh Distinct Count] )
-
( [Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,[Measures].[Sfzh Distinct Count] )
)
/
( [Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,[Measures].[Sfzh Distinct Count])
End
登记日期不连续,存在空缺 ===>
登记日期维度:每月/每天都存在,尽管在事实表中不存在的“天”
Case
When IsEmpty
(
(
Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),
[Measures].[Sfzh Distinct Count]
)
)
Then Null
Else (
( [Dim Djrq].[YearMonthDay].CurrentMember,[Measures].[Sfzh Distinct Count] )
-
( Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),[Measures].[Sfzh Distinct Count] )
)
/
( Cousin([Dim Djrq].[YearMonthDay].CurrentMember, [Dim Djrq].[YearMonthDay].CurrentMember.Parent.PrevMember),[Measures].[Sfzh Distinct Count])
End
--- 同期比较 parallelperiod
--- 同期比较 Generate/DOWSet
With Member [Measures].[PrevWeekSales] as
([Measures].[Sales Amount],
Generate(
{[Date].[Date].CurrentMember,Exists([Date].[Date].[Date].Members,[Date].[Day of Week].CurrentMember) as DOWSet}.Item(0),
DOWSet.Item(Rank([Date].[Date].CurrentMember,DOWSet) - 2)).Item(0)
), FORMAT_STRING = "Currency"
select {[Measures].[Sales Amount], [Measures].[PrevWeekSales]} on 0,
{[Date].[Date].&[20010701]:[Date].[Date].&[20010714]} on 1
from [Adventure Works]
--- 环比
Case
When [Dim Djrq].[YearMonthDay].CurrentMember.Level.Ordinal = 0
Then Null
When IsEmpty
(
(
[Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,
[Measures].[Sfzh Distinct Count]
)
)
Then Null
When IsEmpty
(
(
[Dim Djrq].[YearMonthDay].CurrentMember,
[Measures].[Sfzh Distinct Count]
)
)
Then Null
Else (
( [Dim Djrq].[YearMonthDay].CurrentMember,[Measures].[Sfzh Distinct Count] )
-
( [Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,[Measures].[Sfzh Distinct Count] )
)
/
( [Dim Djrq].[YearMonthDay].CurrentMember.PrevMember,[Measures].[Sfzh Distinct Count])
End
相关文章推荐
- SQL Server 2008 Analysis Services(OLAP) - unknown member
- SQL Server 2008 Analysis Services(OLAP) - drill through
- SQL Server 2008 – How To Build and Deploy AdventureWorks OLAP Cubes
- 在IIS中共享OLAPService,基于(SQL Server 2008 OLAP Service)
- 知识小结(Sql server 2008 OLAP)
- sql server 获取同比或环比
- SQL Server 2008 Analysis Services(OLAP) - jpivot fetch hierarchy/level/members
- SQL server 2008数据库的备份与还原
- Sql Server 2008 安装常见问题
- Win Server 2008, Visual Studio 2008, SQL Server 2008 的纪念版可乐
- SQL Server 2008如何创建定期自动备份任务
- SQL SERVER 2008 “阻止保存要求重新创建表的更改” 解决方法
- 基于Sql Server 2008的分布式数据库的实践(一)
- VS2010 自带的SQL SERVER 2008 EXPRESS 如何连接?
- SQL Server 2008编程入门经典(第3版) 学习记录1
- SQL Server 2008 126错误代码
- SQL Server 2008 数据库同步的两种方式 (发布、订阅)
- ibatisnet连接sql server 2008连接方法
- SQL SERVER 2008分页
- MyEclipse连接SQL Server 2008 错误提示:TCP端口1433,sql server 2008 Connection refused:connect