Get The Previous Six Weeks in Query

I have an MDX query that I'm using in an SSRS report. The report returns results for the current week beginning on Sunday. THe query takes three parameters: Year, Month, and Week. The year is defaulted to the curret year, the month is defaulted to the current
month, and the week is defaulted to the current week. Here is the MDX of the query:
SELECT
NON EMPTY
{[Measures].[Employee Hours]} ON COLUMNS
,NON EMPTY
[Employee].[Employee Discipline].[Employee Discipline].ALLMEMBERS*
[Employee].[Employee Department].[Employee Department].ALLMEMBERS*
[Employee].[Employee Full Name].[Employee Full Name].ALLMEMBERS*
[Employee Hours Time Category].[Utilization Category].[Utilization Category].ALLMEMBERS*
[Employee Hours Time Category].[Time Category].[Time Category].ALLMEMBERS*
[Project].[Client].[Client].ALLMEMBERS*
[Time].[Year].[Year].ALLMEMBERS*
[Time].[Month].[Month].ALLMEMBERS*
[Time].[Week].[Week].ALLMEMBERS
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
SELECT
StrToSet
(@TimeWeek
,CONSTRAINED
) ON COLUMNS
FROM
SELECT
StrToSet
(@TimeMonth
,CONSTRAINED
) ON COLUMNS
FROM
SELECT
StrToSet
(@TimeYear
,CONSTRAINED
) ON COLUMNS
FROM
SELECT
StrToSet
(@EmployeeEmployeeDepartment
,CONSTRAINED
) ON COLUMNS
FROM
SELECT
StrToSet
(@EmployeeEmployeeDiscipline
,CONSTRAINED
) ON COLUMNS
FROM [OLSON BI]
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
What I would like to do is return not just the current week, but also the previous five weeks.
IF there is an easier way to do this without having to pass the current year and the current month, that would be een better. I do have a time dimension called time which does have the [Time].[Week] member which is in the format of MM/DD/YYYY 00:00:00:00.
Any help would be greatly appreciated!
Thanks!!
A. M. Robinson

Your solution requires me to figure out what the week was six weeks ago. How is that accomplished? That is what the MDX is supposed to do. Take the current week (i.e., 8/31/2014) and go back six weeks.
In MDX you can do this for years, month, days, etc. It's fairly easy to say "give me the three previous years from the current year". I want the same thing for weeks.
I'm passing in a simple parameter for week: 8/31/2014 00:00:00. This is how it is formatted in the actual dimension table.
From what I've found, LastPeriods seems like the way to go...just trying to figure it out to work with my MDX. Take the current period and go back X number of periods.
SELECT LastPeriods(3,[Date].[Fiscal].[Fiscal Quarter].[Q4 FY 2002]) ON 0
FROM [Adventure Works]
A. M. Robinson

Similar Messages

  • Help needed in getting the previous Quarter Data

    Hello folks,
    I have this procedure where i have to modify the current procedure in the following manner:
    I need to get rid of the variables p_start and p_end so that i cannot see them in the crystal report and include the Frequency in the procedure to get the Data based on the Dates.
    and Main requirement is" If the Frequency is Quarterly " it should get the previous quarter Data, if "Frequency is monthly" it should return the previous month data.Can anyone please let me know where shud i make changes. Am including the procedure for refernce. Any help is appreciated
    Thanks a millioin,
    CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h(report_record in out cr_return_types.gen_cursor,
    p_start       string,
    p_end         string)
    IS
    v_startdate date;
    v_enddate date;
    BEGIN
    v_startdate := to_date(p_start, 'YYYY/MM');
    v_enddate := last_day(to_date(p_end, 'YYYY/MM'));
    open report_record for
    select --distinct r.recovery_id
    r.event_id,
    r.event_case_id,
    c.client_id,
    c.client_code,
    c.client_name,
    b.branch_group_code,
    b.branch_group_description,
    g.employer_group_code,
    g.employer_group_name,
    e.client_policy_identifier,
    e.date_of_incident,
    e.event_type_code,
    sum(nvl(r.amount, 0)) as amt_received,
    nvl(sum(case
    when r.amount >= 0 then
    rd.fees
    else
    rd.fees * (-1)
    end),
    0) as fees,
    ec.close_date, *001* commented
    (case
    when ec.close_date <= to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
    'MMDDRRRR HH24MISS') then
    ec.close_date
    else
    null
    end) as close_date, --*001*  added
    get_case_value(ec.event_id, ec.event_case_id, v_enddate) as case_value,
    nvl(etl.fee_percent_flag, 'N') workmans_comp,
    max(to_char(r.recovery_date, 'FMMonthYYYY')) Year_Month,
    max(to_char(r.recovery_date, 'YYYYMM')) Y_M,
    max(to_date(to_char(r.recovery_date, 'MMYYYY'), 'MM/YYYY')) date_MY
    from recovery r,
    recovery_detail rd,
    event e,
    client c,
    branch_group b,
    employer_group g,
    event_case ec,
    event_type_lookup etl
    where r.event_id = e.event_id
    and r.event_case_id = ec.event_case_id
    and ec.event_id = e.event_id
    and rd.recovery_id(+) = r.recovery_id
    and r.recovery_date between v_startdate and
    to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
    'MMDDRRRR HH24MISS')
    and e.client_id = c.client_id
    and g.client_id = c.client_id
    and b.client_id = c.client_id
    and g.employer_group_id(+) = e.employer_group_id
    and b.branch_group_id(+) = g.branch_group_id
    and e.event_type_code = etl.event_type_code -- SST 130852 04/14/09
    group by r.event_id,
    r.event_case_id,
    c.client_id,
    c.client_code,
    c.client_name,
    b.branch_group_code,
    b.branch_group_description,
    g.employer_group_code,
    g.employer_group_name,
    e.client_policy_identifier,
    e.date_of_incident,
    e.event_type_code,
    ec.close_date,
    get_case_value(ec.event_id, ec.event_case_id, v_enddate),
    nvl(etl.fee_percent_flag, 'N')
    having sum(nvl(r.amount, 0)) <> 0
    order by c.client_code,
    b.branch_group_code,
    g.employer_group_code,
    r.event_case_id;
    Edited by: user11961230 on Oct 20, 2009 9:02 AM

    user11961230 wrote:
    1. I want to get rid of the p_start and p_end. So how do i declare the v_startdate and v_enddate in the following part?
    v_startdate := to_date(p_start, 'YYYY/MM');
    v_enddate := last_day(to_date(p_end, 'YYYY/MM'));I'm not sure what you mean by "declare".
    In PL/SQL, "declare" means state (at the beginning of a block) that there will be a certain variable with a certain name (such as v_startdate) and datatype (such as DATE). You're already declaring the variables v_startdate and v_enddate correctly, right before the BEGIN statement.
    Declaring a variable is not the same as initializing it, that is, giving it a value for the first time. Your next question seems to be about initializing..
    2. where exactly shud i include the logic that u have mentioned. sorry a dumb questionIn place of the two assignment statments that reference p_start and p_end.
    3. This time am gonna use frequency instead of report_type so that i will get rid of the p_start and p_end from the procedure.Do you mean you want to pass an argument (called frequency) that tells if you want a quarterly or a mionthly report, just like the variable report_type in my example?
    If so, replace report_type in my example with frequency.
    I think you want something like this:
    CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h
    (      report_record         in out     cr_return_types.gen_cursor
    ,      frequency         IN           VARCHAR2
    IS
         -- Declare local variables:
         v_startdate     date;
         v_enddate      date;
    BEGIN
         -- Initialize v_startdate and v_enddate, depending on frequency
         IF  frequency = 'QUARTERLY'
         THEN
              v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -3)
                                           , 'Q'
              v_enddate := TRUNC (SYSDATE, 'Q');
         ELSIF  frequency = 'MONTHLY'
         THEN
              v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -1)
                             , 'MM'
              v_enddate := TRUNC (SYSDATE, 'MM');
         END IF;
         --   Subtract one second from v_enddate
              v_enddate := v_enddate - ( 1
                                            / (24 * 60 * 60)
         open report_record for
         select --distinct r.recovery_id
                r.event_id,
         and     r.recovery_date  BETWEEN  v_startdate     
                         AND       v_enddate
         ...When you post formatted text on this site (and code should always be formatted), type these 6 characters:
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
    Edited by: Frank Kulash on Oct 20, 2009 2:37 PM
    Changed query to use BETWEEN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • FM to get the previous sunday date based on current date(sy-datum)

    hi all,
    Is there any function module to get the previous sunday date based on current date(sy-datum)?
    Regards,
    Kapil Sharma
    Moderator Message: Basic date related questions are not allowed
    Edited by: Suhas Saha on Sep 19, 2011 11:39 AM

    Hi,
    There are function modules to find out the current day of the week depending on sy-datum. These are as below:
    1. DATE_COMPUTE_DAY - Returns a number indicating what day of the week the date falls on. e.g. Monday is returned as a 1, Tuesday as 2,...., Sunday as 7.
    2. RH_GET_DATE_DAYNAME  - Returns the day based on the date provided, e.g. Monday, Tuesday,..., Sunday.
    Using any of the above, if you can find out the current day, then you can calculate and compute the date of the previous Sunday.
    My observation is that using the first FM might make the calculation simpler.
    Hope this is of help to you.
    Regards,
    Shayeree

  • I have a problem with my Internet Security and the new Firefox, where can I get the previous version which I had before my system crashed?

    Hi I use CA Internet Security Suite which checks ALL pages and searches, but it does not work with this version, also I wish to use Goggle Toolbar which ALSO does not work with this version where can I get the previous version? As my harddrive crashed I have had to install windows 7 and this version doesn't seem to allow me to change my homepage, why is this? Cheers Ernest

    You can get the latest version of Firefox 3.6 from http://www.mozilla.com/en-US/firefox/all-older.html
    Mozilla are working to prevent Mac users with non-compatible systems from getting the notification about Firefox 4, and also not displaying the "Download Firefox 4" button on http://www.mozilla.com

  • I HAVE AN IPHONE 5S AND WANT TO USE SOFTWARE 7.0.2 BECAUSE IT IS COMPATIBLE WITH MY VEHICLE FOR UCONNECT. I CURRENTLY HAVE SOFTWARE 7.0.3 ON MY DEVICE. HOW WOULD I GET THE PREVIOUS SOFTWARE BACK ON MY PHONE

    I HAVE AN IPHONE 5S AND WANT TO USE SOFTWARE 7.0.2 BECAUSE IT IS COMPATIBLE WITH MY VEHICLE FOR UCONNECT. I CURRENTLY HAVE SOFTWARE 7.0.3 ON MY DEVICE. HOW WOULD I GET THE PREVIOUS SOFTWARE BACK ON MY PHONE

    Forum Tip: It is generally considered inappropriate to type all in uppercase letters in Internet discussions, as text that is typed all in uppercase is by convention considered to be shouting.  Uppercase is also more difficult to read, so please use all uppercase sparingly and only when you really mean to shout, which we hope you won’t need to do here .
    Regards.

  • Computer iMac7,1 has been giving sundry problems for some time. Within the last six weeks I have reinstalled the OS (Snow Leopard), without affecting the overall contents of the hard drive. ±3 weeks later the problems became more serious and I again reins

    Computer iMac7,1 has been giving sundry problems for sometime. Within the last six weeks I have reinstalled the OS (Snow Leopard),without affecting the overall contents of the hard drive.
    ±3 weeks later the problems became more serious and I againreinstalled the OS and installed OS 6.6.7 from the internet.
    I used the option to restore from the external backup driveand went back some time as it was my intention to reinstall individualcomponent in an attempt to find out where the problem might lie. This hasintroduced an entirely new problem! If I open Time Machine from the desktop itappears that all backups from late 2009 to June 2011 are intact. But, in thiscase there are none of the restore functions &c on screen. The latter areonly shown if Time Machine is opened from the menu bar or from the dock but, inthis case, available are only backups in late 2009!
    I also opened the Apple Hardware Test in an attempt toestablish the nature of the problem. The ‘quick’ version said there’s nothingwrong; the more detailed one reported “Error detected, 4HD/11/40000004.” I haveagain tried to employ this test but nothing I do can induce it to open!!!
    What to do? I need help urgently and would appreciate anyadvice that offers solutions to the problem.

    To check your S.M.A.R.T status open disk utility and click on your drive and then click on the info icon.

  • How to get the previous state of my data after issuing coomit method

    How to get the previous state of some date after issuing commit method in entity bean (It should not use any offline storage )

    >
    Is there any way to get the state apart from using
    offline storage ?As I said the caller keeps a copy in memory.
    Naturally if it is no longer in memory then that is a problem.
    >
    and also what do you mean by auditlog?
    You keep track of every change to the database by keeping the old data. There are three ways:
    1. Each table has a version number/delete flag for each record. A record is never updated nor deleted. Instead a new record is created with a new version number and with the new data.
    2. Each table has a duplicate table which has all of the same columns. When the first table is modified the old data is moved to the duplicate table.
    3. A single table is used which has columns for 'table', 'field', 'data' and 'activity' (update, delete). When a change is made in any table then this table is updated. This is generally of limited useability due to the difficulty in recovering the data.
    All of the above can have a user id, timestamp, and/or additional information which is relevant to the data being changed.
    Note that ALL of this is persisted storage.
    I am not sure what this really has to do with "offline storage" unless you are using that term to refer to backed up data which is not readily available.

  • How to get the previous version of Flash professional?

    I need to install flash proffessional on 32 bit computer? How can I get the previous version as the Flash ProfessionalCC requires 64 bit?
    Many thanks for help.

    Hi Barbara,
    Flash Professional CS5.5 is a 32-bit application which can be installed on computers with either 32-bit or 64-bit operating systems.
    You can purchase this by Adobe's backward Licensing policy :
    " Adobe allows program members to order a current-version license but use a prior version. These members can contact Adobe Customer Service to request a serial number for the earlier version if they do not already have one. Prior-version software is available via ESD and can be purchased through standard resellers. The program member must follow all guidelines of the current-version EULA. "
    Please check the doc : http://www.adobe.com/volume-licensing/policies.html

  • How can I get the previous record's field value in a VO

    Hi I would like to know how can I get the previous record's field value in a VO
    For example : I have a VO porequisitionlinesvoimpl, and it contains 5 records (porequisitionlinesvoimpl.getRowCount() = 5). How can I search all records in the VO and get the field (attribute3) for all records?
    Many thanks anyone can help
    Lawrence

    Hi ,
    U can loop through the VO to get the value of attribute3,
    need to extend the controller ,use below code
    OAViewObject vo = (OAViewObject)oawebbean.getApplicationModule (VO1);
    OARow row = null;
    int fetchedRowCount = vo.getFetchedRowCount();
    RowSetIterator Iter = vo.createRowSetIterator("Iter");
    if (fetchedRowCount > 0)
    Iter .setRangeStart(0);
    Iter .setRangeSize(fetchedRowCount);
    for (int i = 0; i < fetchedRowCount; i++)
    row = (OARow)Iter .getRowAtRangeIndex(i);
    String value = (String)row.getAttribute("Atrribute3");
    Thanks
    Pratap

  • How can i get the previous version of iTunes back

    I have a MacBook with a DVD/CD drive, Mac OS X (10.7.5). I recently updated to iTunes version 12.0.1.26. It seems to be designed for Macs without a DVD/CD drive. How can I get the previous version back? I don't have a back up or use time machine.

    Thanks Chris, there a number of problems I'm experiencing. When I insert a CD, despite the preference being ticked, I nolonger get the box that asks me if I want to import. When I did manage to import I couldn't find where the file had gone. Perhaps what I need is a good user guide for the latest version of iTunes because at this point the impression I have is unless I'm buying from iTunes nothing seems to work as it previously did. It is impossible to add anything to my library.
    I'd be the first to admit I'm no computer nerd and all the information I've found so far to try and sort out my difficulties don't seem to work. Can someone please tell me where can I get a good user guide for iTune 12.0.1.26 because I find it far from intuitive? At least then I have a chance of working out if it's me or the machine.
    Many thanks in anticipation.

  • I made iOS7 update, a big mistake , such a ****, how can I get the previous version ?

      I made iOS7 update, a big mistake , such a ****, how can I get the previous version ?

    Sorry, but you cannot downgrade the iOS now.

  • HT1692 how can i get the previous contact details in iphone

    how can i get the previous contact details in iphone

    You don't want to maintain a reference to the last selected node, but to the last selected path. Nodes within a tree are addressed using a TreePath, with contains references to each node from the root, down to a specific node. Look at the JavaDocs of javax.swing.tree.TreePath for more info.
    Also, JTree has getter/setter methods for the selectionPath.

  • Is there any function module to get the variables used in a query?

    Hi experts
    Please, do you know if is there any function module to get the variables used in a query?
    Thanks and regards
    Luis

    Hi Srini
    Yes, I have checked the tables but I need a function module
    Thanks anyway!
    Luis

  • How to get the previous price of the  list price  in a order

    Hi All,
    I need to get the previous price of the condition type in an order  to calculate the %change of price.
    for ex: the conditon ZXXX has price 600 and its changed to 400 now .( by changing the quantity etc ).
    when the price value is changing to 400 , I need to capture  the value of 600 in another condition type.
    how can i acheive this ? Any idea?
    Please provide some pointers on it.
    Thanks in advance.
    Swapna.

    Hi Viraylab,
                     check  <b>VBAP-NETPR</b> field of table <b>VBAP</b>
    It gives the net price corresponding to a line item.
    Goto Tcode VA03.See the <b>item overview</b> tab U will get <b>Net Price</b> field for indivisual line item.
    Reward points if helpful.
    Regards,
    Hemant

  • How to get the previous record value in the current record plz help me...

    In my sql how to get the previous record value...
    in table i m having the field called Date i want find the difference b/w 2nd record date value with first record date... plz any one help me to know this i m waiting for ur reply....
    Thanx in Advance
    with regards
    kotresh

    First of this not hte mysql or database forum so don;t repeate again.
    to get diff between two date in mysql use date_format() to convert them to date if they r not date type
    then use - (minus)to get diff.

Maybe you are looking for

  • Getting a Square Root Result

    Does anyone have an clever ways to yield a square root result. I can use the ^ feature a business rule or calc script and it validates fine, but then I don't get a result ex: I can say 100^.5 and should get a value of 10, but no go.....anyone having

  • How can I get Adobe Media Gallery for Bridge CS3

    I want to create an online photo gallery for 3rd party client proofing. I am using a reference book byScott Kelby (the editor of 'Photshop User' magazine) and he refers to Adobe Media Gallery: ( Bridge CS3 / Windows / Workspace / Adobe Media Gallery)

  • Request for someone to enable "bootlogd"

    This is not a request for a package per say (hopefully it's simpler): What I am requesting is for someone to figure out how to enable a boot log file for Arch systems.  This means a recorded text file which contains all of the messages echoed to the

  • URGENT: Dreamweaver CS3 crashes while uploading any PHP File

    Hello, My Dreamweaver CS3 crashes everytime I try to upload any PHP file to the Web Server. It does upload the file but crashes and you received a "Not Responding" error in the Windows title bar. I did search alot on this issue until I found the ". D

  • How can I register a number with iMessage for my iPad2?

    I've got a 3G card with a mobile phone number. How can I register this number with iMessage?