MDX Query to roll up by date range.

I am trying to create a report that over time shows how many employees there are at any given time level. I have a list of employees and each employee has an Employment Start and Employment End. I also have a list of Times by Year, Month and Day. I have
looked at many of the examples but I cannot find anything that does this.
Thank you,
Logan

Please check the following:
http://sqlserverdiary.blogspot.com/2013/01/mdx-periodstodate-more-efficient-stored.html
Please mark this reply as the answer
or vote as helpful, as appropriate, to make it useful for other readers

Similar Messages

  • Need MDX query to find something like date diff and Date Range for last 10 days

    Hi ,
    I need two Query .First Query for below;
    I have below data in table like.
    Cat      StartDate    EndDate     
    A    2000-01-01     2000-01-15   
    B    2000-01-02     2000-01-30    
    C    2000-01-01     2000-01-31    
    D    2000-02-01     2000-02-28    
    A    2000-01-10     2000-01-31    
    I need if Startdate and Date completes whole one month then set status =1 else  0 using MDX query.
    like this ;
    Cat      StartDate    EndDate       Status
    A    2000-01-01     2000-01-15    1
    B    2000-01-02     2000-01-30    0
    C    2000-01-01     2000-01-31    1
    D    2000-02-01     2000-02-28    1
    A    2000-01-10     2000-01-31    1
    In second query I need last 10 days from current days like;
    Now = 8/20/2014
    output will be ;
    8/20/2014
    8/19/2014
    8/18/2014
    8/17/2014
    8/16/2014
    8/15/2014
    8/14/2014
    8/13/2014
    8/12/2014
    8/11/2014
    8/10/2014
    Please help me .
    Thanks

    Hi Prajapati,
    In your scenario, you can use Properties and Datediff function to achieve your requirement. Since not know the structure of your cube, we cannot give you the esact query.
     I have tested it on the AdventureWorks cube, the query below is for you reference.
    WITH MEMBER [Measures].[StartDate]
    AS
    [Employee].[Employee Department].CURRENTMEMBER.PROPERTIES('Start Date')
    MEMBER [Measures].[WorkYear]
    AS
    DATEDIFF('yyyy',[Measures].[StartDate],NOW())
    MEMBER [Measures].[Status]
    AS
    IIF(DATEDIFF('yyyy',[Measures].[StartDate],NOW())>10,1,0)
    SELECT {[Measures].[StartDate],[Measures].[WorkYear],[Measures].[Status]} ON 0,
    [Employee].[Employee Department].[Employee].MEMBERS ON 1
    FROM [Adventure Works]
    Results
    Reference
    http://msdn.microsoft.com/en-us/library/ms144821.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • 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

  • Mdx query to get the last date of every month if the month is current month need current date..

    i have a scenario where i need the data of last date of every month and if the month is current month need current date data...
    is it possible using MDX...

    Hi Shashi,
    According to your description, you want to return the last day for each month except current month, right?
    In MDX, we can use ClosingPeriod function to return the member that is the last sibling among the descendants of a specified member at a specified level, here is a sample query for you reference.
    with member [measures].[a]
    as
    ClosingPeriod ([Date].[Calendar].[Date],[Date].[Calendar].currentmember).name
    select {[measures].[a]} on 0,
    [Date].[Calendar].[Month].members on 1
    from
    [Adventure Works]
    And then use the IIF function to evaluate if the month is current month. Please refer to the links below.
    http://msdn.microsoft.com/en-us/library/ms145584.aspxhttp://msdn.microsoft.com/en-IN/library/ms145994.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • Query output based on the date range ...

    Hi All,
    I have an issue related to the jump query, main query based on the time frame. For Example if he selects Sold_To : 6895 for the Calday 10/01/2007 – 01/31/2008 and when jumps to jump query , the jump query should display the data based on the input given in the main query. That is it should show the data individually for four months.
    Expecting the reply from your side...
    Thanks in advance…
    Regards,
    Sruthi

    Sruthi,
    Make sure that u have those 3 fields in 2nd Query and CALDAY with Variable.
    Create settings in RSBBS.
    Click on ASSIGNMENT DETAILS tab
    CALDAY  >  Type = Variable  > Selection Type = Selection/Single value/Multiple single values ( same like ur first query )
    All other fields ( 3 na ) > Type = Generic
    Click on Continue / Save.
    If you need more info...if possible come to yahoo chat my ID is [email protected]....and am online now.
    Regards,
    Ramkumar.

  • How to get the child data in MDX query?

    I have an MDX query that will return the data for an OLAP report. These report data include the parent_id, child_id and some dimensions data in it. How do I modify the MDX query to have a New member to show a dimension value of the child_id.
    The child_is is actually the parent_id on another row. It is the "Pstpd Decision" I want to be included in a new column using the "Appeal Id". Thanks
    WITH MEMBER [Measures].[Avg TA Time] AS [Measures].[Turn Around Time]/[Measures].[Number of Request]
    SELECT NON EMPTY { [Measures].[Number of Request] } ON COLUMNS,
    NON EMPTY { ([Request Date Time].[FY-AP].[Account Period].ALLMEMBERS *
    [Request Drugs].[Drug Generic Name].[Drug Generic Name].ALLMEMBERS *
    [Dispensary].[Dispensary Hierarchy].[Dispensary].ALLMEMBERS *
    [Disease].[Tumour Group Site].[Tumour Group Site].ALLMEMBERS *
    [Disease].[Tumour Group Sub Site].[Tumour Group Sub Site].ALLMEMBERS *
    [Patient].[Patient Agency ID].[Patient Agency ID].ALLMEMBERS *
    [Pstpd Decision].[Decision].[Decision].ALLMEMBERS *
    [Request].[Request Id Key].[Request Id Key].ALLMEMBERS *
    [Request].[Appeal Id].[Appeal Id].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
    FROM ( SELECT ( { [Appeal Yes No].[Status].&[Yes] } ) ON COLUMNS
    FROM ( SELECT ( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED) ) ON COLUMNS
    FROM [CAP Request])) WHERE ( IIF( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED).Count = 1, STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED), [Request Date Time].[Fiscal Year].currentmember ), [Appeal Yes No].[Status].&[Yes] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
    data. 
    Kahlua

    I got it to work by adding the child_id's "decison' to the fact table as it is alot easier to get that data using Sql Script while creating the fact table and also there is already a "decsion" dimension setup. In the cube I can select the
    parent_id's decision and/or child_id's decision. It is working on the report. Thanks.
    Kahlua

  • Date Ranges Query

    Hi Experts,
    A very happy new year to all of you(to some in advance)!!
    I have a table where I have the employee id and task assigned with start dates & end dates. Overlapping dates of tasks is a data issue however I know how to spot them & eradicate them. So there will be no overlapping task dates
    Employee_id
    Task_No
    Task_Start_date
    Task_End_Date
    Sample Data
    1     T1     01-Jan-2014     28-Feb-2014
    1     T2     01-Mar-2014     31-Dec-2014
    2     T1     23-Jan-2014     31-Dec-2014
    2     T2     01-Jan-2015     31-Dec-2073 (Means end of time)
    3     T3     01-Jan-2014     15-Jul-2014
    3     T4     01-Aug-2014     31-Dec-2014
    4     T5     01-Jan-2014     31-Dec-2073
    I want to devise a query where i provide the end date & it will list out all the employees who are free for even one day starting 01-Jan-2014. So for example If I give 31-Dec-2014, it will list out
    EmpId     (First day on which the employee is free)
    2               01-Jan-2014
    3               16-Jul-2014
    If I give end date = end of time(31-Dec-2013), Expected Result -
    EmpId     (First day on which the employee is free)
    1               01-Jan-2015
    2               01-Jan-2014
    3               16-Jul-2014
    If I give end date = 31 Jan 2014, Expected Result -
    EmpId     (First day on which the employee is free)
    1               01-Jan-2015
    I devised following query, however it does not catch employee id 2. Also it does not provide flexibility to change end date-
    select *
      from (select employee_id,
                   task_start_date,
                   task_end_date,
                   lag(task_end_date, 1, task_start_date) over(partition by employee_id order by task_start_date) prev_end_date
              from shop.employee_tasks
             where task_end_date >= trunc(sysdate))
    where task_start_date - prev_end_date > 1
    Thanks in advance!!
    Regards,

    This is an example of what I call the "free time" query: you have the dates when you are busy and you want the dates when you are free.
    You can find a beautiful solution to the basic problem here: Ask Tom "SQL Query to find gaps in date ranges" (search for Antony Boucher's solution). Please note that this solution works even with overlapping date ranges.
    To apply the solution here, first create the test data (please do this yourself in later questions).
    create table t(Employee_id, task_no, Task_Start_date, task_end_date)
    as select
    1, 'T1', to_date('01-jan-2014'), to_date('28-feb-2014') from dual union all select
    1, 'T2', to_date('01-Mar-2014'), to_date('31-Dec-2014') from dual union all select
    2, 'T1', to_date('23-jan-2014'), to_date('31-dec-2014') from dual union all select
    2, 'T2', to_date('01-jan-2015'), to_date('31-dec-2073') from dual union all select
    3, 'T3', to_date('01-jan-2014'), to_date('15-jul-2014') from dual union all select
    3, 'T4', to_date('01-aug-2014'), to_date('31-dec-2014') from dual union all select
    4, 'T5', to_date('01-Jan-2014'), to_date('31-Dec-2073') from dual;
    In the query, you have to add records for yesterday and for the "end date" you want. This allows you to find "free time" before and after the date ranges in your table.
    Now you partition by Employee_id and order by Task_Start_date. Using the max(task_end_date) analytic function, you get the latest end date up to now. Add 1 to this and you get the first free date (maybe). To make sure that date is free, it has to be before the next start date.
    variable end_date varchar2(64)
    exec :end_date := '31-Dec-2073';
    with boundaries as (
      select trunc(sysdate)-1 task_start_date, trunc(sysdate)-1 task_end_date from dual
      union all
      select to_date(:end_date)+1, to_date(:end_date)+1 from dual
    ), data as (
      select * from t
    where task_end_date >= trunc(sysdate)
      and task_start_date < :end_date
      union all
      select distinct a.employee_id, null, b.task_start_date, b.task_end_date
      from t a, boundaries b
    select employee_id, min(free_start) free_start
    from (
      select employee_id,
      max(task_end_date) over (partition by employee_id order by task_start_date)+1 free_start,
      lead(task_start_date) over (partition by employee_id order by task_start_date)-1 free_end
      from data
    where free_start <= free_end
    group by employee_id;
    EMPLOYEE_ID
    FREE_START
    1
    01-JAN-15
    2
    01-JAN-14
    3
    16-JUL-14

  • Single day date range query

    I have a table with a created_date column. The datatype is DATE.
    When i query this table for some date range I do not ever get any results for a single day.
    e.g. select * from table where created_date >='29-Dec-2009' and created_date <='30-Dec-2009'.
    Result set = 5 records
    However,
    select * from table where created_date >='29-Dec-2009' and created_date <='29-Dec-2009'.
    OR
    select * from table where created_date >='30-Dec-2009' and created_date <='30-Dec-2009'.
    yield 0 records.
    Why is this so? I seem to be missing something obvious. Any pointers would be really helpful

    select * from table where created_date >='29-Dec-2009' and created_date <='30-Dec-2009'.means all created date between '29-Dec-2009 00:00:00' and '30-Dec-2009 00:00:00'
    select * from table where created_date >='29-Dec-2009' and created_date <='29-Dec-2009'.means all created date between '29-Dec-2009 00:00:00' and '29-Dec-2009 00:00:00'
    select * from table where created_date >='30-Dec-2009' and created_date <='30-Dec-2009'.means all created date between '30-Dec-2009 00:00:00' and '30-Dec-2009 00:00:00'
    So you need to correctly manage the time...
    select * from table where created_date >='29-Dec-2009' and created_date &lt; '30-Dec-2009'.To get only records at any time during Dec-29.
    select * from table where created_date >='30-Dec-2009' and created_date &lt; '31-Dec-2009'.To get only records at any time during Dec-30.
    select * from table where created_date >='29-Dec-2009' and created_date &lt; '31-Dec-2009'.To get only records at any time during Dec-29 and Dec-30.
    Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • Date Range Issue

    Hi Experts,
    I have created a linked server to connect to mysql DB . The query is executing fine currently filter is based on the on going month.
    The query actually fetches the records from 2 tables User and time sheet to find how many hours the users have  .
    Now we check the Hours for a period of 10th of the current month and 10th of the upcoming month .
    So for now date range will be  between 2014/10/05 and 2014/10/06.  This logic i have implemented in the query .
    Based on the query a report is generated which is sent out every Wednesday  .Now suppose its 5th of June 2014 . 
    The query will fail because the date range is derived based upon
    where cast(t.created_on as Date) > Concat(year(now()),"-",month(now()),"-","10")
     AND cast(t.created_on as Date) <=Concat(year(now()),"-",month(now())+1,"-","10")
    Please provide with a date filter like the report runs anytime the data is not affected. Like if the report is run in the
    first week of a new month  date range should be previous month Date 10 and current month  Date 10 and if the report is run after 10th of the current month then the date range should be between 10th of current month and 10 of upcoming month . Kindly
    help
    Select * From
    OPENQUERY
    (Mysql,
    'Select
     Sum(t.hours),
     Concat(u.firstname," ",
     u.lastname) as Name
     From mysql.time_entries t
     Inner Join
     users u
     on u.id = t.user_id    
     where cast(t.created_on as Date) >
     Concat(year(now()),"-",month(now()),"-","10")
     AND
     cast(t.created_on as Date) <=Concat(year(now()),"-",month(now())+1,"-","10")
     Group By u.firstname,u.lastname
     Union all
     Select Sum(0) as hours,
     Concat(firstname," ",
     lastname) as Name
     from users
     where id not in(
     Select
     t.user_id
     From mysql.time_entries t
     Inner Join
     users u
     on u.id = t.user_id    
     where cast(t.created_on as Date) >
     Concat(year(now()),"-",month(now()),"-","10")
     AND
     cast(t.created_on as Date) <=Concat(year(now()),"-",month(now())+1,"-","10"))
     And firstname not in( "xyz")
      GRoup by firstName,lastname'
      go

    I recommend use CLOSED-OPEN dates rather than OPEN-CLOSED dates...
    Hopefully this helps with your logic:
    DECLARE @ReportDate TABLE
    [ReportDate] DATE,
    [mDay] AS DAY([ReportDate]),
    [Beg] AS DATEADD(month, CASE WHEN DAY([ReportDate]) < 10 THEN -1 ELSE 0 END, [ReportDate]),
    [End] AS DATEADD(month, CASE WHEN DAY([ReportDate]) < 10 THEN 0 ELSE 1 END, [ReportDate]),
    [ReportBeg] AS DATEADD(month, CASE WHEN DAY([ReportDate]) < 10 THEN -1 ELSE 0 END, DATEADD(day, 10 - DAY([ReportDate]), [ReportDate])),
    [ReportEnd] AS DATEADD(month, CASE WHEN DAY([ReportDate]) < 10 THEN 0 ELSE 1 END, DATEADD(day, 10 - DAY([ReportDate]) + 1, [ReportDate]))
    INSERT INTO @ReportDate(ReportDate)
    VALUES
    ('7-May-2014'),
    ('10-May-2014'),
    ('15-May-2014');
    SELECT
    CASE WHEN SYSDATETIME() >= [ReportBeg] AND SYSDATETIME() < [ReportEnd] THEN 1 ELSE 0 END
    FROM @ReportDate;

  • 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.

  • Passing date range parameters in MDX Query

    Following is my mdx query
    SELECT NON EMPTY
        [Measures].[Cache Attendees Count]
    ON COLUMNS,
    NON EMPTY
        ([Cache Attendees].[Visit Id].[Visit Id].ALLMEMBERS *
        [Cache Attendees].[User Id].[User Id].ALLMEMBERS *
        [Cache Attendees].[Screen Name].[Screen Name].ALLMEMBERS *
        [Cache Attendees].[User Type Id].[User Type Id].ALLMEMBERS *
        [Cache Attendees].[User Type Name].[User Type Name].ALLMEMBERS *
        [Cache Attendees].[Group Date Count].[Group Date Count].ALLMEMBERS *
        [Cache Attendees].[Insert Time Stamp].[Insert Time Stamp].ALLMEMBERS )
        DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM
        SELECT
                STRTOMEMBER(@FromCacheAttendeesInsertTimeStamp) : STRTOMEMBER(@ToCacheAttendeesInsertTimeStamp)
            ) ON COLUMNS FROM (
            SELECT
                STRTOSET(@CacheAttendeesConferenceId) ) ON COLUMNS FROM [Cube_Attendee])
            WHERE ( IIF( STRTOSET(@CacheAttendeesConferenceId).Count = 1, STRTOSET(@CacheAttendeesConferenceId), [Cache Attendees].[Conference Id].currentmember ) )
    CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
    I want to filter my cube with three parameters
    1. @CacheAttendeesConferenceId
    2. @FromCacheAttendeesInsertTimeStamp
    3. @ToCacheAttendeesInsertTimeStamp
    When i pass following parameters
    ConferenceId = 1, StartDate='2010-01-28T00:00:00', EndDate='2010-02-03T00:00:00'
    Then it show records
    But When i pass following parameters
    ConferenceId = 1, StartDate='2010-01-27T00:00:00', EndDate='2010-02-03T00:00:00'
    Then it display message No Data Available
    PLease help me on this issue why not FromDate & ToDate range works properly.

    Step1:- First i create a SSAS datasource. Then i create a cube for my table CacheAttendees.
    It has following columns:-
    [Cache Attendees].[Conference Id]
    [Cache Attendees].[Group Date Count]
    [Cache Attendees].[Insert Time Stamp]
    [Cache Attendees].[Screen Name]
    [Cache Attendees].[User Id]
    [Cache Attendees].[User Type Id]
    [Cache Attendees].[User Type Name]
    [Cache Attendees].[Visit Id]
    Step2:- Then i create a dimension with this cube with all columns.
    Step3:- Then i deploy my SSAS project.
    Step4:- Use SSAS datasource in my SSRS datasource.
    Step5:- Create a report with chart control. Add a parameter ConferenceId. Set default to 1. When i preview my report then it show Cache Attendees].[Conference Id].[1] in header of report instead of that, When i pass the parameter value as 1 then report cannot show & throw an error. I want to pass this parameter at runtime.
    Step6:- Please help me how is it possible to pass parameter at runtime.

  • Date parameters using MDX query

    Hello experts,
    Not sure if this question falls under SSAS or SSRS but I'm writing it here for now and hopefully get the answer.
    I'm using SSAS cube to develop a report using SSRS and this is the first time I'm doing it. I want to filter records based on date range and did some research online. My report contains two datasets:
    1. dsMain dataset -> it contains all the field which I want to use in the report and added a parameter thru query designed with following settings:
    Dimension : Dates
    Hierachary : Date
    Operator : Range (Inclusive)
    Parameters : checked
    it created two parameters called FromDatesDate and toDatesDate
    2. I created another dataset called dsDate and wrote a custom query (found at following link) and changed FromDatesDate and ToDatesDate using this date dataset
    https://jsimonbi.wordpress.com/2011/03/22/using-a-date-parameter-in-ssrs-with-mdx/
    Query for dsDate
    WITH
    MEMBER DateValue
    AS
       [Dates].[Date].CurrentMember.UniqueName
    MEMBER DateLabel
    AS
       [Dates].[Date].CurrentMember.Name
    SELECT
        [Measures].[DateValue],
        [Measures].[DateLabel]
    } ON 0,
         [Dates].[Date].[Date]
    } ON 1
    FROM [myCube]
    Here is the value returned by dsDate dataset (above query)
                            DateValue                          DateLabel
    06/04/1980 [Dates].[Date].&[29375]
    06/04/1980
    06/05/1980 [Dates].[Date].&[29376]
    06/05/1980
    06/06/1980 [Dates].[Date].&[29377]
    06/06/1980
    06/07/1980 [Dates].[Date].&[29378]
    06/07/1980
    06/08/1980 [Dates].[Date].&[29379]
    06/08/1980
    06/09/1980 [Dates].[Date].&[29380]
    06/09/1980
    06/10/1980 [Dates].[Date].&[29381]
    06/10/1980
    06/11/1980 [Dates].[Date].&[29382]
    06/11/1980
    06/12/1980 [Dates].[Date].&[29383]
    06/12/1980
    06/13/1980 [Dates].[Date].&[29384]
    06/13/1980
    Here is what I changed in FromDatesDate and ToDatesDate parmeter:
    Under Available Values tab:
    Dataset : dsDate
    Value Field : DateValue
    Label Field : DateLabel
    Here are my questions:
    1. I want to use date/time parameter so that user doesn't have to scroll thru whole date dimension.
    2. I changed the FromDatesDate and ToDatesDate to date/time parameter, removed the values from Available values tab and made the following changes on Parmaeters expression under dsMain dataset
    =”[Dates].[Date].&[” + Format(CDate(Parameters!FromDatesDate.Value),”MM/dd/yyyy”)
    + “T00:00:00]”
    =”[Dates].[Date].&[” + Format(CDate(Parameters!ToDatesDate.Value),”MM/dd/yyyy”)
    + “T00:00:00]”
    Now when I run the report I get following error:
    Query (1, 55) The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function are violated.
    I think the reason is by changing parameter to date/time, now I cannot get "DateValue" which is required for the query.
    1. What is the best way to work with date parameters?
    Hope it is all clear and look forward to hear from experts.
    Thanks,
    P
    mark it as answer if it answered your question :)

    Hi Parry2k,
    In Analysis Services, a member can be referenced by either its member name or by its member key. The member key is used by the dimension to specifically identify a given member. The ampersand (&) character is used in MDX to differentiate
    a member key from a member name. In this scenario, the datetime is member name, not the member key. So you should not add "&".
    Reference:
    Member Names and Keys
    Simon Hou
    TechNet Community Support

  • MDX MTD with a Date Range

    Hi All
    I need some advice on the below, it works, gives the answers I want, but I believe the filter on the set can be moved to a where clause, and the MTD can work effectively then with the sum of the date range on the [RangeHasResponse] measure (advice apart
    from "if it ain't broke don't fix it" ;) ).  This is query for a report where I can sub in a param date range (set the Today value, and the from in the DateRange), and produce the Sum of Has Response across that date range, and also the MTD
    for last month up to the ToDate.
    Any advice on how the MDX could be better structured would be great, I can understand I'm calculating members, then adding them to my query, it just seems I should be calculating them in the SELECT based on a filter.  Output just needs to be
    [MTD]: single sum of Has Response to the current todate for that month
    [RangeHasResponse]:Sum of the entire range
    [Has Response] : sum on the last day, this isn't necessary, I'm just curious to see how that would tie into a filter, if it ruins the above leave it out.
    WITH
    SET [ToDate]=[Date].[Year - Quarter - Month - Date].[Date].&[2014-02-22T00:00:00]
    SET [DateRange] =
    [Date].[Year - Quarter - Month - Date].[Date].&[2014-01-01T00:00:00]:
    [ToDate].item(0)
    MEMBER [Measures].[MTD] AS
    SUM(MTD([Date].[Year - Quarter - Month - Date].CurrentMember),[Measures].[Has Response])
    MEMBER [Measures].[RangeHasResponse] AS
    SUM([DateRange],[Measures].[Has Response])
    SELECT
    {[Measures].[MTD],[Measures].[Has Response],[Measures].[RangeHasResponse] } on columns
    ,[ToDate] on rows
    FROM
    [ISD Prototype]
    Thanks
    Best Wishes, The Redman; If something helps, please help show it by voting, if it solves, bonus!

    Hi GGoldspink,
    In MDX, the CREATE MEMBER statement defines calculated members that are available throughout the session, and therefore, can be used in multiple queries during the session. So if the members can will be used in multiple times in SELECT clause, we can create
    a calculated member, and then use this members on SELECT clause which will improve the query performance.
    In your scenario, are there any performance issue in your MDX query? In this case, I'd suggest you enable SQL Sever profiler to monitor the queries, and check which part in the query took a very long time to run. Here is a useful link for your reference.
    http://sqlmag.com/database-performance-tuning/using-sql-profiler-tune-mdx-queries
    Besides, here is a document which will help you understand where issues can occur in your existing MDX code that will prevent you from experiencing the performance improvements, and provide advice on how to avoid these issues in your new MDX coding.
    http://technet.microsoft.com/en-us/library/bb934106(v=sql.105).aspx
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here
    Charlie Liao
    TechNet Community Support

  • Date range query  problem  in report

    Hi all,
    I have created a report based on query and i want to put date range selection but query giving problem.
    If i am creating select list selection then it is working fine means it will display all records on the particular date.
    But what i need is that user will enter date range as creation_date1,creation_date2 and query should return all the records between these date range. i want to pass it by creating items, i created two items and passing creation_date range to display all records but not displaying and if not passing date then should take null as default and display all records
    Here is the query:
    /* Formatted on 2006/12/10 20:01 (Formatter Plus v4.8.0) */
    SELECT tsh."SR_HEADER_ID", tsh."SALES_DEPT_NUMBER", tsh."COUNTRY",
    tsh."LOCAL_REPORT_NUMBER", tsh."ISSUE_DATE", tsh."SUBJECT",
    tsh."MACHINE_SERIAL_NUMBER", tsh."MACHINE_TYPE", tsh."MACHINE_HOURS",
    tsh."STATUS"
    FROM "TRX_SR_HEADERS" tsh, "TRX_SR_PARTS" tsp
    WHERE (tsh.status LIKE :p23_status_sp OR tsh.status IS NULL)
    AND (tsh.machine_type LIKE :p23_machine_type_sp)
    AND ( tsh.machine_serial_number LIKE
    TO_CHAR (:p23_machine_serial_number_sp)
    OR tsh.machine_serial_number IS NULL
    AND ( TO_CHAR (tsh.failure_date, 'DD-MON-YY') LIKE
    TO_CHAR (:p23_failure_date_sp)
    OR TO_CHAR (tsh.failure_date, 'DD-MON-YY') IS NULL
    AND ( TO_CHAR (tsh.creation_date, 'DD-MON-YY')
    BETWEEN TO_CHAR (:p23_creation_date_sp)
    AND TO_CHAR (:p23_creation_date_sp1)
    OR TO_CHAR (tsh.creation_date, 'DD-MON-YY') IS NULL
    AND (tsh.issue_date LIKE :p23_date_of_issue_sp OR tsh.issue_date IS NULL)
    AND (tsh.country LIKE :p23_country_sp OR tsh.country IS NULL)
    AND ( tsh.local_report_number LIKE TO_CHAR (:p23_local_rep_num_sp)
    OR tsh.local_report_number IS NULL
    AND ( tsp.part_number LIKE TO_CHAR (:p23_part_number_sp)
    OR tsp.part_number IS NULL
    AND tsh.machine_type IN (
    SELECT DISTINCT machine_type
    FROM trx_sales_dept_machine_list
    WHERE sales_department_id IN (
    SELECT DISTINCT sales_department_id
    FROM trx_user_sales_department
    WHERE UPPER (user_name) =
    UPPER ('&APP_USER.'))
    AND SYSDATE >= valid_from)
    AND tsh.sr_header_id = tsp.sr_header_id
    can any one tell me wat is wroung in this query.
    Any other way to write this?
    Thank You,
    Amit

    Hi User....
    Here is some date range SQL that my teams uses with some success:
    For date columns that do not contain NULL values, try this (note the TRUNC, it might help with your "today" problem).
    The hard coded dates allow users to leave the FROM and TO dates blank and still get sensible results (ie a blank TO date field asks for all dates in the future.
    AND TRUNC(DATE_IN_DATABASE)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),:
    :P1_DATE_TO)
    For date columns that contain NULL values, try this (a little bit trickier):
    AND nvl(TRUNC(DATE_IN_DATABASE),
    decode( :P1_DATE_FROM,
    decode( :P1_DATE_TO,
    TO_DATE('30-DEC-3000'),
    NULL),
    NULL)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),
    :P1_DATE_TO)
    Note the 30-DEC-3000 versus 31-DEC-3000. This trick returns the NULL dates when the FROM and TO date range items are both blank.
    I hope this helps.
    By the way, does anyone have a better way of doing this? The requirement is given a date column in a database and a FROM and a TO date item on a page,
    find all of the dates in the database between the FROM and TO dates. If the FROM date is blank, assume the user want all dates in the past (excluding NULL dates). If the TO date is blank, assume that the user wants all of the dates in the future (excluding NULL dates). If both FROM and TO dates are blank, return all of the dates in the databse (including NULL dates).
    Cheers,
    Patrick

  • SSRS report with tabular model - MDX query to filter parameter data based on Tuple value.

    Hello Everyone,
    I am working on SSRS report in which a tabular model is being used as a backend.
    I want to filter the report parameters which are dependent to other parameters. Like, country, state, and cities drop downs.
    All are multi-select parameters. I am using MDX queries to filter the parameters data.
    Based on selected one or more countries, the data of states needs to be filtered.
    The point is the text which is being displayed in state dropdown for each state name is combination of 3 different members.
    So, I created the following Tuple for the same and can see the expected display names in states dropdown.
    "("+
    [Location].[Code 1].CURRENTMEMBER.UNIQUENAME +","+
    [Location].[Code 2].CURRENTMEMBER.UNIQUENAME +","+
    [Location].[Descr].CURRENTMEMBER.UNIQUENAME +")"
    Now, when I would like filter the cities data based on selected one or more states, I am unable to pass the multiple Tuples (more than one selected Tuples) as parameter for cities dropdown.
    The following is my query for City parameter. It is working well when I select only one State from the dropdown.
    However, when I select multiple states, it is unable to convert the Tuple into SET in ELSE part of IIF condition specified in following query.
    Can anybody help me how to resolve the error that I am getting about STRTOSET function?
    Or
    Are there any other alternatives to achieve this requirement?
    Any help would be much appreciated.
    Query:
    WITH MEMBER [Measures].[ParameterCaption] AS [City].[City Business].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS [City].[City Business].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS [City].[City Business].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]} ON COLUMNS ,
    [City].[City Business].Children ON ROWS
    FROM (
    SELECT ( STRTOSET(@State, CONSTRAINED) ) ON COLUMNS FROM [Model])
    WHERE ( IIF( STRTOSET(@State).Count= 1,
    STRTOTUPLE(@State, CONSTRAINED),
    STRTOSET("{
    ("+
    [Location].[Code 1].CURRENTMEMBER.UNIQUENAME +","+
    [Location].[Code 2].CURRENTMEMBER.UNIQUENAME +","+
    [Location].[Descr].CURRENTMEMBER.UNIQUENAME
    + ")
    }",CONSTRAINED )) ) CELL PROPERTIES VALUE
    Thanks, Ankit Shah
    Inkey Solutions, India.
    Microsoft Certified Business Management Solutions Professionals
    http://www.inkeysolutions.com/MicrosoftDynamicsCRM.html

    Hi,
    I used following dynamic query in expression of dataset of parameter and it works like a charm.
    "WITH MEMBER [Measures].[ParameterCaption] AS [City].[City Business].CURRENTMEMBER.MEMBER_CAPTION "&
    "MEMBER [Measures].[ParameterValue] AS [City].[City Business].CURRENTMEMBER.UNIQUENAME "&
    "MEMBER [Measures].[ParameterLevel] AS [City].[City Business].CURRENTMEMBER.LEVEL.ORDINAL "&
    "SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]} ON COLUMNS , " &
    "[City].[City Business].Children ON ROWS " &
    " FROM [Model] WHERE ({"& join(Parameters!Location.Value,",") &"}) CELL PROPERTIES VALUE"
    Thanks, Ankit Shah
    Inkey Solutions, India.
    Microsoft Certified Business Management Solutions Professionals
    http://www.inkeysolutions.com/MicrosoftDynamicsCRM.html

Maybe you are looking for

  • VPN Client and Terminal Server

    We have several clients that allow us to vpn into their systems and it has come to the point that we are getting software incompatabilities. What I am trying to do is set up "compatable" connections on a Terminal server box and let our people access

  • I just bought a song on itunes and it downloaded it but for some reason is not playing, does anybody know why ??

    i just bought a song on itunes and it downloaded it but for some reason is not playing. o you know why?

  • Loan from Vendor Employee

    Hi Our directors are created as Employee Vendor. There are some cases where company take loan from directors. We have created these "loansfrom directors" as as special GL indicators. Now i want to know how to take loan from directors vendors. I tried

  • Pictures in a video

    Is there are way to put a "still frame picture" into a video for narration, a la Ken Burns type documentary? I am trying to mix video with stills and narration, like seen in a typical documentary you see. I am using IMove o8 so far and may upgrade to

  • Automatically creating sequence diagram.

    Hi, Is there any way to create UML sequence diagram automatically from the existing java code? I am using jdeveloper 11.1.2.2.0. I know this feature is there in older versions, debug->debug with diagram. How can I achieve that in this version? Regard