Calculating Vacation Days using a query

Hi everyone. I have an issue with the following query provided by Pollywog. He did a great job on it however there is a bit of a problem in the way it operates. What it does is calculate the number of days for this year excluding saturday and sunday. It also has a cutoff date, July 1st. This is where the problem lies.
Currently if the user chooses a vacation day that includes the cut off date. So from june 30th to july 5th it doesn't bundles it together and calculates it into the next year total. So if you have a vacation from June 15th to July 2nd it all goes into your next year's vacation days.
What I want is to have this year's vacation days be calculated into this year and next year to be calculated into next year. So if you have the June 15th to July 2nd vacation it would add 11 days to This year's total and 2 days to next year's total.
WITH t AS (  SELECT id,
                    MAX (strt) strt,
                    MAX (finish) finish,
                    SUM (dys) days_off
               FROM (SELECT id,
                            strt,
                            finish,
                            CASE
                               WHEN TO_CHAR (dy, 'day') LIKE 'saturday%' THEN 0
                               WHEN TO_CHAR (dy, 'day') LIKE 'sunday%' THEN 0
                               ELSE 1
                            END
                               dys
                       FROM vacations
                     MODEL
                        PARTITION BY (ID id)
                        DIMENSION BY (0 d)
                        MEASURES (POCETAK strt, KRAJ finish, POCETAK dy)
                        RULES
                           (dy [FOR d FROM 1 TO finish[0] - strt[0] INCREMENT 1] =
                                 (NVL (dy[CV () - 1], dy[CV ()]) + 1)))
           GROUP BY id
           ORDER BY id)
SELECT t.id,
       t.strt,
       t.finish,
       t.days_off,
       vacations.korisnik,
       SUM (
          CASE
             WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off
             ELSE 0
          END)
       OVER (PARTITION BY vacations.korisnik ORDER BY t.id)
          this_years_running_total,
       SUM (
          CASE
             WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off
             ELSE 0
          END)
       OVER (PARTITION BY vacations.korisnik)
          this_years_grand_total,
       SUM (
          CASE
             WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy')
             THEN
                days_off
             ELSE
                0
          END)
       OVER (PARTITION BY vacations.korisnik ORDER BY t.id)
          next_years_running_total,
       SUM (
          CASE
             WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy')
             THEN
                days_off
             ELSE
                0
          END)
       OVER (PARTITION BY vacations.korisnik)
          next_years_grand_total
  FROM t, vacations
WHERE t.id = vacations.idLooking forward to any ideas you can offer

hi,
You need to write a code to get the key figure and characterstics value.
First step is to defined the structure of all the field that you want to read.
This table I_AXIS_DATA will contain the characterstics.
This table I_CELL_DATA will contain the keyfigure.
Please find the code.
            READ TABLE I_AXIS_DATA INTO WA_AXIS_DATA WITH KEY AXIS = '001' .
            IF SY-SUBRC = 0.
              LOOP AT WA_AXIS_DATA-SET INTO WA_SET.
                    INDEX = INDEX + 1.
                    IF WA_SET-CHANM = 'infoobject name'.
                      WA_ROW_COL-fields = WA_SET-CHAVL_EXT .
                    ENDIF.
                    IF WA_SET-CHANM = 'infoobject name'.
                      WA_ROW_COL-field2 = WA_SET-CHAVL_EXT.
                    ENDIF.
              ENDLOOP.
            ENDIF.
******* POPULATE COLUMNS AGAINST ROWS
            CLEAR WA_ROW_COL.
            V_COUNT = 1.
            INDEX = 1.
            LOOP AT IT_ROW_COL INTO WA_ROW_COL.
              WHILE ( V_COUNT <= V_NUMOFKEYF ).
                    READ TABLE I_CELL_DATA INTO WA_CELL_DATA INDEX INDEX.
                    IF V_COUNT = 1.
                      WA_ROW_COL-keyfigure = WA_CELL_DATA-FORMATTED_VALUE.
                    ENDIF.
                    V_COUNT = V_COUNT + 1.
                    INDEX = INDEX + 1.
                    CLEAR WA_CELL_DATA.
              ENDWHILE.
              APPEND WA_ROW_COL TO IT_R_C_H.
              V_COUNT = 1.
Hope this is helpful.
Thanks,
Saveen Kumar

Similar Messages

  • Find current age from day in mdx query

    Hi,
    I need to find current age.In my cube i have dob attribute.
    so how can  i find current age from day using mdx query.
    Thanks,
    Indu
    indu

    Hi,
    when i ran above query, i am getting days.
    But i need current age in years.
    so i tried with below query, then i am getting value  like 8.99.how can i round off in mdx query?
    in sql i used Floor function for roundoff. in mdx which function should i use?
    With
    MEMBER [DOB] AS DATEDIFF('d',[Ship Date].[Date].CurrentMember.Name,Now())/365.25
    Select {[DOB]}
    on columns ,
    NON
    EMPTY {[Ship Date].[Date].[Date]}
    ON ROWS From [Adventure Works]
    indu

  • How to use a calculated column in the same query

    Hi All,
    I need some help with using a calculated column in the same query.
    For eq
    I am joining a couple of tables and some of the select columns are calculated based on the columns of the tables and i want a new column in the same query to use this calculated feild in some other calcualtion.
    something like this...
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    Thanks

    user548171 wrote:
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    ThanksWhat about just repeating the column values:
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( (12+3) / (12-3)  * 100  > 0 )  THEN 'Yes' ELSE 'No'  END FROM DUAL

  • Using a "Sum" Calculated Field on a "Count" query column?

    Here's my query using the Query Report Builder:
    SELECT Col1, COUNT(Col1) AS Count_Column
    FROM Table
    GROUP BY Col1
    It generates a report that lists all the values of column
    "Col1" and how many times each value was used in Col1
    For instance, if Col1 contained the value 'A' 12 times, 'B' 6
    times, and 'C' 19 times, the report would generate this:
    A - 12
    B - 6
    C - 19
    What i need as a column footer is the total count of all the
    values, which in this case 12+6+19=37
    I am using a calculated field, setting the data type to
    Double, the calcuation to Sum, and the perform calculation on to
    'query.Count_Column'. Reset Field When is set to None.
    When I run the report, it doubles the last number in the
    report's Count column (19) and displays 38 on the page. I tested
    this with another column and it doubled the last number in the
    report as well.
    How can I get it to properly Sum my Count_Column?

    Hi,
    You need to check note 208366.1 which explains why totals can be blank. Without knowing the detail of you decode function it is hard to say what needs to be changed. Try putting a sum in front of the decode e.g.
    sum(decode(period, 'Jan period', value, 0))
    Hope that helps,
    Rod West

  • Calculating Average Days in Crystal Reports using a Visual FoxPro driver

    Post Author: sher
    CA Forum: Crystal Reports
    I use the following code in a crystal XI report to calculate average days between two dates using the sql server driver.  It worked fine.  I used the same code in a crystal XI program using a visual FoxPro driver.  It does not work.  Can someone help me with code needed to calculate average days using a visual foxpro driver?
    cast ( Avg( DateDiff( DD, CREDENTIALING.APPLICATION_RECEIVED, ENTITYASSIGNMENTS.STATUSASOF )) As int ) AS AvgDaysFromReceipt,
    cast ( Sum( DateDiff( DD,CREDENTIALING.APPLICATION_RECEIVED, ENTITYASSIGNMENTS.STATUSASOF)) As int )  AS TotDaysFromReceipt

    Not sure if this is any simpler but you could save this as a custom function, that way you will have to modify it once a year for the holidays.
    numbervar days;
    datevar date1 := minimum({?My Parameter});
    datevar date2 := maximum({?My Parameter});
    days := DateDiff ("d", date1, date2) -
    DateDiff ("ww", date1, date2, crSaturday) -
    DateDiff ("ww", date1, date2, crSunday);    // this will give you the number of business days
                                                        // (excluding Saturdays and Sundays) for a given date range.
    // then, for each holiday, you can enter lines like this
    if date(2008,01,01) in {?My Parameter} then days := days - 1;
    // The final tally of DAYS should give you the total business days in a date range.
    totext(days,0);
    where {?My Parameter} is the date range.

  • Calculating Work Day Formulas

    We've recently adopted BOBJ/Webi at my company and I find the software to be rather easy to use in some instances and mind-wreckingly hard in others. One roadblock myself and other users are bumping into is calculating work days. A definition of a work day in this instance would be Monday through Friday. The monkey wrench is that we would also like to subtract out holidays, such as July 4th and Thanksgiving. Then end product would be calculating out what work day the current date is and how many days it is out of so that a simple straight-line extrapolation can be made (Metric/Current Work Day)*Total Work Days. Also, what we invoice/ship is not accounted for until the following day... for example, today (2.22.10) would be the 15th workday in February out of 20 total work days.
    Appreciate any and all help/assistance/counsel I can get on this.
    Ryan

    Hi Ryan,
    If I have understood your question then I think following solution may help you.
    Do you have your Universe created on the top of BW query or is it some other Database?
    If it is some other database then create couple of Filter at Universe level: Such as Holidays so that you can use this one to subtract holidays:
    For Example:
    ucase(Calendar_year_lookup.Holiday_Flag)
    ucase(Calendar_year_lookup.Holiday_Flag) = 'Y'
    Then you create another Dimension for Work days that would be between Monday to Friday.
    Once they are created in Universe you export Universe.
    Now create a formula where you would use month minus custom dimension workdays and minus holidays to get actual work days which would be from Monday to Friday and son on.
    Basically we can achieve this by using filters and formulas.
    Wish you good luck.
    Bashir Awan

  • How to use this query in oracle?

    Hi sir,
    i am using one query in sql that is
    declare @date date='2012-10-25', @date1 varchar(5)
    set @date1 = DATEPART(W, @date)
    print @date1
    in that its returning value 5 means 25 oct day is thursday so it's checking and counting from sunday in that week so the result is coming 5.
    and storing in @date1
    the same result i want it in oracle.
    thanks

    To_char(date,'D') conversion depends on setting of nls_territory.
    So in AMERICA the week starts on sunday and in GERMANY it starts on monday.
    Of cause, the solution of ranit B will work with proper setting of nls_territory.
    You can check the setting of nls_parameters with
    select * from v$nls_parameters;Alternatively here is a solution that is independent of nls_territory with starting day sunday:
    SELECT 1+ mod(1 + TRUNC (to_date('2012-10-25','YYYY-MM-DD')) - TRUNC (to_date('2012-10-25','YYYY-MM-DD'), 'IW'),7)  AS d
    FROM    dual;
    D
    5If you want a nls_territory independent solution with starting day monday you can use:
    SELECT 1+ mod(TRUNC (to_date('2012-10-25','YYYY-MM-DD')) - TRUNC (to_date('2012-10-25','YYYY-MM-DD'), 'IW'),7)  AS d
    FROM    dual;
    D
    4Edited by: hm on 04.10.2012 22:26

  • Calculating Business Days in a Date Range

    I have two questions:
    1. Does anyone know a better formula for calculating business days in totals?
    I am currently using the formula in https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/701a52c3-6b1e-2b10-21b3-a6e101be1a0f
    I tailored to my needs.  However, there are still a lot of manual maintenance every year. 
    2. I have many reports that need the formula.  It is very consuming to update the formula in each report.  Does anyone know a better way to do it? 
    I use Crystal XI. 11.0.0.895.  We do have a Crystal Enterprise server hosted in another department.

    Not sure if this is any simpler but you could save this as a custom function, that way you will have to modify it once a year for the holidays.
    numbervar days;
    datevar date1 := minimum({?My Parameter});
    datevar date2 := maximum({?My Parameter});
    days := DateDiff ("d", date1, date2) -
    DateDiff ("ww", date1, date2, crSaturday) -
    DateDiff ("ww", date1, date2, crSunday);    // this will give you the number of business days
                                                        // (excluding Saturdays and Sundays) for a given date range.
    // then, for each holiday, you can enter lines like this
    if date(2008,01,01) in {?My Parameter} then days := days - 1;
    // The final tally of DAYS should give you the total business days in a date range.
    totext(days,0);
    where {?My Parameter} is the date range.

  • Calculating work days in a function

    I have a function that will count the total number of days between two weeks. ie May 19, 2010 to June 18, 2010 is 30 total days in my cycle. We dont work on weekend so that 30 days is not correct. The formula below is how i'm calculating the days between cycles. Is there any way to not count the weekends in my cycle? Please see formula below:
    TIMESTAMPDIFF(SQL_TSI_DAY, "Release Dim"."Release Cycle Start Date", "Release Dim"."Release Cycle End Date")

    Thanks Hammett81.
    I used your formula but it's still calculating the days in my cycle as 30. My start date comes from my column "Release Dim"."Release Cycle Start Date" and my end date comes from the column "Release Dim"."Release Cycle End Date". Can you tell me why the formula below is giving me the weekends included in my count?
    Thanks a million for all your help.
    TIMESTAMPDIFF(SQL_TSI_DAY,TIMESTAMPADD( SQL_TSI_DAY, 7-DAYOFWEEK("Release Dim"."Release Cycle Start Date"),"Release Dim"."Release Cycle Start Date"),TIMESTAMPADD(SQL_TSI_DAY, 7-DAYOFWEEK("Release Dim"."Release Cycle End Date"),"Release Dim"."Release Cycle End Date"))+ CASE 7-DAYOFWEEK("Release Dim"."Release Cycle Start Date") WHEN 6 THEN 5 ELSE 7-DAYOFWEEK("Release Dim"."Release Cycle Start Date") END-CASE 7-DAYOFWEEK("Release Dim"."Release Cycle End Date") WHEN 6 THEN 5 ELSE 7-DAYOFWEEK("Release Dim"."Release Cycle End Date") END

  • Making calculations in QueryDesigner using only two decimals

    Hi,
    I need to make a calculation in a bex analyzer query, using only two decimals.
    Ex.
    A = 10
    B = 3
    C = 1000
    D is a variable.
    In a query, the following calculation: A/B = D | D*1000
    Results in the following: 3333
    But if D only had two decimals, the result would end up as = 3330.
    I know I can control the number of decimals <u>shown</u> using properties, but this won't change the number of decimals actually used for the calculation.
    Anyone got an idea ?
    -Tone

    Tonni!!
    if 3333 if you put two decimal place it will put 3333.00 but not rounding, if you need rounding then that is different, 3333.51 will be rounded to either to 3333.00 or 3334.00
    thanks.
    Wond

  • WebI Report using BW Query

    Hi,
    I am using WebI Report using BW Query. I don't see some Formulas in Universe which is there in BEx Query.
    Did anybody face the same problem before?

    Hi,
    I meant that you should post in the forum the calculation contained in the formula that you cannot see in your universe.
    But let's start from the begining since you are new to SAP: Did you generated the universe yourself? If the formula was added in the query after the universe was created then you must refresh your universe (In the Universe designer  please select the option "Refresh structure" under the "view" menu) in order to get the newly created formula (I assume we are takling about a calculate figure here) in your universe also.
    Regards,
    Stratos

  • How to backup database using sql query?

    Hello,i'm student, i'm researching oracle database,i want to backup database that using sql query (like backup query in SQL SERVER) ,how to do that ??
    Thank!

    No, database backups cannot be done from within the database.
    Commands for backups are outside of the database.
    See the "2 Day DBA Guide" http://download.oracle.com/docs/cd/E11882_01/server.112/e10897/toc.htm
    and the "Backup and Recovery Users's (actually Adminsitrator's) Guide : http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/toc.htm
    Hemant K Chitale

  • Dataload using sql query

    Hi,
    i need to load the data using sql query in to essbase cube by using maxl .If any one knows this please let me know.
    i
    thanks in advance

    Here is a sample maxl script I use to clear, load, and calculation a BSO Application and Database. Both the Application and Database are titled "STAT_2".
    /*** Login to essbase server ***/
    /*** login $1 $2 on $3; ***/
    login 'username 'password' on 'server';
    /*** Set output file to spool all error messages only ***/
    spool stdout on to 'C:\Hyperion\Automation\Logs\STAT_2_ALL_Load_Essbase.LOG';
    spool stderr on to 'C:\Hyperion\Automation\Errors\STAT_2_ALL_Load_Essbase.ERR';
    /*** Clear data in STAT_2 ***/
    /** execute calculation 'STAT_2'.'STAT_2'.'ClrA2Yr'; **/
    /*** Import data from the FACT_STAT_2YEARS table using a load rule ***/
    import database 'STAT_2'.'STAT_2' data connect as 'SQLUserName' identified by 'SQLPassword' using server rules_file 'LdA_All.rul' on error write to 'C:\Hyperion\Automation\Logs\STAT_2_ALL_Load_Essbase.log';
    /*** Calculate data in STAT_2 ***/
    /** execute calculation 'STAT_2'.'STAT_2'.'ClcA2Yr'; ***/
    spool off;
    logout;
    exit;

  • Filtering data using sql query

    I am pulling data from a database which is a log of events type data. It consists of entries at a certain time, entry text, and even has an entry type. One of those types is known as "open item." This entry has the potential to be present on multiple days over and over. The problem is I only want the "open item" entries to appear that occur on the most recent day of a date range that is input by the user, but also not excluding all other entries from all of the other days that are not "open item." The "is_open=0" is what is excluding the "open items" from all of the entries, but now there needs to be a way to include (ie. "is_open=1") the "open items" on the current day. My query is as follows:
    SELECT     b.log_title, a.log_id, MIN(a.shift_date) AS shift_date,a.shift_id,a.operator_position_descr,a.is_open,a.user_id, MAX(a.annotation_number) AS annotation_number,
                          a.entry_text, MIN(a.entry_time) AS entry_time,a.font_num
    FROM         log_entries AS a INNER JOIN
                          log_list AS b ON a.log_id = b.log_id
    WHERE ((entry_type_code NOT LIKE '%NLOG%'
                AND entry_type_code <> 'daily'
                AND entry_type_code <> 'shift act') or entry_type_code is null)
              AND (is_open = 0  AND is_standing_order = 0 AND is_rolled_forward is null) 
    GROUP BY b.log_title, a.log_id, a.user_id,a.shift_id,a.operator_position_descr,a.is_open, a.entry_text,a.font_num
    Order by entry_time

    Change you WHERE clause to something like this... (You didn't say what kind of DB you were using so I used SQL Server syntax)
    WHERE ((entry_type_code NOT LIKE '%NLOG%'
    AND entry_type_code IN ('daily', 'shift act')) OR entry_type_code is null)
    AND (is_open = 0 OR (is_open = 1 AND a.shift_date >= DateAdd(dd, DateDiff(dd, 0, GetDate()), 0)))
    AND is_standing_order = 0
    AND is_rolled_forward is null
    The biggest change is this... AND (is_open = 0 OR (is_open = 1 AND a.shift_date >= DateAdd(dd, DateDiff(dd, 0, GetDate()), 0))).
    It allows is_open = 1 if the shift_date is =&gt; midnight of the of the current day.
    HTH,
    Jason

  • Days Overdue analysis Query

    Hi
    I have a requirement to change the query which is exactly
    the same as Days Overdue analysis query (0FIAR_C03_Q0005)
    based on FI_AR line item cube which calculate the ageing buckets.
    In this query we have a key due date and all the ranges are
    calculated on this and they are all fixed 30, 60, 90,....
    But In my case the user want to have the flexibility to enter the  bucket values as 15, 25, 35,....
    and then all the key figures should calculated accordingly..
    Please advise how this can be achieved....
    Many Thanks in advance.
    Kind Regards,
    Kate.

    Kate
    U will have to create a variable on a date which is a basis for overdue calculation and then make a replacement path for the same, in a coding for make a fields as a parameter (so that it will appear in the selection screen of the query) Now, u will offset date by this parameter value. This u have to Code in ABAP in Exit with the help of ABAPer, it's bit of abnormal requirement, It will great if u could manage to do this.
    Please let me know the progress so that i can add a bit whenever required.
    Message was edited by: sunraj

Maybe you are looking for

  • Can't create 8.0.5 DB on Redhat 6.1

    Hello, I am attempting to install the standard edition of Oracle 8.0.5 on Redhat 6.1. At this point in time, I have performed the following steps: 1. Logged on as Oracle. 2. Installed all products without creating the DB. 3. Applied glibcpatch, proba

  • Large String in ALV Cell

    Hi, what is the best way to get a large string into an ALV Grid cell? Any help is greatly appreciated. / Elvez

  • Is this a proper reparation of my nokia 5800XM?

    My nokia 5800 suffered from the well know "crack" So i went back to tmobile (my carier) to have it fixed. They took back the phone and fixed it under garantee. When i got it back the crack was indeed gone but today i discovered how they fixed it! Is

  • Ipad 1 ios 4.3.3 battery charge

    I've an ipad with ios 4.3.3 and takes a long time to charge the battery, is this normal??

  • Server7 Installer crashes on NT

    I am attempting to install a legacy database on a (clean) Windows NT 4.0 system with no other Oracle products installed. Oracle Server 7.3.4 installs correctly but when I attempt to install Designer/2000 1.3.2 (or ANY other Oracle product including s