OLAP分析(八)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wh_xia_jun/article/details/90747656

关键词:

members

currentMembers

parent

children

decendant

avg

Time  : PrevMember(前一期)

Time:ParallelPeriod(同期)

Time:PeriodsToDate(期间累计)

lag、lead、ParallelPeriod+avg()、max\min等(求移动平均、一个周期最大、最小等):这个因为我们项目暂时用不到,不介绍。

LastPeriods

本章节内容比较多,介绍通用计算上半部分:

Many kinds of ratios, averages, percentages, and allocation

Simple ratios between levels in a hierarchy

Ratio to parent 

Ratio to ancestor 

Ratio to [All] 

Percentage contribution to parent/ancestor/All 

Handling divide-by-zero 

Basic allocations 

Proportional allocation of one quantity based on the ratios of another 

Unweighted allocations down the hierarchy 

Averages

Simple averages 

Weighted averages 

Time-based references and time-series calculations 

Period-to-period references and calculations

Year-ago references and calculations 

Year-to-date (period-to-date) aggregations

Rolling averages

52-week high/low

Mixing aggregations: sum across non-time, average/min/max along time

Mixing aggregations: sum across non-time, opening/closing balance along time

Using member properties in MDX expressions (calculations and sorting)

Filling in blanks

Carryover of balances for slowly changing values

Reporting of last entered balance (as opposed to balance for last time descendant)

Finding the last time member for which any data has been entered

先上图,不解释:

(各种引用用到的概念)

贡献率(占比):

占总额的比例

占父节点比例

1、对总额的贡献率

//占比1  /全部收入
        String mdxStr_101 =
                "with member [Measures].[占比] as  '[Measures].[金额]/([Measures].[金额],[All Account])'" +
                        "SELECT "+
                        "{[Measures].[金额],[Measures].[占比]} ON COLUMNS,"
                        +"non empty {[Account].[Account_L].Children} ON ROWS "
                        + "FROM [Col_trade_detail]" +
                        "   where [Time].[Time].[2017]";

结果:

parent:查看占上级收入的比例。看到这里,我想看看政府基金收入的构成及其占比:

        String mdxStr_102 =
                "with member [Measures].[占上级项目比例] as  '[Measures].[金额]/([Measures].[金额],[Account].CurrentMember.Parent)'" +
                        "SELECT "+
                        "{[Measures].[金额],[Measures].[占上级项目比例]} ON COLUMNS,"
                        +"non empty {[Account].[Account_L].[政府性基金收入],[Account].[Account_L].[政府性基金收入].Children} ON ROWS "

结果:

可以看出,2017年,政府基金占该县全部非税收入的64%,其中,最大头是其他基金收入及国有土地使用权出让金收入。其他基金收入中,大头还是和土地有关的收入。

Ancestor:(占祖先的比例)

我希望进一步看看国有土地使用权出让金收入、及其他基金的构成及比例情况:

//占指定祖先级别比例
        String mdxStr_103 =
                "with  member [Measures].[Proportion] as" +
                        "'[Measures].[金额]/([Measures].[金额],Ancestor([Account].CurrentMember,[Account].[Level2projectname]))',solve_order=5,format_string='0%'" +
                        "select {[Measures].[金额],[Measures].[Proportion]} on columns," +
                        "non empty {Descendants([Account].[政府性基金收入].[其他基金收入],[Account].[Level3projectname],SELF_AND_BEFORE)," +
                        "Descendants([Account].[政府性基金收入].[国有土地使用权出让金收入],[Account].[Level3projectname],SELF_AND_BEFORE)} ON ROWS" +
                        " from [Col_trade_detail] " +
                      "   where [Time].[Time].[2017]";

结果:

这里不过是进一步确认的和土地相关的资金,占非税收入的最大份额,不过,是不是可以加上房租呢,我再修改mdx语句:

        //增加房租收入2
        String mdxStr_105 =
                "with  member [Measures].[Proportion] as" +
                        "'[Measures].[金额]/([Measures].[金额],[All Account])',solve_order=1,format_string='0%' member " +
                        "[Account].[小计] as '[Account].[政府性基金收入].[其他基金收入].[补充耕地指标交易收入]+" +
                        "[Account].[政府性基金收入].[国有土地使用权出让金收入].[土地出让金收入]+" +
                        "[Account].[其他收入].[其他收入].[房租收入]'" +
                        "select {[Measures].[金额],[Measures].[Proportion]} on columns," +
                        "non empty {[Account].[All Account],[Account].[政府性基金收入].[其他基金收入].[补充耕地指标交易收入]," +
                        "[Account].[政府性基金收入].[国有土地使用权出让金收入].[土地出让金收入]," +
                        "[Account].[其他收入].[其他收入].[房租收入],[Account].[小计]} ON ROWS" +
                        " from [Col_trade_detail] " +
                        "   where [Time].[Time].[2017]";

结果:

可以看出,2017年,土地、地产相关业务,占63%,是非税的收入的主力。

Members:

回到前面章节的问题,我只想看到第3层收费项目数据:

//非税项目层级比较多,我只想看到第3层
        String mdxStr_106 ="select {[Measures].[金额]} on columns,"+
        "non empty {[Account].[Account_L].[Level3projectname].Members} ON ROWS"+
                " from [Col_trade_detail] " +
                "   where [Time].[Time].[2017]";

结果:

果然直到第3层,其实,也可以用Ancestor函数,实现同样的功能,不过,项目太多,我想对他们排序:

        //增加排序
        String mdxStr_107 ="select {[Measures].[金额]} on columns,"+
                "non empty {order([Account].[Account_L].[Level3projectname].Members,[Measures].[金额],desc)} ON ROWS"+
                " from [Col_trade_detail] " +
                "   where [Time].[Time].[2017]";
        //增加排序2
        String mdxStr_108 ="select {[Measures].[金额]} on columns,"+
                "non empty {order([Account].[Account_L].[Level3projectname].Members,[Measures].[金额],bdesc)} ON ROWS"+
                " from [Col_trade_detail] " +
                "   where [Time].[Time].[2017]";

 结果:

(大项排序) 

 (明细项排序)

我也可用Ancestor:

        //Descendants
        String mdxStr_109 ="select {[Measures].[金额]} on columns,"+
                "non empty {order( Descendants([Account].[Account_L],[Account].[Level3projectname],SELF_AND_BEFORE)," +
                "[Measures].[金额],desc)} ON ROWS"+
                " from [Col_trade_detail] " +
                "   where [Time].[Time].[2017]";

结果:

 对排序结果增加占比列:

        //增加排序2 增加占比
        String mdxStr_110 ="with  member [Measures].[Proportion] as" +
                "'[Measures].[金额]/([Measures].[金额],[All Account])',solve_order=1,format_string='0%' "+
                " select {[Measures].[金额],[Measures].[Proportion]} on columns,"+
                "non empty {order([Account].[Account_L].[Level3projectname].Members,[Measures].[金额],bdesc)} ON ROWS"+
                " from [Col_trade_detail] " +
                "   where [Time].[Time].[2017]";

结果:

可以看出,排名前3的都是资产带来的收入,这些收入,是不是可以看成一种土地税呢。
我推测公安行政事业性收费收入的数据比较准确,我就专门来看看这组数据:比较2015-2016-2017的变化,先求其均值,

求机动车辆号牌工本费,10年来大于均值的年份:

Avg 平均值问题

        //均值
        String mdxStr_113 ="WITH SET [MyY] AS " +
                " '{[Time].[2009]:[Time].[2017]}'"+
                " MEMBER [Time].[Avg Over Y] AS 'Avg ([MyY])' "+
                " select {[Time].[2009]:[Time].[2017],[Time].[Avg Over Y]} on columns,"+
                "non empty {[Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]," +
                "[Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入].children} on rows"+
                " from [Col_trade_detail] ";

结果:

 从上面结果看出,驾驶许可考试费,该县最后2年是下降的,如果不是考试费标准下降,那一定说明考试人数在下降,假设新增加考试人员以年轻人为主的话,基本可以判定该县年轻人在显著减少?

顺便研究了一下该县09-17年的交通罚没收入:

发现15、16、17年交通罚没收入和前几年相比,下降蛮快,原因是什么呢:

大家都遵守交规了?

罚款标准降低?

数据抽取有问题?

还需要进一步分析原因。

Weighted Averages(加权平均):

用到的时候再说。这里先跳过。

Time  : PrevMember:

        String mdxStr_114 ="with  member [measures].[increase] as " +
                "'[Measures].[金额]-([Measures].[金额],[Time].[Year].CurrentMember.PrevMember)' " +
                "select {[Time].[2007]:[Time].[2017]} on columns,{[Measures].[金额],[Measures].[increase]} on rows from [Col_trade_detail] " +
                " where  [Account].[Account_L].[政府性基金收入].[计提廉租住房资金]";

结果:

可以看出,从计提廉租住房资金看,该县这些年,土地财政收入一直是正增长,从没负过。 

ParallelPeriod:(平行期间 我理解可以是上一年、上一个季度、上一个月等)

上例子:我要找出公安行政收费和去年同期相比变化情况:

        String mdxStr_115 ="with  member [Measures].[和去年同期相比] as "+
       " '[Measures].[金额]-([Measures].[金额],ParallelPeriod([Time].[Year],1,[Time].[Quarter].currentMember))'"+
       " select {[Time].[2014].Children,[Time].[2015].Children,[Time].[2016].Children,[Time].[2017].Children} on columns,{[Measures].[金额],  [Measures].[和去年同期相比]} on rows " +
                "from [Col_trade_detail]  where ([Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入])";

 结果:

这里有个问题,我是枚举了我要查的年份的季度,如何直接限定年份的范围,是不是可以用filter函数?

PeriodsToDate:(计算本期累计?)

例子:

        String mdxStr_116 ="with member [Measures].[2017累计] as " +
                "'sum(PeriodsToDate ([Time].[Year], [Time].CurrentMember),[Measures].[金额])' " +
                " select {[Time].[2017].[1],[Time].[2017].[2],[Time].[2017].[3],[Time].[2017].[4]} on columns,{[Measures].[金额],[Measures].[2017累计]} on rows  from [Col_trade_detail] where  [Account].[Account_L].[罚没收入].[一般罚没收入].[交通罚没收入]";
        //简写
        String mdxStr_117 ="with member [Measures].[2017累计] as " +
                "'sum(YTD( [Time].CurrentMember),[Measures].[金额])' " +
                " select {[Time].[2017].[1],[Time].[2017].[2],[Time].[2017].[3],[Time].[2017].[4]} on columns,{[Measures].[金额],[Measures].[2017累计]} on rows  from [Col_trade_detail] where  [Account].[Account_L].[罚没收入].[一般罚没收入].[交通罚没收入]";

结果:

 

从起始位置到本期的累计:

        String mdxStr_120 ="with member [Measures].[累计] as " +
                "'Sum({[Time].CurrentMember.Level.Members.Item(0):[Time].CurrentMember},[Measures].[金额])'" +
                " select {[Time].[2017].[1],[Time].[2017].[2],[Time].[2017].[3],[Time].[2017].[4]} on columns,{[Measures].[金额],[Measures].[累计]} on rows  from [Col_trade_detail] where  [Account].[Account_L].[罚没收入].[一般罚没收入].[交通罚没收入]";

结果:

 

ps:移动平均:

移动平均的本质是一种低通滤波。它的目的是过滤掉时间序列中的高频扰动,保留有用的低频趋势,可以用于预测?啥时候,我用他来预测**地方非税业务量?

用到的无非是lag、lead、prevMember等再配合avg()的使用。

LastPeriods:Using LastPeriods() to Select Time Ranges Based on a Target Member

ClosingPeriod:返回指定成员在指定级别的后代中的最后一个兄弟的成员。

OpenningPeriod:和closingPeriod相反,是期初的

example:这里,我要求2017年最后一个月的收入

        //-------------------------------------begin ClosingPeriod --------------------------------------
        String mdxStr_130 ="SELECT ClosingPeriod ([Time].[Month],[Time].[2017]) ON 0  FROM [Col_trade_detail] ";
        String mdxStr_131 ="SELECT Tail(Descendants([Time].[2017], [Time].[Month]), 1) ON 0  FROM [Col_trade_detail] ";
        //-------------------------------------begin ClosingPeriod --------------------------------------

结果:

这2个函数使用上,要注意口径。

ClosingPeriod 等价与Tail(Descendants(Member_Expression, Level_Expression), 1)

Carryover of Balances for Slowly Changing Values and Reporting of Last Entered Balance?由于财政数据非常规范,或者再抽取阶段就处理好了,这个问题暂时不考虑?

CoalesceEmpty :将空单元值转换为指定的非空单元值,该值可以是数字或字符串。可惜的是,mondrian不认识它!

Using Member Properties in MDX Expressions (Calculations and Sorting):用到再说。

ps:

地方财政总收入(全口径)=地方 财政收入+上划中央收入=地方一般预算财政收入+基金预算收入(包括政府性基金收入和社会保险基金收入)+上划中 央收入 注:包含有基金收入的财政总收入叫做全口径财政收入, 否则仅叫财政总收入。

一般预算收入是指地方实际可用财力,扣 除了上缴中央部分的税收,比如上缴中央财政 75%的增值 税、上缴中央财政 60%的所得税等属于财政总收入的盘子, 没有计入一般预算收入。一般预算收入包括国税、地税扣除 上缴中央财政部分的地方留存部分再加财政部门组织的收 入

上一章节:计算成员与命名set

下一章节:

 

猜你喜欢

转载自blog.csdn.net/wh_xia_jun/article/details/90747656