OLAP analysis application (nine) - YoY

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wh_xia_jun/article/details/91449260

Key words:

Filter

MoM

Year

On the volume

Drill

MDX Query Context and Execution

Filter: return set according to the criteria specified sets screened.

It context-sensitive! ! !

语法:Filter(Set_Expression, Logical_Expression )

        String mdxStr_140 ="select non empty{[Account].Children} on columns,{Filter({[Time].[2017].[4].[11],[Time].[2017].[4].[12]},[Measures].[金额]>10000)} on rows " +
                "from [Col_trade_detail]  ";
//错误?
        String mdxStr_142 ="select non empty{[Account].Children} on columns,{Filter([Time].[Year].Members,[Measures].[金额]>10000)} on rows " +
                "from [Col_trade_detail]  ";

result:

Note that: msdStr_142 statement is not wrong, but in some years free value! All did not filter out null values ​​involved in computing, the latter need to sum up.

The relevant comparison statement is as follows:

    String mdxStr_144="SELECT Filter({[Account].[Level1projectname].Members},[Measures].[金额]>10000000)on axis(0) FROM  [Col_trade_detail] where ([Time].[2017],[Measures].[金额])";
 //----去掉条件  啥也查不出来,原因是默认的维度成员有空值引起的?
        String mdxStr_145="SELECT Filter({[Account].[Level1projectname].Members},1)on axis(0) FROM  [Col_trade_detail] ";
        String mdxStr_146="SELECT Filter({[Account].[Level1projectname].Members},1)on axis(0) FROM  [Col_trade_detail] where ([Measures].[金额])";
        //下面的语句 如果把[Time].[2017] 换成[Time].[2005],则什么也没有
        String mdxStr_146_1="SELECT Filter({[Account].[Level1projectname].Members},[Measures].[金额]>10000000)on axis(0) FROM  [Col_trade_detail] where ([Time].[2017],[Measures].[金额])";
        String mdxStr_147="SELECT Filter([Account].[Level1projectname].Members,[Measures].[金额]>10000000)on axis(0) FROM  [Col_trade_detail] where ([Time].[2005])";

Behind the content:

MoM:

        String mdxStr_151="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
        " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2017].Children} on rows  from [Col_trade_detail] "+
        " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";
        //这里我想求全部年度的的季度及月份的环比? 首先查2017年第4季度前面30个季度的同比情况
        String mdxStr_152="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
                " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2011].[4]:[Time].[2017].[4]} on rows  from [Col_trade_detail] "+
                " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";

        String mdxStr_153="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
                " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2017].[4].Lag(20):[Time].[2017].[4]} on rows  from [Col_trade_detail] "+
                " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";


       String mdxStr_151="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
        " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2017].Children} on rows  from [Col_trade_detail] "+
        " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";
        //这里我想求全部年度的的季度及月份的环比? 首先查2017年第4季度前面30个季度的同比情况
        String mdxStr_152="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
                " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2011].[4]:[Time].[2017].[4]} on rows  from [Col_trade_detail] "+
                " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";

        String mdxStr_153="with member [Measures].[环比] as "+
                "'[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1', FORMAT_STRING=\"0%\""+
                " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2017].[4].Lag(20):[Time].[2017].[4]} on rows  from [Col_trade_detail] "+
                " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";

//修正  应对前一期可能为0的情况  iif 有问题?
        String mdxStr_154="with member [Measures].[环比] as "+
                "'IIF(([Measures].[金额]=0),null," +
                "[Measures].[金额]/([Measures].[金额],[Time].CurrentMember.PrevMember)-1)', FORMAT_STRING=\"0%\""+
                " select {[Measures].[金额],[Measures].[环比]} on  axis(0),{[Time].[2017].[4].Lag(20):[Time].[2017].[4]} on rows  from [Col_trade_detail] "+
                " where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";

 Chain results:

Police industry administrative charges have interesting features of the first quarter of each year, have gone up sharply administrative fees chain, why, I'm afraid to know the characteristics of the industry combined.

iif:

According to the Boolean condition is true or false, calculate different branches of expression.

语法:IIf(Logical_Expression, Expression1 [HINT <hints>], Expression2 [HINT <hints>])

Year:

cousin: Returns the specified members of the sub-sub-members have the same relative position below the parent member.

Cousin( Member_Expression , Ancestor_Member_Expression )

example:

 String mdxStr_160="SELECT Cousin([Time].[2017].[4],[Time].[2016]) ON 0  FROM [Col_trade_detail]";

result:

 

Year:

 

        String mdxStr_160="SELECT Cousin([Time].[2017].[4],[Time].[2016]) ON 0  FROM [Col_trade_detail]";
        String mdxStr_161="WITH MEMBER Measures.[同比] AS"+
                "'[Measures].[金额]/([Measures].[金额], Cousin([Time].CurrentMember, [Time].CurrentMember.Parent.PrevMember))- 1', FORMAT_STRING = \"0%\""+
        " SELECT {[Measures].[金额], Measures.[同比]} ON 0,"+
                "{[Time].[2011].[1]:[Time].[2017].[4]} ON 1"+
        "   FROM [Col_trade_detail] where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";
        String mdxStr_162="WITH MEMBER Measures.[同比] AS"+
                "'[Measures].[金额]/([Measures].[金额], Cousin([Time].CurrentMember, [Time].CurrentMember.Parent.PrevMember))- 1', FORMAT_STRING = \"0%\""+
                " SELECT {[Measures].[金额], Measures.[同比]} ON 0,"+
                "{[Time].[2008].[1]:[Time].[2017].[4]} ON 1"+
                "   FROM [Col_trade_detail] where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入].[公民出入境证件费]";

result:

Be readily formed by an ParallelPeriod, direct the examples:

        String mdxStr_167="WITH MEMBER Measures.[同比] AS"+
                "'([Measures].[金额]-([Measures].[金额],ParallelPeriod([Time].[Year],1,[Time].[Quarter].currentMember)))/" +
                "([Measures].[金额],ParallelPeriod([Time].[Year],1,[Time].[Quarter].currentMember))', FORMAT_STRING = \"0%\""+
                " SELECT {[Measures].[金额], Measures.[同比]} ON 0,"+
                "{[Time].[2011].[1]:[Time].[2017].[4]} ON 1"+
                "   FROM [Col_trade_detail] where [Account].[Account_L].[行政事业性收费收入].[公安行政事业性收费收入]";

result:

It can be seen: mdxStr_167 and mdxStr_161 statement is the same.

Volume:

 

Drill:

Drill My understanding is that the application DrilldownLevel function,

DrilldownLevel:Drills down the members of a set to one level below the lowest level represented in the set.

DrilldownLevel(Set_Expression [,[Level_Expression] ,[Index]] [,INCLUDE_CALC_MEMBERS])

例1:

        String mdxStr_171="SELECT  non empty DrilldownLevel({[Account].[Account_L].[行政事业性收费收入]})  ON COLUMNS  from [Col_trade_detail] " +
                " where [Time].[2017]";

 结果:

ps:如果不限定[Time].[2017],前面的年份是年份,什么都查不出来!空值的处理,后面需要专题学习、测试。

本节未完,待续.....

上一章节:Common Calculations and Selections in MDX

下一章节:动态sql

Guess you like

Origin blog.csdn.net/wh_xia_jun/article/details/91449260