MDX Query using BottomCount to limit Median calculation returns null

I'm building a new cube that includes some person age values that aren't useful when summed, but are
useful when the median is determined. The measure group that contains the measure for the age has a 1-1 relationship with a dimension in the cube because both use the same table as the source. This is important because I use the key attribute of the dimension
as the set expression in the Median function to prevent any summation before the median is found. Here is the code for the original median calculation:
MEMBER Measures.[Median Age] AS
MEDIAN(
[Placement Dimension].[Id Removal Episode Fact].Members,
[Measures].[Age At Removal Months]
This median naturally represents the half-way point in the series of values. My analysts have also requested
median-type values at the quarter and three-quarter points in the same series. I've been able to accomplish this for the three-quarter point by nesting the TopCount function in the set expression of the Median function to limit the set to the last half of
the records and then find the median point like this:
MEMBER Measures.[75th Percentile] AS
MEDIAN(
TOPCOUNT(
[Placement Dimension].[Id Removal Episode Fact].MEMBERS
,Measures.[Episode Count] / 2
,Measures.[Age At Removal Months]
,Measures.[Age At Removal Months]
However, my attempt to use the BottomCount function in the same way as TopCount to find the quarter point
in the whole data set by limiting the calculation's set to the first half of the data always returns null. Here is how I've formed the code:
MEMBER Measures.[25th Percentile] AS
MEDIAN(
BOTTOMCOUNT(
[Placement Dimension].[Id Removal Episode Fact].MEMBERS
,Measures.[Episode Count] / 2
,Measures.[Age At Removal Months]
,Measures.[Age At Removal Months]
And here is the query that returns the values:
SELECT
Measures.[Episode Count]
,Measures.[Median Age]
,Measures.[25th Percentile]
,Measures.[75th Percentile]
} ON 0
,[Date Begin].[Calendar Hierarchy].Year.&[2011]:[Date Begin].[Calendar Hierarchy].Year.&[2014] ON 1
FROM [POC Cube]
WHERE
[Age at Removal Mos].[Age in Years List].[Age Year].&[0]:[Age at Removal Mos].[Age in Years List].[Age Year].&[5]
I don't know why the end result is always null. I don't have any null values in the data for this measure, and I know what values I should be seeing because I've found the median records manually in results from a SQL Server query. I've tried using TopCount
and multiplying Measures.[Age At Removal Months] in the TopCount function by -1 to workaround the descending sort, but I still get nulls. I've also tried separating these queries out so the quarter point and three-quarter point calculations aren't run together,
but I still get nulls for the quarter point calculation.
I'm open to any help fixing this situation by modifying my current code or by using alternate methods, but the end result has to be dynamic enough to be used as a calculation in the cube. Thanks!

The links might helps.
http://technet.microsoft.com/en-us/library/ms144864.aspx
http://www.mssqltips.com/sqlservertip/3034/sql-server-analysis-services-ssas-2012-top-and-bottom-functions/
http://www.sqlservercentral.com/blogs/bradleyschacht/2012/03/12/mdx-functions-bottomcount/

Similar Messages

  • How to generate mdx query using C#

    I am new to mdx query and i am very curious about mdx query generation using c# so i searched for any demo or open source then i found
    Ranet.olap, which is providing what i need. After taking the dlls i tried to incorporate them in my code. I am pasting my full
    console code which should generate mdx query but it's not doing so, Am i doing something wrong.
    using System;
    using System.Collections.Generic;
    using Microsoft.AnalysisServices.AdomdClient;
    using Ranet.Olap.Core.Managers;
    using Ranet.Olap.Core.Metadata;
    using Ranet.Olap.Core.Types;
    namespace MDX
        class Program
            static void Main(string[] args)
                startWork();
            public static void startWork()
                string connString = "Provider=MSOLAP.3; Data Source=localhost;Initial Catalog=AdventureWorkDW2008R2;Integrated Security=SSPI;";
                CubeDef cubes;
                AdomdConnection conn = new AdomdConnection(connString);
                conn.Open();
                cubes = conn.Cubes.Find("AdventureWorkCube");
                Ranet.Olap.Core.Managers.MdxQueryBuilder mdx = new Ranet.Olap.Core.Managers.MdxQueryBuilder();
                mdx.Cube = cubes.Caption;
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listColumn = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listRow = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listData = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                //Column area
                Dimension dmColumn = cubes.Dimensions.Find("Dim Product");
                Microsoft.AnalysisServices.AdomdClient.Hierarchy hColumn = dmColumn.Hierarchies["English Product Name"];
                //hierarchy properties
                List<PropertyInfo> lPropInfo = new List<PropertyInfo>();
                foreach (var prop in hColumn.Properties)
                    PropertyInfo p = new PropertyInfo();
                    p.Name = prop.Name;
                    p.Value = prop.Value;
                    lPropInfo.Add(p);
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIColumn = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIColumn.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
                areaIColumn.Caption = hColumn.Caption;
                areaIColumn.CustomProperties = lPropInfo;
                listColumn.Add(areaIColumn);
                //Rows Area
                Dimension dmRow = cubes.Dimensions.Find("Due Date");
                Microsoft.AnalysisServices.AdomdClient.Hierarchy hRow = dmRow.Hierarchies["English Month Name"];
                List<PropertyInfo> lRowPropInfo = new List<PropertyInfo>();
                foreach (var prop in hRow.Properties)
                    PropertyInfo p = new PropertyInfo(prop.Name,prop.Value);
                    lRowPropInfo.Add(p);
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIRow = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIRow.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
                areaIRow.Caption = hRow.Caption;
                areaIRow.CustomProperties = lRowPropInfo;
                listRow.Add(areaIRow);
                //Measure Area or Data Area
                Measure ms = cubes.Measures.Find("Order Quantity");
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIData = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIData.AreaItemType = AreaItemWrapperType.Measure_AreaItemWrapper;
                areaIData.Caption = ms.Caption;
                List<PropertyInfo> lmpropInfo = new List<PropertyInfo>();
                foreach (var prop in ms.Properties)
                    PropertyInfo p = new PropertyInfo(prop.Name, prop.Value);
                    lmpropInfo.Add(p);
                areaIData.CustomProperties = lmpropInfo;
                listData.Add(areaIData);
                mdx.AreaWrappersColumns = listColumn;
                mdx.AreaWrappersRows = listRow;
                mdx.AreaWrappersData = listData;
                string mdxQuery = mdx.GenerateMdxQuery();
                conn.Close();

    Hi mkm1,
    According to your description, you want to use C# code to generate MDX Query. Right?
    In Analysis Servcies, we just need to use "Microsoft.AnalysisServices.AdomdClient.dll" to open connection to SSAS database and retrieve data from cube. Here are some sample code about executing MDX query using C#.
    Dim objConnection As New AdomdConnection("Data Source=localhost;Initial Catalog=Adventure Works DW 2008;")
    Dim objCommand As New AdomdCommand()
    Dim objDatatable As New DataTable
    Dim strCommand As String
    strCommand = "SELECT [Measures].[Internet Sales Amount] ON COLUMNS, "
    strCommand = strCommand & " [Date].[Calendar].[Calendar Year] ON ROWS"
    strCommand = strCommand & " FROM [Adventure Works]"
    objConnection.Open()
    objCommand.Connection = objConnection
    objCommand.CommandText = strCommand
    Dim objDataAdapter As New AdomdDataAdapter(objCommand)
    objDataAdapter.Fill(objDatatable)
    objConnection.Close()
    Since your code is more related to a third party API, we suggest you post your question to Rnet.
    Reference:
    Microsoft.AnalysisServices.AdomdClient Namespace
    If you have any question, please feel free to ask.
    Simon Hou
    TechNet Community Support

  • How to get the Benefits Rate multiplier value in HCM extract ? used Extract rule type Fastfomula, but returns null.

    how to get the Benefits Rate multiplier value in HCM extract ? used Extract rule type Fastfomula, but returns null.
    Formula:
    DEFAULT FOR BEN_ABR_NAME IS 'NA'
    DEFAULT FOR l_rate_multiplier IS 'X'
    L_BG_ID = GET_CONTEXT(BUSINESS_GROUP_ID, 1)
    L_EFF_DATE = GET_CONTEXT(EFFECTIVE_DATE, to_date('1951/01/01 00:00:00'))
    L_ABRT_ID = GET_CONTEXT(ACTY_BASE_RT_ID, 9999)
    CHANGE_CONTEXTS(EFFECTIVE_DATE = L_EFF_DATE, BUSINESS_GROUP_ID = L_BG_ID, ACTY_BASE_RT_ID = L_ABRT_ID )
    l_rate_multiplier = BEN_ABR_NAME
    RETURN l_rate_multiplier

    I used DBI - BEN_ABR_NAME.
    What is back end query ? can we use query to extract the value in Extracts ?

  • Simple sql to mdx query using the max fn

    I'm using the MDX Max fn to get the max of a certain value but now I want get max for a certain pair of values and not all, how could i write this in mdx as a calculation?
    More details: For a certain pair of status and substatus (status=1, substatus=1) from a trans dimension table i want to get the max insertionid (attribute in trans measure table). How would you guys suggest I go about this?
    I'm new to mdx and I'm converting a whole sql statement to a measure not to include it as a named query for performance concerns!
    If needed this is the sql query im converting:
    SELECT TOP (1) InsertionDT
    FROM dbo.TransTasksFFMS_GVT AS TSI
    WHERE (TaskCode = T.TaskCode) AND (TaskStatus = 1) AND (TaskSubStatus = 1)
    ORDER BY InsertionDT) AS RegistrationTimeWithoutConversion
    Another way to think of this is how to apply a certain measure only on certain values and not all values in the browser.

    Hi Junior,
    According to your description, you want to get the max value by using MDX query, right? Since no know your cube detail information, we cannot convert this T-SQL to MDX query. Here is a sample MDX query for your reference. The query below returns the Sale
    Amount measure and the MaxValue calculated member.  The MaxValue calculated member takes the maximum value for members of the Fiscal Year level in the Fiscal hierarchy of the Date dimension.
    WITH
    MEMBER [Measures].[MaxValue] AS
    MAX([Date].[Fiscal].[Fiscal Year].Members, [Measures].[Sales Amount])
    SELECT
    {[Measures].[Sales Amount],[Measures].[MaxValue]} ON COLUMNS,
    {[Date].[Fiscal].[Fiscal Year].Members} ON ROWS
    FROM
    [Adventure Works]
    Reference:Max (MDX)
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to use getRelativePath() with browseForOpen()? It returns null

    It's quite simple:
    fTargetFile:File = File.applicationDirectory.resolvePath("assets");
    fRootFile:File = File.applicationDirectory.resolvePath("assets");
    fTargetFile.addEventListener(Event.SELECT,onSelect)
    fTargetFile.browseForOpen("test"); <-- here I open a file in "/assets/images/test.jpg"
    function onSelect(e:Event):void
        trace(fRootFile.getRelativePath(fTargetFile));  <-- this returns null
    Every single "tutorial" in the web - along with Adobe's documentation - gracefully uses resolvePath to explicitly point to the file objects, thereby bypassing the actual use case. getRelativePath indeed works with resolvePath, but using resolvePath means I've already known where the file is located in the first place, rendering getRelativePath actually useless
    tracing the nativePath property of both objects returns the correct path.
    What I'm trying to do is letting the user choose a file within the "assets" directory. The file can be from any folder so long as they're under the "assets", and once user chooses a file, display the relative path from "assets" to the chosen file.
    So, in the example above, I expect "images/test.jpg" to be returned, but it returns nothing
    Do I have to do some wizardry before getRelativePath works?

    This post is rather old, so I may not be able to help the original author of this topic, but as I found this thread, when searching for a solution for this problem myself, I might be able to help someone else.
    I found the following solution:
    function onSelect(e:Event):void
      var f1:File = (new File()).resolvePath(e.currentTarget.nativePath);
      var f2:File = (new File()).resolvePath(File.applicationDirectory.nativePath);
      trace(f2.getRelativePath(f1, true));

  • Bex Query- Use of ABAP code in Calculated Keyfigure/formula

    Dear Experts.
    I am wondering if there is any way to use ABAP in the formula editor of the Bex Query desinger.
    I have to build a report with very complex formulas (a lot of key figures, comporations, If then else ) an I think it would be easier to build all then in ABAP.
    So what I am looking for is any kind of user-exit/Badi that allows to calculate a Calculated Key figure/fomula in ABAP with the same data that is availabe in the fomula editor.
    If SAP is not providing this, this is clearlly a must for next releases.
    Thanks a lot and best regards,
    Alfonso.

    Dear Ananda.
    Thnaks for your reply, but could you please extend your answer a little bit more?
    As far as I know, Formula customer exit variables are only called once and they don´t provide the rest of the keyfigures and characteristic use in the drilldown level, so for my needs they are useless.
    Regarding IF-then-else statement in the formula, I already know about it. Actually what I am trying to avoid is to use them. In order to build my query I might need to build really big formulas with a lot of If-then-else, making it quite complex what the formula is doing. This is the reson I want to do it on ABAP.
    Please any other ideas?
    Thanks a lot.

  • MDX Query-How To ignore all measure calculations where the measure is zero

    Hi,
    I have a query MDX that also extracts the values of 2 measure with value 0. 
    How can I do ignore and not to extract ? 
    Example:
    Customer________Quantity________Revenue
           1____________0_______________0
            2____________1______________10
           3_____________2______________15
    I want extrcat only:
    Customer________Quantity________Revenue
           2____________1______________10
           3_____________2______________15
    thanks.

    Hi,
    I too have the same issue. It would be great if you can update how you resolved it.
    Thnaks for your answer.
    Saravanan Payani.

  • Range selection in MDX query

    Hello to everyone,
    Is there anyway to develop a MDX query, using a sap variable, and use the range interval at this query.
    For example, at BEX I can define a variable to accept year/month from xxx to yyy.
    How can I do this in MDX? I'm only able to execute only with a single value (like in this simple example). Is the other way possible?
    SELECT {[Measures].[3ZFR2WD9UJZZZBUBZNRGDIQ9X]}
    ON COLUMNS,
    NON EMPTY
    {[0SALESEMPLY].LEVELS(01).MEMBERS}
    ON ROWS
    FROM [YSD_M05/YSD_M05_Q0040]
    SAP VARIABLES
    [YKC_MESN] INCLUDING [0CALMONTH].[200503]
    Thanks and best regards from a cloudy day at Lisbon
    Bruno

    Hello,
    Ok... I just figured it out. We must use the ":" operator.
    The query must be like this:
    SELECT {[Measures].[3ZFR2WD9UJZZZBUBZNRGDIQ9X]}
    ON COLUMNS,
    NON EMPTY
    {[0SALESEMPLY].LEVELS(01).MEMBERS}
    ON ROWS
    FROM [YSD_M05/YSD_M05_Q0040]
    SAP VARIABLES
    [YKC_MESN] INCLUDING [0CALMONTH].[200503]:[0CALMONTH].[200504]
    Best Regards
    Bruno

  • MDX question using MDXTEST

    Hello.  I was wondering if anybody has any experience using MDX to return an XMLA result set for a query that contains a hierarchy. Any help of simple example would be helpful.  We are trying to use the MDX web service within BI and are testing out various MDX queries.
    Thank you.

    Hello Aron,
    Please see this doc
    [Load Testing Web Services in ESA with Custom Examples|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/60f4cabe-0401-0010-fbba-fae6c7a8d29e]
    See this blog as well
    [SAP Network Blog: Work with XMLA Web Service for BI Data in External Applications!|/people/prakash.darji/blog/2006/09/04/work-with-xmla-web-service-for-bi-data-in-external-applications]
    Other docs
    [Web Dynpro Java Application to Execute MDX Query Using the Business Intelligence Java SDK|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/60f35908-ecd4-2910-6c89-e75e1054d9d1]
    [Using the MDX Editor (SAP Library - SAP NetWeaver Visual Composer: User Guide)|http://help.sap.com/saphelp_nw04/helpdata/en/45/f33574fee1487f9b8487d2986a2658/frameset.htm]
    Thanks
    Chandran

  • MDX query for to get the data from two cubes

    Hi
    Can you tell me how to create MDX query to get the values from two cubes.  (One hierarchy from first cube and one hierarchy from second cube)
    Can you give me one example.
    Regards,
    Madhu.
    Sudhan

    Hi Sudhan,
    According to your description, you want to retrieve data from two different cubes, right? The short answer is yes. To query multiple cubes from a single MDX statement use the LOOKUPCUBE function (you can't specify multiple cubes in your FROM statement).
    The LOOKUPCUBE function will only work on cubes that utilize the same source database as the cube on which the MDX statement is running. For the detail information about it, please refer to the link below to see the blog.
    Retrieving Data From Multiple Cubes in an MDX Query Using the Lookupcube Function
    Regards,
    Charlie Liao
    TechNet Community Support

  • SAP BW BEx query - WEBi MDX query

    Hi Experts, have we had some discussion on this?
    Does MDX query send by WEBi report to BW use the same program to extract data from BW database?
    One of the option for WEBi report source of data is to build Universe on top of BEx query. Could you share how this process actually happen.
    I think
    - WEBi query will pass parameters that is relevant for BEx query filter of the universe
    - the BEx query will then extract the data (following normal process if we run BEx query independently)
    - if WEBi has further filtering, it will then get the BEx result above and filter it further ..??
    So, how is MDX query come into the picture?
    Or is it:
    - WEBi query and the BEx query will determine what MDX query will be generated, and this MDX query will then fetch the data.
    But why BEx query extract data faster then MDX query?
    Sorry, i am new to this. hope someone could share some light here. In the meantime i continue to real those documentation and try to get some more ideas of what is actually happening.
    Thanks.

    Hi Thanks a lot for pointing this out.
    Did i understand it correctly that BEx query is using a different set of program (platform) to retrieve data compare to MDX query, and not MDX uses those program that is used by BEx to retrieve data from BW database and have extra steps on top of that?
    Can anyone share what is actually happen WEBi MDX query is executed (how the database is hit with SQL, and what are the tools to evaluate the efficiency of the WEBi (or the used BEx). As for BEx we have RSRT to analyze it right.
    And even to test the MDX query using MDXTEST and try to get the data from WEBi report, i found WEBi report still take considerably a lot longer. Why is this so? just because BO is a different system then BW?
    And as it's shared the BO 4.0 is using the same platform as BEx to retrieve data from BW database, does this mean we don't need to care about MDX usage in BW anymore as far as BO data extraction concern?
    Thank you very much.

  • Less than in MDX Query Designer

    I have a month year parameter like March, 2014. I want to calculate actual for current year and Prior year.
    I have time intelligence build in the cube which will give me Prior year.
    When user select March,2014, I will show data in line chart with 2 series like current year and prior year.
    Current year data will be from Jan 2014 to march 2014 as user select march (not current month which is August,2014).
    But in Prior year series, I need to show data from jan 2013 to Dec 2013.
    I have a dataset right now which gives me current year and prior year full data. I have used ancestor function to get the full year data. How how I restrict data in chart to cut off at Mar 2014 and not show data till Dec 2014.

    Hi!
    Based on your question I assume you expect a result similar to this:
    If your entry parameter is month than and you have Year-Month-Date hierarchy in your cube you could do the following:
    select cnt on 0,
    [Date].[Y-M-D].[Year].members
    on 1 from
    select {[Date].[Y-M-D].[Month].&[14]&[2].parent.prevmember.firstchild:
    [Date].[Y-M-D].[Month].&[14]&[2]}
    on 0 from YOURCUBE)
    This query uses subselect to limit the cube space to date range starting at first month of previous year(firstchild) and ending at your entry date (in my case February 2014)
    So lets explain starting point expression for date range:
    [Date].[Y-M-D].[Month].&[14]&[2].parent.prevmember.firstchild
    [Date].[Y-M-D].[Month].&[14]&[2] - is your entry parameter 
    [Date].[Y-M-D].[Month].&[14]&[2].parent - sets position to [Date].[Y-M-D].[Year].&[2014] (assuming that the direct parent of Month level is Year level. If this is not the case you could use "ancestor" function).
    [Date].[Y-M-D].[Month].&[14]&[2].parent.prevmember -  sets the position to [Date].[Y-M-D].[Year].&[2013]
    [Date].[Y-M-D].[Month].&[14]&[2].parent.prevmember.firstchild   sets the position to January 2013
    This gives you date range starting from January 2013 and ending at February 2014.
    HTH
    Ivan Roguljić

  • When using TODATE function MDX query is not correctly generated

    Essbase 9.3.1.2 and OBIEE 10.1.3.4.1.
    When using TODATE function MDX query is not correctly generated.
    This leads to unexpected values not only on cumulative columns in report (generated with TODATE), but also other columns (calculated with AGO function or directly read from cube) have incorrect values.
    The problem occurs when you filter on a column that is not in the select list. If you filter on just one level of dimension, results are fine. You can filter on multiple dimensions as long as you filter on just one level of each dimension.
    If you filter on two or more levels of one dimension, than results are not correct. In some cases results for TODATE column are all zeros, in some cases it is a random value returned by Essbase (same random value for all rows of that column), and in some cases BI Server returns an error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. Essbase Error: Network error [10054]: Cannot Send Data (HY000).
    Here is generated MDX code:
    With
    set [Grupe proizvoda2] as '{[Grupe proizvoda].[N4]}'
    set [Grupe proizvoda4] as 'Generate([Grupe proizvoda2], Descendants([Grupe proizvoda].currentmember, [Grupe proizvoda].Generations(4), leaves))'
    set [Segmentacija2] as '{[Segmentacija].[RETAIL]}'
    set [Segmentacija4] as 'Filter(Generate({[Segmentacija2]}, Descendants([Segmentacija].currentmember, [Segmentacija].Generations(4),SELF), ALL), ([Segmentacija].CurrentMember IS [Segmentacija].[AFFLUENT]))'
    set [Vrijeme3] as '{[Vrijeme].[MJESEC_4_2009]}'
    member [Segmentacija].[SegmentacijaCustomGroup]as 'Sum([Segmentacija4])', SOLVE_ORDER = AGGREGATION_SOLVEORDER
    member [Accounts].[MS1] as '(ParallelPeriod([Vrijeme].[Gen3,Vrijeme],2,[Vrijeme].currentmember), [Accounts].[Trosak kapitala])'
    member [Accounts].[MS2] as '(ParallelPeriod([Vrijeme].[Gen3,Vrijeme],1,[Vrijeme].currentmember), [Accounts].[Trosak kapitala])'
    member [Accounts].[MS3] as 'AGGREGATE({PeriodsToDate([Vrijeme].[Gen2,Vrijeme],[Vrijeme].currentmember)}, [Accounts].[Trosak kapitala])'
    select
    { [Accounts].[Trosak kapitala],
    [Accounts].[MS1],
    [Accounts].[MS2],
    [Accounts].[MS3]
    } on columns,
    NON EMPTY {crossjoin ({[Grupe proizvoda4]},{[Vrijeme3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
    from [NISE.NISE]
    where ([Segmentacija].[SegmentacijaCustomGroup])
    If you remove part with TODATE function, the results are fine. If you leave TODATE function, OBIEE returns an error mentioned above. If you manually modify variable SOLVE_ORDER and set value to, for example, 100 instead of AGGREGATION_SOLVEORDER, results are OK.
    In all cases when this variable was modified in generated MDX, and query manually executed on Essabse, results were OK. This variable seems to be the possible problem.

    Hi,
    Version is
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for 64-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    Sorry, in my last post i forgot to mention that i already created a function based index but still it is not using because, there is a UNIQUE constraint on that column.
    Thanks

  • Custom Calculation in ASO - Error in MDX query

    Hi All,
    We are trying to use a run a custom calculation on our ASO cube
    We are getting the error as below
    Syntax error in input MDX query on line 13 at token ' )'
    When i checked my POV i did not find any issue. Even when I try to put only one crossjoin, it is still giving me the error saying "error at line 2')' "
    I am unable to find the cause of this issue.
    Can any one help me on this.
    ******content of Maxl Script********
    execute calculation on database ASOFNPLN.ASOFNPLN with local script_file D:\++++++++Sateesh+++++++\ADWEA\Custom.csc"
    POV
    "Crossjoin({[FY09]},
    Crossjoin({[Actual]},
    Crossjoin ({[Jan],[Feb]},
    Crossjoin({[Working]},
    CrossJoin({[XA]},
    CrossJoin({[0000000]},
    CrossJoin({[000000000]},
    CrossJoin({[00000]},
    CrossJoin({[175110]},
    CrossJoin({[CC_ADWEA_0000_AED]},
    CrossJoin({[Unspecified Product]},
    CrossJoin({[HSP_InputValue]},
    CrossJoin({[Local]} )))))))))))))"
    SourceRegion "{[Opening Balance],[Ending Balance],[Periodic Balance]}";
    *************** Content of Custom.csc *********
    case when
    IsUda([Account].currentMember, "Expense") OR IsUda([Account].currentMember, "Revenue")
    AND
    Is([Period].CurrentMember, [Jan]) OR Is([Period].CurrentMember, [Feb]) OR Is([Period].CurrentMember, [Mar]) OR Is([Period].CurrentMember, [Apr]) OR Is([Period].CurrentMember, [May]) OR Is([Period].CurrentMember, [Jun]) OR Is([Period].CurrentMember, [Jul]) OR
    Is([Period].CurrentMember, [Aug]) OR Is([Period].CurrentMember, [Sep]) OR Is([Period].CurrentMember, [Oct]) OR Is([Period].CurrentMember, [Nov]) OR Is([Period].CurrentMember, [Dec]) OR Is([Period].CurrentMember, [YearTotal])
    THEN
    ([Ending Balance]):=([Opening Balance]+[Periodic Balance]);
    ([Opening Balance]):=([View].[Ending Balance], [Period].CurrentMember.lag(1));
    ([Ending Balance]):=([Opening Balance]+[Periodic Balance]);
    END

    You've got a mismatched " in the first line of the "execute calculation" statement.
    However, I think the real problem is in the calc script.  I don't believe you can do this in MDX:
    CASE WHEN x THEN
        a := y;
        b := z;
    END
    You have to do this:
    a := CASE WHEN x THEN y END;
    b := CASE WHEN x THEN z END;
    An alternative is to create a formula member for each of the measures you are trying to set (with the member formula containing the CASE logic) and have the calc script copy the formula member to the permanent member.

  • Advise on median MDX query and/or dimension hierarchy setup

    Hey guys,
    I have a fairly weird situation with SSAS/Dimension Hierarchies and an MDX based median-calculation that is actually not working as I would like it to work.
    Hierarchy
     - State
     - County
     - Town
     - Neighborhood
     - Filing Date
     - Usage Category
     - TransactionID (PRIMARY KEY)
    I have a hierarchy set up which shall be used in order drill down the cube. The median, which shall be calculated based off the Sales Price measure and all the affected records, shall be available at every single level of the hierarchy. That is also why
    I decided to use a hierarchy: I am at least not aware of a do-able alternative that would allow to use any available dimension without a hierarchy and calculate the median dynamically based off on that.
    This is the MDX expression I use in order to calculate the median.
    Median
          NONEMPTY(EXISTING Descendants( [Statistics Hierachy1].[Hierarchy].CurrentMember,
                       [Statistics Hierachy1].[Hierarchy].[Transaction Id])),
            [Measures].[Sale Price]
    It works, and the numbers are correct, but it is way too slow in order to use it properly.
    The hierarchy of dimension states that there is no relationship between the attributes of the hierarchy. That is right, because every single attribute is an attribute to the primary key (TransactionId).
    So for me there are three ways to solve this:
     1) Set up relationships. That, for some reason, brings up only a very limited subset of my data. Not sure why?
     2) Get the hierarchy to work properly so it calculates the underlying median FASTER!
     3) Set up a different measure (maybe my MDX is totally wrong?) to calculate the median the right way? In the end the median needs to be calculated based off on all underlying transactions that make up to the current level of the hierarchy.
    In the end we are not talking about a ultra-large cube. Right now it only has like 3.1 Million rows in its one single partition.
    Can anybody of you help me to address either the issue I am facing with the hierarchy (one I set up the relations I only see a subset of data) and/or let me know how to set up the median measure the right way ?
    Thanks in advance! I really appreciate any help!
    Thanks,
    Lars

    Hi L,
    I would encourage you to set up the attribute hierarchies.  That will make your calculation much faster, the further down the user is in the hierarchy.  This is because the nonempty set you are getting the median from will be much smaller.
    As you point out, to have an attribute hierarhcy, you need to have keys that cascade down, which you haven't got, at least yet.  One simple way around this is to use composite keys all the way down the hierarchy.  ie. State just has State as key,
    County has State and County as key, Town has State, County and Town in key etc.  I can assure you that this will make you calc much faster down the hierarchy.
    One side effect you will have is that attributes will now be unique based on their parents.  Two towns with the same name in different states or counties will appear as separate towns.  You may or may not want this.  If you don't want it,
    simply have two Town attributes, call one TownKey (with composite key) which will be invisible as an attribute but used in the hierarchy.  The other Town attribute simply has Town as the key, so it can be used as an attribute on its own.  Town attribute
    can be an attribute of TownKey. 
    Hope that makes sense,
    Richard

Maybe you are looking for