Current Year & Prior Month

Hello experts.  I tried a bunch of things, but I can't seem to get it right.  I want to get the format of my date like this: yyMM
and have MM be the prior month.
So, for 03/06/2015, I'd like to get this '1502'
How can I do that?
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

>>  I want to get the format of my date like this: yyMM .. So, for 03/06/2015, [gee, is that '2015-03-06' or '2015-06-03'?? ] I'd like to get this '1502' <<
Why did you pick the worst possible local dialect for your display in the presentation layers? Google some articles on temporal data. This is more than SQL. 
Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
The report period table gives a name to a range of dates that is common to the entire enterprise. 
CREATE TABLE Something_Report_Periods
(something_report_name CHAR(10) NOT NULL PRIMARY KEY
   CHECK (something_report_name LIKE <pattern>),
 something_report_start_date DATE NOT NULL,
 something_report_end_date DATE NOT NULL,
  CONSTRAINT date_ordering
    CHECK (something_report_start_date <= something_report_end_date),
etc);
These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Creating charts that represent current year in Months in order to show YTD performance by month

    I continue to struggle with what, to me, seem to be the simplest things in SSRS.  I have spent over two days trying desperately to get a chart to properly show the quantities of Manufacturing Orders that we have made each month, Year To Date. 
    Below is the closest I’ve been able to come and the axis is still off by one month and not in sync at all with my data. 
    Then when I run the report for other part numbers, that only have MO’s in say two months (Jan & Jun), they don’t even behave scalar and I get the following screwed up mess.  Notice the two columns have decided to fill most of the scale and they
    did not skip the four months between Jan and Jun and they also are completely out of sync with my scalar x-axis!
    My goal is to create a chart that can be run for any part number on any day and show how many times it has been built during the current calender year.  Chart should always show months of current year starting Jan on left and ending with Dec on
    right (even if I am running report in February for example).  Then for each month that we have data, it should show the QTY on the column chart and leave blank columns for months with no data.
    Can anyone help me with this? 
    Chris

    Hi Chirs,
    From your desription, you want to createa a chart to show all the months on the chart no matter it has data on that month or not, rigth? If in this case, we can create an other dataset to show all the month, and then use the lookup function to get the month
    QTY. The steps below are for you reference.
    Create an other dataset use the query below.
    DECLARE @TMP TABLE (Month nvarchar(20),QTY INT)
    INSERT @TMP SELECT 'Jan',0
    INSERT @TMP SELECT 'Feb',0
    INSERT @TMP SELECT 'Mar',0
    INSERT @TMP SELECT 'Apr',0
    INSERT @TMP SELECT 'Mat',0
    INSERT @TMP SELECT 'Jun',0
    INSERT @TMP SELECT 'Jul',0
    INSERT @TMP SELECT 'Aug',0
    INSERT @TMP SELECT 'Sep',0
    INSERT @TMP SELECT 'Oct',0
    INSERT @TMP SELECT 'Nov',0
    INSERT @TMP SELECT 'Dec',0
    SELECT * FROM @TMP
    Drag [Month] filed to Category Groups and drag [QTY] field to Values.
    Then change the of [QTY] to:
    =Lookup(Fields!Month.Value,Fields!Month.Value,Fields!QTY.Value,"DataSet1")
    The report looks liek below.
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • How to display Current Year and Month in Drop Down list

    Hi Dear friends,
    I am devloping a report. It has got 2 pages--input and output(Report) page.
    IN input page, user will select Month and Year from drop down list as one of the input parameters. (seperate drop down list 4 month and year)
    Now, my problem is:
    HOw to display current month and year by default in the dropdown list...........
    I hope my question is clear.
    Please help.
    Regards,
    ASh

    NO da,
    it is not working.
    First i tired with for-loop. I initialized variable "i" to -2 (i=-2) I would get the year drop down list from 2003 but, by default 2003 would come.
    So, i posted the question.
    I tried your code. It is giving following error.
    A Servlet Exception Has Occurred
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occured between lines: 122 and 127 in the jsp file: /test/inpt.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\general\test\inpt$jsp.java:182: Invalid type expression.
    first.set(Calendar.YEAR, 2003)
    ^
    An error occured between lines: 127 and 131 in the jsp file: /test/inpt.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\general\test\inpt$jsp.java:186: Invalid declaration.
    out.write("\r\n \r\nYear : \r\n \r\n"); ^ An error occured between lines: 198 and 203 in the jsp file: /test/inpt.jsp Generated servlet error: C:\Program Files\Apache Tomcat 4.0\work\localhost\general\test\inpt$jsp.java:282: Invalid type expression. first1.set(Calendar.YEAR, 2003) ^ An error occured between lines: 203 and 207 in the jsp file: /test/inpt.jsp Generated servlet error: C:\Program Files\Apache Tomcat 4.0\work\localhost\general\test\inpt$jsp.java:286: Invalid declaration. out.write("\r\n \r\nYear :\r\n \r\n");
    ^
    4 errors
    Pls. Help.
    Regards,
    Ashu

  • Infpackage with logical file name having current year and month

    Hello all,
    I am using the FILE transaction to maintain the logical file name for infopackage loads in BW.This logicalfile name is to be assigned to physical csv file in AL11 directory.
    This csv  file would be having the current month and date at the end of the name for e.g for the month of April 2008,the file name would be say xx_200804.csv.I wanted to know if by using the palceholder  <YEAR><MONTH> in the physical file name ,would the current month date and month be automatically concatenated at the end of file name ?Has anyone used this option before?

    yes it does work,i tried out finally and the system picks current month and year

  • YTD, MTD, Prior Year, Prior Month calculations in SAP BW Universe

    I am finding the SAP BW based universe a totally different animal so far and my question comes from my inexperience in this domain.
    In a normal universe, one can use CASE Statement and Calendar or Time table to help do these calculations. Since BW based universes are based on a super BEx query, how are these calculations done in the universe? Are these calculations done in the BEx query itself?
    Are there any standards of what should be handled on the BEx side vs. what should be handled on the Universe side?
    Also, what's the syntax of a CASE statment or using Substring (or similar function) in a BW universe?
    Thanks!

    Hi,
    You can define calculated measures in OLAP universes using MDX language.
    To define a Calculated Measure, users must create manually new Measures in the Universe.
    Calculated Measures definitions are using MDX functions embedded in XML tags.
    In order to create calculated measures, users must to create pure MDX expression emclosed in XML tags: <EXPRESSION></EXPRESSION>
    In this new expression, we authorize to use any Designer function such as:
    u2022     @SELECT
    u2022     @PROMPT
    u2022     @VARIABLE
    The check integrity will validate the XML syntax and any of the Designer functions described above.
    No MDX parser is provided in this version of Universe Designer.
    This paragraph describes how to define calculated measures in MDX and using @Select and @Prompt functions.
    CASE statement is not supported in MDX but you can use IIF statement instead of.
    It is important to notice that the result of a calculated measure/member in SAP BW (using MDX) must be numeric due to a current limitation f the SAP MDX engine.
    Here is 2 samples of an MDX expression using YTD:
        <EXPRESSION>
    SUM(YTD(@Select(Key Figures\Billed Quantity
    </EXPRESSION>
        <EXPRESSION>
    SUM(YTD([Measures].[D3B1M57O3MN5499LF2X9UNHKA]))
    </EXPRESSION>
    Regards,
    Didier

  • How to get current fiscal year/quarter/month/week

    Post Author: [email protected]
    CA Forum: Semantic Layer and Data Connectivity
    Hi friends,
    I have to calculate
    1. current year/quarter/month/week.
    2.Previous year/quarter/month/week.
    please tell the process to achieve the above scenerio's.
    the structure of the fiscal_cal is as  follows.
    Name                                      Null?    Type
    TODAY                                     NOT NULL DATE
    FISCAL_DAY                                         NUMBER(8)
    FISCAL_WEEK                                        NUMBER(6)
    FISCAL_MONTH                                       NUMBER(6)
    FISCAL_QTR                                         CHAR(18)
    FISCAL_YEAR                                        NUMBER(4)
    FISCAL_MONTH_WORK_DAYS                             NUMBER(2)
    sample week data is as follows
    FISCAL_WEEK
         200752
         200753
         209901
    Thanks.

    based on ur target database DBMS you can find a built-in functions be used in the universe designer to get the requirment you talked about, like in oracle
    to_char(mydate,'yyyy') it will return the year in the yyyy format.
    and the same way for the other things you want
    to_char(mydate,'q') return the quarter.
    w return the week of the month
    ww return the week of the year
    mm return the month
    ,, to get the last year
    you can use also a builtin functions
    like add_months(mydate,-12) that return the same date for the last year, and you can do the same operations as before.
    its all related to the DBMS.
    good luck

  • Macro issue: Current Year and Current Year +2

    Hi Macro experts
    I have a view in monthly buckets. I like to copy values for one KF to another from current year to only Current year + 2. I have made following macro but it dosen't work:
    AT: Initiate Input Row 
    Copy Sales FC to Al FC Input Y+2 : ( 24 Iterations :  M 03.2009 ;  M 02.2011 )
    IF
    Check year
    YEAR( DATE(
    Row: Customer Forecast ( Frm  M 03.2009 )
    =
    (YEAR( DATE( TODAY ) )
    +
    2
    Row: Annual Target Input ( Frm  M 03.2009 ) =
    Row: Sales Forecast ( Frm  M 03.2009 )
    ENDIF
    I get following message when I do the check:
    Fehlerhafter logischer Ausdruck "(YEAR(  4D4HPL3ENNRMKCXE1NULTI4LX  )  +  2  )":
    Please help (If there is an easier way to make the macro please let me know)
    Thanks
    Sun

    Hi
    Thanks for the answer. It is a rolling period dataview.  I understand you suggest the macro as:
    AT: Initiate Input Row 
    Copy Sales FC to Annual FC Input Y+2 : ( 24 Iterations :  M 03.2009 ;  M 02.2015 )
    Row: Annual Target Input ( Frm  M 03.2011 ) =
    Row: Sales Forecast ( Frm  M 03.2009 )
    But the problem is that when it is rolling period it will then also copy values in current year+3 and that is not acceptable. That is why I canu2019t use this macro. Values in current year (jan. month to dec. 2009) to (jan. month to dec. 2011)
    Br
    Sun

  • Current year Previous Year in Query

    Hi,
    I have to get the results of current year 12 months( 12 columns) previous year 12 month( 12 columns) in one report.
    Once the user gives the current year , how to automatically populate the previous year. The PY varaint can be used for all months of previous year.
    Any thoughts on this, please let me know.

    As venkat said , using offset is the best option, rather than jumping directly to custom exit variable.
    for e.g.
    you report display is
    net qty.............net qty
    current year......  previous year........
    bil1
    bil2
    so u intend to see the net quantity for current year and previous year.
    Bring net qty... in Columns in query designer.
    Now right click and hit Edit
    Now bring in time chara. that u wish to use and want to create variable for.................
    for e.g. say fiscal period....
    Now hit fiscal period with right click andhit  Restrict.
    Go for Interval variable if already exist or else create a new one.
    hit okey..
    now in query designer in columns copy ur net quantity
    now paste there again.
    in Second net quantity u can hit edit.
    now where fiscal period is there hit restrict
    in dialog box hit Select offset.
    As ur intention is for previous year, keep the offset value as -12
    also restrict fiscal year variant in selection.....
    hit okey
    test it...
    if this doesnot work
    then go for custom exit....

  • SSRS Matrix report. Variance expression by Month. Need to compare month from prior year to current month of current year VS2010

    Please help.  I have a matrix report.  In the report I have row group  PO Type.  One the Column groups I have a parent group by Fiscal Year, and then a child group by Month.  When I run the report, I get two years of data back broken
    out by month.  Please see below.
    Now here is where I am getting stuck.  I need to take the variance between the current month of the current year, from the same month of the prior year.  So I need to show the difference between Oct , 2014 from Oct, 2013. November, 2014 from November
    2013... etc. etc.
    In the example below, how do I create a column or row showing the variance for Contracts for October 2014.  I need to take the contracts for October 2014 which is 3 and subtract that from October 2013 which is 8.  Any suggestions? How do I do that
    for each month?  Then I need to do it for the quarter... then the year?  But I'll be happy if I can just get the month working first.
    Any help will be appreciated. 
    here is what my rdl file looks like.
    Here is what my report looks like when I render it.

    Hi Adrian_s2012,
    According to your description, you want to compare values for the month of current year with the month of prior year and get the variance. Right?
    In Reporting Services, we don't have any function to get this "Year to Year" Growth. In this scenario, if you data source is a cube, we suggest you use Analysis Services to achieve your requirement. If this data source is just from database, it will be hardly
    to calculate the variance because we need to compare the values within every two different column group and matrix generate adjacent columns one by one. Even we make it by using custom, every time executing the long code when generating result
    in a cell will reduce a lot of performance, we really don't suggest to do that in SSRS. Here is a thread with much easier requirement, please take a reference of that:
    http://social.msdn.microsoft.com/Forums/office/en-US/842e2dcb-d949-4297-9d91-eac989692cb5/difference-between-the-grouped-column?forum=sqlreportingservices
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • MDX to dynamically create period to date for each month of current year

    I need some help with MDX. I am not even sure if this is possible to do but here is what I need.  Any help is greatly appreciated.
    I have a Date dimension with a hierarchy defined as Year-Qtr-Month-Date
    I have a measure called Rentals
    Assume the current date is 10/24/2014.  I want to display by month for the year 2014, the sum of rentals equivalent to the current MTD.  So January would sum 1/1 thru 1/24.  February would sum 2/1 thru 2/24.  March would sum 3/1 thru
    3/24, etc.
    On the end of the current month, all months would display the sum of the whole month. I am not concerned if a month ends on the 30th or 31st.  The end is end.
    It needs to be dynamic enough so that if the current date is the 27th, each month would sum from the 1st to the 27th.

    Hi Rocko,
    According to your description, you want to compare the sum amount of rentals for each month, right?
    In MDX, we can use
    PARALLELPERIOD function returns a member from a prior period in the same relative position as a specified member. So you can use the query like
    with set Period as {[Arrival Date].[Date].[Month].&[2014]&[1]:[Arrival Date].[Date].[Month].&[2014]&[27]}
    member [Arrival Date].[Date].[0] as sum({Period})
    member [Total Amount N-1] as (PARALLELPERIOD([Arrival Date].[Date].[Month], 1, [Arrival Date].[Date].[Year].&[11]), [Measures].[Total Amount])
    Here is a sample query on AdventureWorks cube.
    SELECT ParallelPeriod ([Date].[Calendar].[Calendar Semester]
    , 3
    , [Date].[Calendar].[Month].[October 2003])
    ON 0
    FROM [Adventure Works]
    Regads,
    Charlie Liao
    TechNet Community Support

  • Current Month, Current Year Variable on Posting Date

    Hi,
    I need to construct a BEx variable that will return the Current Month of the Current Year based on Posting Date. I want to be able to compare Current Month of the Current Year with Current Month of the Prior Year. I know SAP delivers variables for this based on 0CALMONTH. Is there any way to create the variable off Posting Date without having to write a customer exit?
    Thanks,
    C

    I guess you could use replacement path variables for the same. No need to write customer exits.
    Create 2 variables, one on calmonth and the other on calyear.
    Variable on Calmonth -
    type - replacement path.
    Replacement path tab - repace with variable, give variable name into which user enters the posting date, replace with key, offset start 2 and offset length 2.
    Variable on calyear -
    type - replacement path.
    Replacement path tab - repace with variable, give variable name into which user enters the posting date, replace with key, offset start 4 and offset length 4.
    to get key figures for current month and previous year, restrict the key figure with calmonth variable created above and use offset on the calyear variable created above, like zcalyear - 1.

  • Calculating prior months using off-set and crossing to prev year

    Gurus,
    I am getting current month period based on user entered value and calculating prior month by off-setting current month by 1.
    it works fine when current month value is greater than 1. If it is 1, prior month does get evaluated as 12 of previous year.
    Example...
    If Current period is - Feb, 2008 (02/2008). previous period comes fine as Jan, 2008.
    If current period is Jan, 2008 (01/2008) perious period is unknown. (I want it to be 12/2007).
    is there way to handle this without too much coding etc?
    Regards,
    -SM

    Mayank,
    What is SAP variable for Fical Year/Period, which will have both month and year value? (I guess I need to Fiscal posting period rather than Cal month?)
    Also what is SAP variable for Quarter/Year? I need to off-set of quarter also.
    Thanks, -SM

  • Expression - First date and last date of current month, current year

    Hi
    I need to have 2 ssrs expression as I can use  as default parameters in my report where I can -  out from my Time dimension, get the
    first date of the current, current year - and one where I get last date, current month, current year.
    My data source is a SSAS cube and my timedimension is structured like this:
    [Time].[Days].&[2009-01-16T00:00:00]
    Any suggestions how to solve this ?

    Hi ,
    You can use below in Default Values in ssrs ;
    for first Day of current month and year
    ="[Time].[Days].&[" +Format(dateadd("m",0,dateserial(year(Today),month(Today),1)), "yyyy-MM-dd")+"T00:00:00]"
    output will be ;
    [Time].[Days].&[2014-09-01T00:00:00]
    For last day of current month and year
    ="[Time].[Days].&[" +Format(DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1), "yyyy-MM-dd")+"T00:00:00]"
    output will be ;
    [Time].[Days].&[2014-09-30T00:00:00]
    Please correct me if I misunderstood your requirement.
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem.

  • Current Year and current month?simple question

    How can i get four Digit current Year and two digit current month. So if is march it should get me as 03 and the Year as 2002. Please do help me, is a simple question isn't it ?. Thanks for your earliest response.
    Thank you.

    i have a directory structre of the format
    REPTS2000209/E200209-98000001
    in which 2002 is current YEAR
    09 is current month
    and 9800001 is the code i would submit(list box) from a form
    so what i need is a program that can generate the above path and open that particular PDF file
    so basically E200209-98000001.pdf is the PDF file.
    i am submitting it from JSP page. PLEASE HELP ME how can i program.

  • MDX calculation based on date logic for the Jan 1 of current year through the 15th of the previous month

    Hello, 
    We need some help with an SSAS MDX query based on date logic. One of the problems is that I don't have access to the Cube but have been given a query example with the logic needed for the calculation. Here's the scenario; 
    The ETL process will run on the first Tuesday after the 15<sup>th</sup> of a given month. The Analysis Cube data queried should include the current year up to the end of the previous month. For example, on May 19<sup>th</sup>
    (the first Tuesday on or after the 15th) the query should include data from January 1<sup>st</sup> through April 30<sup>th</sup>.
    The 15<sup>th</sup> of the month is not part of the query, it is a factor in when the query is run. The query will always be in terms of complete months.
    SELECT
                    NON EMPTY { [Measures].[Revenue Amount],
                    [Measures].[Utilization],
                    [Measures].[AVG Revenue Rate],
                    [Measures].[Actual Hours] }
    ON
                    COLUMNS,
                    NON EMPTY { ([dimConsultant].[User Id TT].[User Id TT].ALLMEMBERS * [dimConsultant].[Full Name].[Full Name].ALLMEMBERS * [dimConsultant].[Employee
    Type].[Employee Type].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION,
                    MEMBER_UNIQUE_NAME
    ON
                    ROWS
    FROM
                    ( SELECT
    ( { [dimDate].[Week Date].[1/4/2015], [dimDate].[Week Date].[1/11/2015], [dimDate].[Week Date].[1/18/2015], [dimDate].[Week Date].[1/25/2015], [dimDate].[Week Date].[2/1/2015] } )
                    ON
                                    COLUMNS
                    FROM
                                    ( SELECT
    ( { [dimIsBillable].[Is Billable].&[True] } )
                                    ON
    COLUMNS
                                    FROM
    [SSASRBA]
    WHERE
                    ( [dimIsBillable].[Is Billable].&[True], [dimDate].[Week Date].CurrentMember ) CELL PROPERTIES VALUE,
                    BACK_COLOR,
                    FORE_COLOR,
                    FORMATTED_VALUE,
                    FORMAT_STRING,
                    FONT_NAME,
                    FONT_SIZE,
                    FONT_FLAGS

    Hi Hans,
    Thank you for your question.  
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.  
    Thank you for your understanding and support. 
    Regards,
    Simon Hou
    TechNet Community Support

Maybe you are looking for