MDX to get last Sunday and Saturday

I built a SSRS 2005 report on a SSAS 2005 cube. The report has start date and end date parameters from Time dimension. I need to set the default values to be last Sunday and last Saturday separately. (financial week is from Sunday to Saturday)
E.g.
Start date: [Time].[Day].&[20140309]
End date: [Time].[Day].&[20140315]
How can I do it dynamically? I mean for this week is above dates, but for next week, it should be 16 March, 22 March. I know how to do it in T-SQL, which will involve some calculation with system date, but MDX?

I created a data set in the report and it will have SQL query. This data set will generate the Week Start date and End Date. Use them as parameter default values. the parameter value you need to pass to the MDX query is going to be "[Time].[Day].&["
+ CStr(Format(Parameters!fromdate.Value, "yyyyMMdd")) + "]" and "[Time].[Day].&[" + CStr(Format(Parameters!enddate.Value, "yyyyMMdd")) + "]"
prajwal kumar potula

Similar Messages

  • Getting the data between Sunday and Saturday of last week.(DAYS NOT DATES)

    I have a stored procedure (that has no parameters right now) and does some extraction of data from different tables. One of the table has a column called 'DeliveryDate'.
    Based on the requirements, I have to create an SSRS 2008 R2 Report out of that stored procedure, so that users can see the data of last week from Sunday(Start DAY) to Saturday(End DAY). Even if it is Wednesday today, they should be able to see the data
    from Last Sunday to this Saturday. I don't want to get data of Monday, tuesday or wednesday. Also, these values shouldn't be STATIC. Meaning, if one user wanted to see deliveries on 04-15-2011, then he shoud see the values of the previous week (and NOT
    CURRENT week)
    1. Do I need to create parameters in my stored proc. Are they needed at all ?
    2. Should I use DateAdd, Datediff functions (If someone can explain, how will they be calculated!)

    to get last week sunday and saturday use below. I prefer to use parameters.
    set @startdate = DATEADD(wk,
    DATEDIFF(wk,
    0,
    getdate()),
    -2) --for
    sunday
    set @enddate = DATEADD(wk,
    -1,
    DATEADD(wk,
    DATEDIFF(wk,
    0,getdate()),
    -1))-- for saturday
    also
    refer the following link
    http://blog.sqlauthority.com/2008/08/29/sql-server-few-useful-datetime-functions-to-find-specific-dates/
    ESHANI. Please click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you
    If I run the query on 5/4/2014, will it give me 4/27/2014 for Sunday and 5/3/2014 for Saturday? Meaning if I run it on a Sunday, it will give me the previous Sunday and not the current Sunday's date.

  • How to get last row and sum of all columns in one query

    Hi ,
    is there a way to get last record for a column and sum of all record for another column in the same query.
    Best Regards ,

    You should define your requirements properly for volunteers to help here..
    Your data is not good enough to provide you accurate solution. Reason being you dont have a proper column which differentiates between first and last entry.
    The solution becomes easy based on your desgin.
    I have introduced a grouping column called "id" and a time column called "time_of_insert" (only this way you can confidently say that you can differentiate between first and last (also a fool proof solution) --- you may optionally use sequence(instead of date though if you say you may end up inserting two rows at the same time, then probably sequence would be a better choice to differentiate rather than a timestamp field) etc...)
    With your sample data something like this can be done to achieve your desired result.
    WITH dataset AS
            (SELECT 1 id,10 used, 8 remain,systimestamp+1/24 time_of_insert FROM DUAL
             UNION ALL
             SELECT 1 id, 1, 7,systimestamp+2/24 FROM DUAL
             UNION ALL
             SELECT 1 id,2, 5,systimestamp+3/24 FROM DUAL
             UNION ALL
             SELECT 1 id,1, 0,systimestamp+4/24 FROM DUAL
             UNION ALL
             SELECT 1 id,0, 0,systimestamp+5/24 FROM DUAL
             UNION ALL
             SELECT 1 id,1, 4,systimestamp+6/24 FROM DUAL)
    SELECT *
      FROM (SELECT SUM (used) OVER () sum_all,
                   FIRST_VALUE (remain)
                      OVER (PARTITION BY id ORDER BY time_of_insert DESC)
                      last_row
              FROM dataset)
    WHERE ROWNUM = 1;
    Output:
    SUM_ALL       LAST_ROW
    15                  4
    Cheers,
    Manik.

  • Get Last Sync and Last Full/Fast Optimization time of a Text Index

    Hi,
    How to get when a text index was last Sync and Last Full/Fast Optimization in oracle 10g and 11g
    - Nimish Garg

    Hi,
    to my knowledge Oracle will not keep this kind of data (I can not find any view in CTXSYS schema which gives this information. Depending on the method of synching there are some options:
    - If you used 'SYNC (ON COMMIT"), then the index is always synched and there is no date to be found
    - If you used 'Every "interval"', there is a job created (select idx_sync_jobname from ctx_user_indexes). You can find the last runtime of this job to get the last sync date
    - If you used 'MANUAL', then the Sync is up to you. You can query CTX_USER_PENDING for the index. In this table the records are recorded which need to be synced. So the lowest PND_TIMESTAMP will give you an idea, of the possible last sync date, it is before this timestamp.
    If you do it manual, you can of course keep your own table which records the date.
    Herald ten Dam
    http://htendam.wordpress.com

  • MDX to get last date MEMBER associated with a time LEVEL

    Hi there,
    I need to come up with a MDX calculation in my cube that takes an average 90 days forward from the last date member associated with whatever time level is being viewed in a time hierarchy.  Is this something anyone could help me with?  I can come
    up with code that is specific to a level (Year, Month, Week) but not one that is dynamic.
    Best,
    D

    I don't know exactly what you want from me.  I have a Time dimension with Year, Semester, Quarter, Month and Date.  I want to be able to get to the last date associated with a time member. So, for example, I would want to derive like this...
    October 31, 2014 would get to October 31, 2014
    October 2014 would get me to October 31, 2014
    Quarter 3 would get to to September 30, 2014
    Semester 2, 2014 would get me to December 31, 2014
    2014 would get me to  December 31, 2014

  • How to calculate  number of sundays and saturdays between two Dates

    friends i want to calculate how many Sundays come in two Dates
    i have tried following code which is hard coded i have to impliment method which can give me number of Sundays between two Dates
    please help me
    import java.util.Date;
         import java.text.DateFormat;
         import java.text.SimpleDateFormat;
         import java.util.Calendar ;
         import java.util.GregorianCalendar;
    public class DateDiffCalculator     {
         private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MMM-dd");
    public DateDiffCalculator()     {
         public static Date getDate (String date) throws Exception {
    //log.debug(" "+date);
              return SDF.parse(date);
    public static Date getDate (Date date) throws Exception {
    // log.debug("date is "+date);
              return getDate(SDF.format(date));
    public static long getDiffInDays(Date d1,Date d2)     {
         boolean isdiffGreaterThanYear=false;
         long diffInMilliSeconds=d1.getTime()-d2.getTime();
         return diffInMilliSeconds/(1000*60*60*24);
    public static int getYear(String date)     {
              //String[] day=     {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
              Integer     year=new     Integer(date.substring(0,4));
         return year.intValue();
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=1;
              if(m.equalsIgnoreCase("Feb"))     {
              month=2;
              if(m.equalsIgnoreCase("Mar"))     {
              month=3;
              if(m.equalsIgnoreCase("Apr"))     {
              month=4;
              if(m.equalsIgnoreCase("May"))     {
              month=5;
              if(m.equalsIgnoreCase("Jun"))     {
              month=6;
              if(m.equalsIgnoreCase("Jul"))     {
              month=7;
              if(m.equalsIgnoreCase("Aug"))     {
              month=8;
              if(m.equalsIgnoreCase("Sep"))     {
              month=9;
              if(m.equalsIgnoreCase("Oct"))     {
              month=10;
              if(m.equalsIgnoreCase("Nov"))     {
              month=11;
              if(m.equalsIgnoreCase("Dec"))     {
              month=12;
              return month;
         public static int getDay(String date)     {
              Integer     day=new     Integer(date.substring(9,11));
         return day.intValue();
    public static int getNumberofSundays(String d1,String d2) throws Exception     {
              //d1 is leave start date d2 is leave end date
              // get object in Date form
                   Date date1=getDate(d1);
                   Date date2=getDate(d2);
              // now get calender objects from it
              GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay(d1));
              GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay(d2));
              // get period
              long leavePeriod = getDiffInDays(date1,date2);
         return 12; // it should return number of sundays but we type 12 to perform compilation
    public static void main(String[] arg)throws Exception     {
    System.out.println(" "+getNumberofSundays("2005-Oct-07","2006-Mar-01"));
    }

    thanks now i have modified the get Month Code
    as follows
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=0;
              if(m.equalsIgnoreCase("Feb"))     {
              month=1;
              if(m.equalsIgnoreCase("Mar"))     {
              month=2;
              if(m.equalsIgnoreCase("Apr"))     {
              month=3;
              if(m.equalsIgnoreCase("May"))     {
              month=4;
              if(m.equalsIgnoreCase("Jun"))     {
              month=5;
              if(m.equalsIgnoreCase("Jul"))     {
              month=6;
              if(m.equalsIgnoreCase("Aug"))     {
              month=7;
              if(m.equalsIgnoreCase("Sep"))     {
              month=8;
              if(m.equalsIgnoreCase("Oct"))     {
              month=9;
              if(m.equalsIgnoreCase("Nov"))     {
              month=10;
              if(m.equalsIgnoreCase("Dec"))     {
              month=11;
              return month;
    but question remains same how to calculate number of Sundays Between 2 Dates

  • Retreive Sunday to Saturday Week records

    Hi Friends,
    I am using Oracle 10.1 version. I have a requirement to retrieve records for week spanning sunday to saturday from the sales table.
    I have to execute this query on sunday, if the production job fails for some reason, i need to execute the job on a monday / tuesday.
    Is it possible to retrieve the records for the last week?
    Example
    Sunday Saturday Sunday
    04/25/2010 05/01/2010 05/02/2010
    if the jobs fails on sunday, i need to execute the job on 05/03, then the query should retrieve only 04/25 till the date reaches 05/08/2010. Since it completes the week span.
    i researched the forum and i found the below query to retrieve the records spanning week time.
    WHERE     some_date     >= TRUNC (SYSDATE + 1, 'IW') - 15
    AND     some_date     < TRUNC (SYSDATE + 1, 'IW') - 8
    How should i be able to modify this query to retrieve the record for a week span time.

    Hi,
    The formula you found is a good way to get the Sunday-to-Saturday week that was 2 weeks ago. If you want last week, then just add 7 days to the expressions to which you are comparing some_date:
    WHERE   some_date >= TRUNC (SYSDATE + 1, 'IW') - 8
    AND      some_date <  TRUNC (SYSDATE + 1, 'IW') - 1When run any time from Sunday, May 2 through Saturday, May 8, the condition above looks for some_date between Sunday, April 25 and Saturday, May 1, inclusive.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data if the query is run on a couple of different dates. (For example: "If I run this one Saturday, May 8, then the output should be ..., but if I run it on Sunday, May 9, then I want ...".)

  • How can i schedule a list of Interfaces which will run only on last sunday of every month ..

    Hi Can any one help me for achieving this scenario...
    Thanks in Advance..

    Hi
    Make scenario for every interface and when expand the scenario there is option is scheduling.
    In Scheduling ---> Execution option ----> select month(Week day)---> monthly date= Last & Sunday and schedule the time accordingly .
    Let me know
    Thanks

  • Get the first and the last date of a week

    Hi all
    I need to get the first and the last date of a specific week.
    I need a function that returns two date passing it just one date.
    The function has to calculate the first and the last date of the week of the argument date.
    hope to be clear
    regards

    goiters,
    I need to get the first and the last date of a specific week.Yup, and what's the first day of the week in your part of the world, is it Sunday or Monday?
    I need a function that returns two date passing it just one date.No you don't, just add 7 days to the start of the week.
    hope to be clearWell, you can hope.
    Keith.
    Message was edited by: corlettk - now I hope to clear ;-)

  • I had 41 tabs open in about six groups over the last year and a half and I just close them and exited Firefox. Is there any way to get them back?

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/856718]]</blockquote>
    I had 41 tabs open in about six groups over the last year and a half and I just close them and exited Firefox. Is there any way to get them back?
    Also, is there any way to save a group or an open session and then restore it later?

    History menu, if it was destroyed in the last session
    then use "Restore Previous session:" and then restore all windows also from the history menu.
    If done in this session try the restore all windows under the history menu.

  • Please help to get onhand stock report with last purchase and billed date warehouse and item wise

    please help to get onhand stock report with last purchase and billed date warehouse and item wise

    Hi Rajeesh Ambadi...
    Try This
    SELECT distinct T0.ITEMCODE , t1.ItemName, T0.ONHAND as 'Total Qty',  
      T1.LASTPURDAT ,t1.LastPurPrc
    FROM OITW T0 INNER JOIN OITM T1 ON T0.ITEMCODE = T1.ITEMCODE
    INNER JOIN OITB T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD left join ibt1 t3 on t3.itemcode = t0.itemcode and t3.whscode = t0.whscode
    WHERE
    T0.ONHAND>0
    AND T0.WhsCode ='[%0]'
    Hope Helpful
    Regards
    Kennedy

  • My iPhone was stolen last night and I'm trying to recover all my photos from that phone and get them on my mac laptop. The iCloud photo stream only imported 1,000 photos from my stolen phone. How can I retrieve all of my other photos?

    my iPhone was stolen last night and I'm trying to recover all my photos from that phone and get them on my mac laptop. The iCloud photo stream only imported 1,000 photos from my stolen phone. How can I retrieve all of my other photos?

    You have to reset the device to Factory Settings in order to restore it from an iCloud backup. You probably want to back it up as is before you do this.
    To do the reset after you have backed up the current device, go to Settings>Reset>Reset all Content & Settings. This will erase the device. If you are signed onto iCloud with Find My iPhone turned on, go to Settings>iCloud and scroll to the bottom to sign out of iCloud before you do the reset.
    Once you have reset your device, you will set it up like a new phone. When it asks if you want to restore it from an iCloud backup, select the backup you want to restore it from.
    Cheers,
    GB

  • Getting the error message"your apple ID has been disabled" . I reset my ID password last night and am still having the same issue.

    getting the error message"your apple ID has been disabled" . I reset my ID password last night and am still having the same issue.

    If you are still unable to access your account after resetting your password, you will need to contact iTunes Store Customer Support via http://www.apple.com/support/itunes/contact/

  • How to get last modified date and time of a file which is in apache server.

    Hi ,
    I need to get last modified date and time of a file in remote machine.
    This file is in remote machine which has apache server installed.
    I am trying to get this information by connecting to apache server from client by giving absolute URI of the file to file object.
    URI is got from apache server URL by using toURI method.
    when I use lastModified method , its throwing exception , because scheme of URI is not file.
    I can't give scheme as file because ftp server is not installed on that server
    Is there any other way to get this information .

    No, unless you can use an FTP client.

  • Films downloaded won't play.I just get a black screen. My computer crashed last week and I had to do a 'total recovery' - an important link is missing... anyone any idea what it could be? I have updated iTunes and Quick Player

    Films that I have downloaded from iTunes won't play. I just get a black screen. My computer crashed last week and I had to do a Total Recovery - Films played perfectly before this. I must have deleted a program or link.............. anyone know what could be missing? I can play YouTube videos etc. but nothing in the iTunes store - films or trailers won't work.

    The movie is from iTunes.   You would think that a download from iTunes to a MacBook could be watched on an HDTV using Apple TV without any headaches bit this does not appear to be the case. 

Maybe you are looking for