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 文件时, ...
随机推荐
- [Erlang36]kerl轻松管理安装各种OTP版本
kerl只有一个目标:让我们在不同的OTP版本间随意切换.他是一个纯Bash项目.简单实用的工作利器! Readme里面用法已说明得非常清楚了.建议按流程来一次. 1.下载 安装(一个bash脚本,根 ...
- WebApi 插件式构建方案:发现并加载程序集
插件式的 WebApi 开发,首要面对的问题就是程序集的发现.因为开发的过程中,都是在各自的解决方案下进行开发,部署后是分模块放在一个整体的的运行时网站下. 约定 这里我根据上一节的设定,把插件打包完 ...
- tar.gz 解压
tar -xzvf .tar.gz tar [-cxtzjvfpPN] 文件与目录 .... 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的参数指令! ...
- C#发送邮件(使用SSL,587端口)
static readonly string smtpServer = System.Configuration.ConfigurationManager.AppSettings["Smtp ...
- “全栈2019”Java第一百一十三章:什么是回调?回调应用场景详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- Spring中 使用注解+c3p0+事物 《模拟银行转账》
使用注解的方式 模拟转账 要么都成功 要么都失败 !保持一致性! 准备工作: jar包: 需要的类: UserDao: package com.hxzy.spring.c3p0.Dao ...
- Elasticsearch(9):使用Logstash-input-jdbc同步数据库中的数
1.数据同步方式 全量同步与增量同步 全量同步是指全部将数据同步到es,通常是刚建立es,第一次同步时使用.增量同步是指将后续的更新.插入记录同步到es. 2.常用的一些ES同步方法 1). elas ...
- vue + ElementUI 表格筛选框的高度设置,超出一定高度,显示滚动条
相信有很多小伙伴遇到过这个问题,首先还是来看图片,筛选框我做了处理,所以和官网的有点小差别 官方网站和个人网站对比图如下: 代码如下:(F12找到该元素的class,设置高度) .el-table-f ...
- 敏感词过滤的算法原理之 Aho-Corasick 算法
参考文档 http://www.hankcs.com/program/algorithm/implementation-and-analysis-of-aho-corasick-algorithm-i ...
- iOS学习笔记(6)——翻译苹果文档About Windows and Views
About Windows and Views 关于窗口和视图 In iOS, you use windows and views to present your application’s cont ...