Declare variables in an MDX query

Is it possible to declare variables in an MDX query like transact sql? something like this:
DECLARE @date1 date
DECLARE @month1 int
set @date1 = '12-12-2012'
set @month1=DATEPART(m, @date1)-1
select @date1 as dt1, @mesreferencia as mt1

Hi ,
  In MDX , you will not be able to put variables in MDX. But Query scoped calculated measures can be used for such cases. The equivalent MDX for the above is
WITH MEMBER [MEASURES].Dt
As
CDATE('12-12-2012')
MEMBER MEASURES.DTPart
As
DATEPART("M", MEASURES.Dt)-1
SELECT {MEASURES.Dt,MEASURES.DTPart} ON 0
FROM [Adventure Works]
Best Regards Sorna

Similar Messages

  • BEx variables ignored in MDX query

    I am having some issues with Crystal Reports running off a Bex query. In the Bex query I have a variable defined on characteristic posting date. However, even though I select a specific posting date when prompted, records from all posting dates are returned. So I copied the MDX statement and ran it in MDXTEST only to get the same result.
    MDX:
    SELECT NON EMPTY EXCEPT([OPSTNG_DATE].MEMBERS, {[OPSTNG_DATE].[All]}) ON ROWS FROM [EFIGL_M01/QEFIGL_M01_4250] SAP VARIABLES [!V000001] INCLUDING "08/01/2010" : "08/01/2010"
    Anyone ran into a similar problem before? The MDX statement does indicate that I only picked one posting date for SAP VARIABLE

    Hi Ingo,
    Yes this variable is built in the underlying Bex query, and running the query in web analyzer or RSRT shows the correct filtered reesult.
    The variable is created under the Posting Date Characteristic under "Default Values" in the "Filter" tab. Now that you mentioned this, I tried moving the variable to "Characteristic Restrictions" from "Default Values" and I am able to get the correct result! What I don't get now is why the original configuration worked for Bex but not for MDX, but worked for both once moved to "Characteristic Restrictions"?
    Thanks!

  • Can I declare variables in Reports from SQL Query

    Hi
    I have a Report from SQL Query published as a portlet on a page among other reports. In the query report I am using the fuction WWCTX_API.GET_USER at quite a few places to filter the data returned to the user. Can I assingn the user id to a variable at some level & replace the fuction WWCTX_API.GET_USER with the variable in all the places.
    For eg:
    usr varchar2(25);
    usr:= PORTAL30.WWCTX_API.GET_USER;
    select USER_ID, USER_LVL, BUSINESS_ID, BRANCH_ID from crs_user where user_id=usr;
    can i declare variable and assign the value like the above at any level(Report or Page Level) to the acces the variale in queries.
    Thanks in advance

    I have found that you can't use a * in a dynamic page.
    Try this:
    <ORACLE>
    DECLARE
    usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
    BEGIN
    for c in
    (SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
    Loop
    htp.p(c.<alias>);
    END;
    </ORACLE>
    You can also add table tags for column formating:
    <table>
    <tr><td>column 1</td></tr><tr><td nowrap>
    <ORACLE>
    DECLARE
    usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
    BEGIN
    for c in
    (SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
    Loop
    htp.p(c.<alias>);
    END;
    </ORACLE>
    </td></tr></table>
    Martin

  • How to union results from 3 different dimensions in where clause with or - Mdx query

    Hi 
    I have a MDX Query and i need to pass the variable values to it by dynamically.
    Each time it will get any one attribute from three dimensions.
    Select 
    {} ON Columns,
    {} ON Rows 
    From
    Cube
    Where
    [Dimension1].[Attribut].&[Value]
    or
    [Dimension2].[Attribut2].&[Value]
    or
    [Dimension3].[Attribut3].&[Value]
    So It is working for two different values by using union and cross join.
    Can you please provide the solution ..
    Thanks in advance

    Hi Philip
    Thanks for replying me.
    I tried on that way, In my mdx query i am using one slice attribute (i.e [Customer].[Gender].allmembers) in rows so getting error "The  Hierarchy already appears in Axis1".
    SELECT
    {[Measures].[Internet Sales Amount] } ON 0,
    NON EMPTY
    {[Customer].[Gender].allmembers } ON 1 -- Used
    FROM
    [Adventure Works]
    WHERE
    [Customer].[Gender].&[M]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].&[XL]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].&[Australia]
    Can you provide alternate ways to get resolved.
    Thanks in advance

  • 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

  • How to execute the content of varchar  variable like a simple query

    Hi everyone!
    I did a PL/SQL region in apex, in this region I did the query which is storaged in a variable; it was did it concatenate several times,
    in the procedure I have several sentences.
    I thought that the command 'execute immediate' would get a good result but it do not print the result.
    declare
    variable varchar2(1000);
    begin
    --sentences
    --execute inmmediate( variable );
    --return variable
    end;
    I only want to how to execute the content of varchar variable.
    For example, suppose that the result of this procedure is
    'SELECT SYSDATE FROM DUAL'
    How and what do I must do for this query execute like a normal query that is in apex?
    I expect your prompt reply.
    Thank you for your help.
    Best regards

    Let us say your table containing SQL is
    t_sql_table
    and has two columns
    primary_key
    and
    sql_query.
    You would need to do the following:
    1. Create a Report of type "Function returning SQL Query"
    2. Put the following there:
    DECLARE
       v_query   VARCHAR2 (4000);
    BEGIN
       SELECT sql_query
         INTO v_query
         FROM t_sql_table
        WHERE primary_key = 1;
       RETURN v_query;
    END;Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • MDX query in Init Block

    hi,
    Need a help regarding the Initialization block which connects to a Essbase and fetches the results using a MDX query.
    I need to get the Max of the month cube column and put in a variable.
    The cube time hierarchy contains the column at the 5th physical level with values as 2008 August, 2008 December, 2009 January and 1994 March etc.
    Now I want to get the Max of the value i.e. 2009 January.
    I saw another Init block with the query. This query gave result as 1994 March.
    select
    {} on columns,
    {ClosingPeriod([DEPMTI01].Generations(5))} on rows
    from [XXX.YYY]
    Now when I modified the query to below and run it throws an syntax error.
    select
    {} on columns,
    {Max([DEPMTI01].Generations(5))} on rows
    from [XXX.YYY]
    Please help me out with the correct way on writing the MDX so as I can fetch my desired result of 2009 January.
    Regards,
    Bhavik

    Hi Manas,
    As u would know ParForEach i sused if u have parallel processing branches,
    The max u can have is 999.
    Check this link
    http://help.sap.com/saphelp_nw04/helpdata/en/ce/bb2c421f3fda2ce10000000a1550b0/frameset.htm
    Hope it helps!!!!!!!!!!!
    Reward points if u found it useful

  • Run mdx query in batch

    Hi,
    I am using BW MDX Driver to report off SAP BW data. Sometimes the returned data may be too much according to user selection. My question is, is there any way to run the MDX query in batch, so that the data is not returned all at once?
    For opensql or infoset driver, we can configure the query to run in batch by adding some system environment variables. But for MDX, I have no idea now.
    Thanks,
    Ray

    Hi,
    Are you including the parameter that you must have created in Crystal Reports in the Select Expert. You need to include the parameter within the record selection or group selection formula of the Select Expert, as may be applicable. Only then the values returned by the database would be in accordance to the input by the user.
    For instance, let us assume that you have created the Country parameter in Crystal Reports. In order to return data as per input fed within the County parameter during Report Refresh, the formula in Select Expert would be somewhat like :
    {Customer.Country} = {?Country}
    Please do this preliminary check before thinking of using Open SQL or InfoSet driver instead of the MDX driver or feeding the environment variables through batch processing.
    Regards,
    Amogh.

  • VAL_FIELD selection to determine RSDRI or MDX query: performance tuning

    according to on of the HTG I am working on performance tuning. one of the tip is to try to query base members by using BAS(xxx) in the expension pane of BPC report.
    I did so and found an interesting issue in one of the COPA report.
    with income statement, when I choose one node gross_profit, saying BAS(GROSS_PROFIT), it generates RSDRI query as I can see in UJSTAT. when I choose its parent, BAS(DIRECT_INCOME), it generates MDX query!
    I checked DIRECT_INCOME has three members, GROSS_PROFIT, SGA, REV_OTHER. , none of them has any formulars.
    in stead of calling BAS(DIRECT_INCOME), I called BAS(GROSS_PROFIT),BAS(SGA),BAS(REV_OTHER), I got RSDRI query again.
    so in smmary,
    BAS(PARENT) =>MDX query.
    BAS(CHILD1)=>RSDRI query.
    BAS(CHILD2)=>RSDRI query.
    BAS(CHILD3)=>RSDRI query.
    BAS(CHILD1),BAS(CHILD2),BAS(CHILD3)=>RSDRI query
    I know VAL_FIELD is SAP reserved name for BPC dimensions.  my question is why BAS(PARENT) =>MDX query.?
    interestingly I can repeat this behavior in my system. my intention is to always get RSDRI query,
    George

    Ok - it turns out that Crystal Reports disregards BEx Query variables when put in the Default Values section of the filter selection. 
    I had mine there and even though CR prompted me for the variables AND the SQL statement it generated had an INCLUDE statement with hose variables I could see by my result set that it still returned everything in the cube as if there was no restriction on Plant for instance.
    I should have paid more attention to the Info message I got in the BEx Query Designed.  It specifically states that the "Variable located in Default Values will be ignored in the MDX Access".
    After moving the variables to the Characteristic Restrictions my report worked as expected.  The slow response time is still an issue but at least it's not compounded by trying to retrieve all records in the cube while I'm expecting less than 2k.
    Hope this helps someone else

  • Formatting MDX report,Error=One or more axes in MDX query have been skipped

    Hi All
    Need to show the measures on row-ways instead of Column-ways in MDX report. Able to generate report with measures Column-ways.
    Getting error when tried the following:
    #) when used "{} On Rows" instead of "{} On COlumns".
    ERROR - 1200545 - One or more axes in MDX query have been skipped.
    ERROR - 1241101 - Unexpected Essbase error 1200545.
    If anyone faced something like this before, please share some work-around.
    Thanks & Regards
    sharma

    Hi,
    Take a look at this SAP Note:  1580524 - Xcelsius Dashboard does not display variable popup
    Also go through the below discussion, it may help you.
    Bex Variable PopUp does not come up launching Xcelsius dashboard
    One or more mandatory variables of query XXX no... | SCN
    Bex Variable PopUp does not come up launching Xcelsius dashboard
    BICS - Passing Mandatory Filter Variable value to a BEx Query
    Passing parameters between XCelsius dashboards using BI direct connection
    Hope this helps brother.
    Regards,
    Suman T

  • 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

  • @CURRMBRRANGE to MDX query

    Hi ,
    Please help me out to get the Proper MDX query ..
    Below is my Essbase formula need to be converted to MDX query ..
    IF(@ISMBR(Actual,Budget,Forecast))
    (@SUMRANGE (A02, @CURRMBRRANGE(Period,LEV,0,-12,0)) /
    (@SUMRANGE (BusPool, @CURRMBRRANGE(Period,LEV,0,-12,0))/13))*100;
    ENDIF;
    I have tried the below but it is showing syntax error near the LEVEL ,
    (SUM(Crossjoin({[Dim Variable].[Parent Variable Id].&[69]},{
    RelMemberRange(
    [Dim Period].[Period ID].CurrentMember, 12,0,LEVEL)}))/
    SUM(Crossjoin({[Dim Variable].[Parent Variable Id].&[363]},{
    RelMemberRange(
    [Dim Period].[Period ID].CurrentMember, 12, 0,LEVEL)})/13))*100
    Please correct me,,
    Thanks in Advance

    Thanks for the Query but still i am getting problem.
    I have tried what u have mentioned like this ,
    WITH MEMBER [Measures].x AS
    IIF(
    Contains([Scenario].CurrentMember, {[Actual], [Budget], [Forecast]}),
    ((Sum(CrossJoin({[[Dim Variable].[Parent Variable Id].&[69]]}, {[Dim Period].[Period ID].[Period ID].CurrentMember.lag(12) : [Dim Period].[Period ID].[Period ID].CurrentMember}))
    / (Sum(CrossJoin({[[Dim Variable].[Parent Variable Id].&[363]]}, {[Dim Period].[Period ID].[Period ID].CurrentMember.lag(12) : [Dim Period].[Period ID].[Period ID].CurrentMember}))/13))*100),
    MISSING
    SELECT [Measures].x on 0
    FROM [BusPool Cube]
    but it giving the following error..
    Executing the query ...
    Query (3, 1) The '[Contains]' function does not exist.
    Execution complete
    And also tried without the IIF condition there too i am getting problem,
    WITH MEMBER [Measures].x AS
    Sum(CrossJoin({[A02]}, {[Dim Period].[Period ID].CurrentMember.lag(12) : [Dim Period].[Period ID].CurrentMember}))
    / (Sum(CrossJoin({[BusPool]}, {[Dim Period].[Period ID].CurrentMember.lag(12) : [Dim Period].[Period ID].CurrentMember}))/13)
    SELECT [Measures].x on 0
    FROM [BusPool Cube]
    For this query it is executed but giving the value as #Error,as like this
    x
    #Error
    When i keep my cursor on the #Error it shows as ,
    Infinite recursion detected.The loop of dependences is x->x.
    Please help me out in this ....

  • MDX query failed to execute (QAAWS)

    Hi All,
    When i execute dashboard (SAP BI -> Universe -> QAAWS -> Xcelsius) i get error:
    A database error occured. The database error text is: The MDX query SELECT  { [4KQ4D7SK7G9NG7WS5G6JD60I7].[4KQ4D808QEVCYUG8BA8VN7Z7Z] }  ON COLUMNS , NON EMPTY [4KQ4D6IH1ONECGO36FSHOU87J].MEMBERS ON ROWS FROM [ZFIGL_C04/ZFIGL_C04_Q0024] SAP VARIABLES [!V000002] INCLUDING 1000/20002M03 [0P_FPER] INCLUDING 004.2010 failed to execute with the error . (WIS 10901)
    Connection test of MDX Parser in sm59 is OK.
    When i execute same MDX statement in MDXTEST i get error:
    Invalid MDX command with /
    Message no. BRAINOLAPAPI100
    some time before i was getting the error:
    Invalid MDX command with Cin
    Message no. BRAINOLAPAPI100
    I have two variables in BEx query, Fiscal year period & Profit center(Hierarchy node variable). if i don't pass value for profit center i get the data in dashboard.
    When i execute QAAWS in edit mode with both parameters i get the data in preview of QAAWS.
    I was unable to find the clear solution when i searched in SDN. please help.
    Product versions:
    Xcelsius 2008 Enterprise edition
    BOE 3.0
    BI 7.0
    Regards,
    Pruthvi R
    Edited by: Pruthvi R on Feb 6, 2011 7:50 PM

    No, not in CR 2008.
    When i execute the QAAWS in preview i get the full hierarchy for selection. i have assigned L01 L02 L03 (levels of hierarchy) to 3 combo boxes  by using Filtered Rows option in combox boxes.
    i an not entering any thing manullay in dashboard. based on combo selection i get 1 node of hierarchy which i am passing to another qaaws along with fiscal period for data.
    the problem is the data feching query is not able to understand passing value of hierarchy node.
    i copied the mdx and executed in MDXTEST with different input. I get the characteristics list in first column and measure in second column will be always balnk for:
    "20002M03" or "1000/20002M03" or "[0profit_ctr].[20002M03]" (within square brackets)
    Regards,
    Pruthvi R
    Edited by: Pruthvi R on Feb 7, 2011 3:55 PM

  • How to show only key in mdx query

    Hello Experts
    i have mdx query such as :
    SELECT
    [Measures].MEMBERS ON AXIS(0) ,
    NON EMPTY [ZCHANNEL].members
    Properties [ZCHANNEL].[2ZCHANNEL]
    ON AXIS(1)
    FROM ZIC_TPL/ZIC_TPL_DETAIL
    SAP VARIABLES
    [ZVSOCALM] INCLUDING [0CALMONTH].[200605]
    the result from this query are zchannel text and zchannel key
    how to show only zchannel key ?
    really appreciate your help.
    regards
    JeiMing
    Message was edited by: JeiMing Tjiam

    Hi Juice
    Yes, i have already tried setting zchannel as key only in my query
    but the result from mdx query still shown key and text
    Regards
    JeiMing

  • Filters not getting passed in MDX query while using SAP BW with OBIEE

    Hello,
    I've been working on OBIEE with SAP BW as back-end. I've created some reports & those are working fine when there is less amount of data. But when I try to run a report with 3 dimensions & 1 fact it throws an error saying "No more storage space available for extending an internal table". When I checked MDX query, I found that the filters that I had applied to request & also selected from prompts are not getting passed in that query. So, I tried running a simple request using a simple filter in Answers. Although this request returns results but I can't see filter conditions in query. MDX query always show crossjoin but I can't see filter conditions anywhere.
    Is it the normal OBIEE behaviour OR am I doing something wrong in there? Can you please help me out with this?
    Thanks,
    Rocky

    Hello Sainath,
    We tried those things. But it is still giving same error.
    State: HY00. Code: 10058. [NQODBC][SQL_STATE:HY000][nQSError: 10058] A general error has occurred. XML/A error returned from the server: Fault code: "XMLAnalysisError.0X80000005". Fault string: "The XML for Analysis provider encountered an error: MDX result contains too many cells (more than 1 million)". (HY000)
    The problem here, I think, is the filter parameters are not getting passed in the MDX query. Any idea why would that happen? Is there any setting to do so?
    Thanks in advance for help.
    Regards,
    Rocky

Maybe you are looking for