FocusBI:地产分析&雪花模型
微信公众号:FocusBI
关注可了解更多的商业智能、数据仓库、数据库开发、爬虫知识及沪深股市数据推送。问题或建议,请关注公众号发送消息留言;
如果你觉得FocusBI对你有帮助,欢迎转发朋友圈或在文章末尾点赞[1]
《商业智能教程》pdf下载地址
链接:https://pan.baidu.com/s/1f9VdZUXztwylkOdFLbcmWw 密码:2r4v
在《租房分析&星型模型》中讲了如何创建一个星型模型的SSAS项目方案,这里我做一个雪花模型案例。雪花模型是在星型模型的基础上进行修改。
雪花模型
雪花模型其实就是把多个表合成一个维度,有减少数据沉余的作用,也易于维护和属性扩展,这里使用地产数据举例, 维度有 房间、楼栋、项目、区域、日期,其实房间、楼栋、项目、区域这些数据都是包含关系,如 房间的上一级是楼栋、楼栋的上一级是项目、项目的上一级是区域,而事实数据签约、认购、回款 是地产通用的三张表,也是明源ERP的核心。

日期维度
日期维度是任何项目都通用的维度,只要涉及到金额数量就会有按年-季-月、年-季-月-日、年-周、年天、月天、星期、旬等这些角度去看数据。那么怎样才能得到某一天是属于哪一年、哪个季度、哪个月、哪个周、那一年的某天、哪个旬、星期几?这里就用存储过程来实现,虽然SSAS提供了智能日期维度,也对财务日期做了一些修改,但是它毕竟是美国人的思维模式很难复合中国国情需要的日期,比如美国人一周的第一天是周日,而中国是周一。那么怎么来实现这个存储过程,这个存储过程可以写的比较长容易看懂如果对SQL 的日期处理比较熟悉的话只要几行就能完成不容易看懂。这里我就是用容易看懂的比较长的SQL语句来实现。
日期存储过程
SETANSI_NULLSON
GO
SETQUOTED_IDENTIFIERON
GO
-- =============================================
-- Author: FocusBI
-- Create date: 20180824
-- Description: 完整的日期信息表
--=============================================
ALTERPROCEDURE [dbo].[Dim_Date]@BeginDate nvarchar(8), @EndDate nvarchar(8)
AS
BEGIN
declare @DateKey int
declare @dtEndOfDay datetime
set @dtEndOfDay =convert(datetime,cast(@BeginDate asnvarchar),120)
set @DateKey =convert(varchar,@dtEndOfDay,112)
while @dtEndOfDay <convert(datetime,cast(@EndDate asnvarchar),120)
begin
select @DateKey as DateKey,
@dtEndOfDayasData,
YEAR(@dtEndOfDay)asYear,
casewhenMonth(@dtEndOfDay)<= 6 then'上半年'
else'下半年'endas HalfAYear,
datepart(qq,@dtEndOfDay)as Quarter_num,
casewhendatepart(qq,@dtEndOfDay)= 1 then'Q1'
whendatepart(qq,@dtEndOfDay)= 2 then'Q2'
whendatepart(qq,@dtEndOfDay)= 3 then'Q3'
else'Q4' endas Quarter_EN,
casewhendatepart(qq,@dtEndOfDay)= 1 then'一季度'
whendatepart(qq,@dtEndOfDay)= 1 then'二季度'
whendatepart(qq,@dtEndOfDay)= 1 then'三季度'
else'四季度'endas Quarter_CN,
month(@dtEndOfDay)as Month_num,
casewhenmonth(@dtEndOfDay)= 1 then'January'
whenmonth(@dtEndOfDay)= 2 then'February'
whenmonth(@dtEndOfDay)= 3 then'March'
whenmonth(@dtEndOfDay)= 4 then'April'
whenmonth(@dtEndOfDay)= 5 then'May'
whenmonth(@dtEndOfDay)= 6 then'June'
whenmonth(@dtEndOfDay)= 7 then'Jul'
whenmonth(@dtEndOfDay)= 8 then'August'
whenmonth(@dtEndOfDay)= 9 then'September'
whenmonth(@dtEndOfDay)= 10 then'October'
whenmonth(@dtEndOfDay)= 11 then'November'
else'December'end Month_EN ,
casewhenmonth(@dtEndOfDay)= 1 then'Jan'
whenmonth(@dtEndOfDay)= 2 then'Feb'
whenmonth(@dtEndOfDay)= 3 then'Mar'
whenmonth(@dtEndOfDay)= 4 then'Apr'
whenmonth(@dtEndOfDay)= 5 then'May'
whenmonth(@dtEndOfDay)= 6 then'Jun'
whenmonth(@dtEndOfDay)= 7 then'Jul'
whenmonth(@dtEndOfDay)= 8 then'Aug'
whenmonth(@dtEndOfDay)= 9 then'Sep'
whenmonth(@dtEndOfDay)= 10 then'Oct'
whenmonth(@dtEndOfDay)= 11 then'Nov'
else'Dec'end Month_JX ,
casewhenmonth(@dtEndOfDay)= 1 then'一月'
whenmonth(@dtEndOfDay)= 2 then'二月'
whenmonth(@dtEndOfDay)= 3 then'三月'
whenmonth(@dtEndOfDay)= 4 then'四月'
whenmonth(@dtEndOfDay)= 5 then'五月'
whenmonth(@dtEndOfDay)= 6 then'六月'
whenmonth(@dtEndOfDay)= 7 then'七月'
whenmonth(@dtEndOfDay)= 8 then'八月'
whenmonth(@dtEndOfDay)= 9 then'九月'
whenmonth(@dtEndOfDay)= 10 then'十月'
whenmonth(@dtEndOfDay)= 11 then'十一月'
else'十二月'end Month_CN ,
day(@dtEndOfDay)as [Month_Day] ,
DATENAME(dy,@dtEndOfDay)as Year_Day,
DATENAME(wk,@dtEndOfDay)as Year_Week,
casewhenday(@dtEndOfDay)< 10 then'上旬'
whenday(@dtEndOfDay)> 20 then'下旬'
else'中旬' end as TenDays,
Datepart(dw,@dtEndOfDay)as WeekDay_num,
datename(dw,@dtEndOfDay)as WeekDay_CN,
casewhendatename(dw,@dtEndOfDay)='星期一'then 1
whendatename(dw,@dtEndOfDay)='星期二'then 2
whendatename(dw,@dtEndOfDay)='星期三'then 3
whendatename(dw,@dtEndOfDay)='星期四'then 4
whendatename(dw,@dtEndOfDay)='星期五'then 5
whendatename(dw,@dtEndOfDay)='星期六'then 6
else 7 endas WeekDay_Short_CN,
casewhenDatepart(dw,@dtEndOfDay) = 1 then'星期一'
whenDatepart(dw,@dtEndOfDay) = 2 then'星期二'
whenDatepart(dw,@dtEndOfDay) = 3 then'星期三'
whenDatepart(dw,@dtEndOfDay) = 4 then'星期四'
whenDatepart(dw,@dtEndOfDay) = 5 then'星期五'
whenDatepart(dw,@dtEndOfDay) = 6 then'星期六'
else'星期日'endas WeekDay_EN,
casewhenDatepart(dw,@dtEndOfDay)= 1 then'周末'
whenDatepart(dw,@dtEndOfDay)= 7 then'周末'
else'平时'endas Weekend
set @dtEndOfDay = @dtEndOfDay + 1
set @DateKey =convert(varchar,@dtEndOfDay,112)
end
END
实现日期维度
在<星型模型_Dome >方案的基础上把 名字改成 <星型模型VS雪花模型_Dome>,把雪花模型跟星型模型做在一起方便对比。根据前面演示的步骤把日期表Dim_Date导入,按照步骤一步一步的完成下图的日期维度,这个type类型一定要设置成time , 如果没有设置成time 后面的MDX同比环比就不好通过层结构计算。

项目维度
导入房间、楼栋、项目、区域四个维度表建立好关系,下图地产分析就是典型的雪花模型,

在创建项目信息维度时有最为核心的一步是他们是层级关系。


地产多维数据集

历史文章:
FocusBI: 使用Python爬虫为BI准备数据源(原创)
FocusBI关注者
FocusBI:SSAS体系结构(原创)
FocusBI:租房分析&星型模型
FocusBI:地产分析&雪花模型
FocusBI:MDX检索多维模型
FocusBI:租房分析可视化(网址体验)
FocusBI: 《DW/BI项目管理》之数据库表结构 (原创)
FocusBI:地产分析&雪花模型的更多相关文章
- FocusBI:租房分析&星型模型
微信公众号:FocusBI关注可了解更多的商业智能.数据仓库.数据库开发.爬虫知识及沪深股市数据推送.问题或建议,请关注公众号发送消息留言;如果你觉得FocusBI对你有帮助,欢迎转发朋友圈或在文章末 ...
- FocusBI:租房分析可视化(PowerBI网址体验)
微信公众号:FocusBI关注可了解更多的商业智能.数据仓库.数据库开发.爬虫知识及沪深股市数据推送.问题或建议,请关注公众号发送消息留言;如果你觉得FocusBI对你有帮助,欢迎转发朋友圈或在文章末 ...
- 微软BI 之SSAS 系列 - 基于雪花模型的维度设计
基于雪花模型的维度以下面的 Product 产品与产品子类别,产品类别为例. DimProduct 表和 DimProductSubcategory 表有外键关系,而 DimProductSubcat ...
- 分析业务模型-类图(Class Diagram)
分析业务模型-类图(Class Diagram) 分析业务模型-类图(Class Diagram)(上) 摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并 ...
- SSAS中雪花模型
上面的[销售事实表]与[门店]维度.[集团]维度就组成了一个雪花模型. 1.可以把[集团]关联到[门店]的维度上去: 2.如果要把[集团]作为一个单独的维度,先在[维度]里把Dim_Group添加进来 ...
- 前端MVC框架Backbone 1.1.0源码分析(二) - 模型
模型是什么? Models are the heart of any JavaScript application, containing the interactive data as well a ...
- Netty源码分析--内存模型(上)(十一)
前两节我们分别看了FastThreadLocal和ThreadLocal的源码分析,并且在第八节的时候讲到了处理一个客户端的接入请求,一个客户端是接入进来的,是怎么注册到多路复用器上的.那么这一节我们 ...
- Netty源码分析--内存模型(下)(十二)
这一节我们一起看下分配过程 PooledByteBuf<T> allocate(PoolThreadCache cache, int reqCapacity, int maxCapacit ...
- HotSpot源码分析之类模型
HotSpot采用了OOP-Klass模型描述Java的类和对象.Klass模型采用Klass类及相关子类的对象来描述具体的Java类.一般HotSpot JVM 在加载Java的Class 文件时, ...
随机推荐
- django设置cookie和session
1 设置cookie 本例中应用名称为cookie 模型model from django.db import models from django.db import models class Us ...
- XEvent--Demo--使用XEvent来捕获在数据库DB1上发生的锁请求和锁释放
--==============================================================--使用XEvent来捕获在数据库DB1上发生的锁请求和锁释放--=== ...
- Tempdb--查看TempDB上是否需要增加文件
SELECT [owt].[session_id], [owt].[exec_context_id], [owt].[wait_duration_ms], [owt].[wait_type], [ow ...
- 查看JVM
通过jconsole.exe来查看,jconsole.exe所在目录为/%JAVA_HOME%/bin/jconsole.exe 需要配置: -Dcom.sun.management.jmxrem ...
- 基于ASP.NET MVC 利用(Aspose+Pdfobject.js) 实现在线预览Word、Excel、PPT、PDF文件
#region VS2010版本以及以上版本源码下载地址:http://download.csdn.net/download/u012949335/10231812 VS2012版本以及以上版本源码下 ...
- 没有xaml的WPF
出于强迫症,我查了一下文档弄明白了WPF脱离xaml应该怎么搞.当然其实本质是为了MaxScript里使用做准备. using System; using System.Windows; using ...
- 「HNOI 2015」实验比较
\(Description\) 有\(n\)个元素,对于每个元素\(x_i\)最多知道一个形如\(x_j < x_i\)或\(x_j=x_i\)的条件,问有多少合法的序列.合法的序列满足每个元素 ...
- iOS 需要了解的
1. 用 CocoaPods 来管理应用用到的第三方库. 2. Jenkins 3. Robotium 4. RESS
- 【Oracle 12c】CUUG OCP认证071考试原题解析(35)
35.choose the best answer View the Exhibit and examine the description of the EMPLOYEES table. Evalu ...
- BZOJ 1248--游乐园(DFS&贪心)
1248: 游乐园Pleasure Ground Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 6 Solved ...