LastYearYTD Date Range Function
Hi,
I have a spreadsheet which includes a column with a date in it. The dates range from 2002-present. I am trying to create a comment for those records where the date falls within the previous 12 months from the time of the report run (today) rather than having to specify the date range every time I run the report. Here is my simple logic:
If {LEVEL_09_UNON_L21_L23_ACTIVE_INACTIVE.STUDY ACTUAL DBF} in LastYearYTD then
"DBF Achieved within Last Year"
Unfortunately, it is only creating the comment for the 2 records below. Why is it not creating the comment for all records where the date is between 08-Jan-2008 and 08-Jan-2009?
STUDY ACTUAL DBF 01c_DBF_ACHVD_12MOS
07-Jan-2008 DBF Achieved within Last Year
08-Jan-2008 DBF Achieved within Last Year
09-Jan-2008
10-Jan-2008
10-Jan-2008
11-Jan-2008
17-Jan-2008
Thank you for your help.
Actually, someone just told me to try this and it worked. I just didn't want to have to change the dates everytime I ran the report. Thank you for your help!!
If {LEVEL_09_UNON_L21_L23_ACTIVE_INACTIVE.STUDY ACTUAL DBF} >=CurrentDate -365 then
"DBF Achieved within Last Year"
Else If {LEVEL_09_UNON_L21_L23_ACTIVE_INACTIVE.STUDY ACTUAL DBF} >=CurrentDate -730 then
"DBF Achieved within Last Two Years"
Similar Messages
-
Hi Experts,
I have a complex requirement for a date range functionality.
Here is the detailed explanation:
I have field TransactionDate field coming from an Oracle View.
I have 2 parameters to be created on the same field and either of them can be selected but not both and both can be blank even.
1. Transaction date on or before
2. Transaction Date Range
We may have values for only one prompt at any given point.
If the user enters value for Transaction date on or before, then report should display data less than or equal to the date entered.
If the user enters values for the Transaction Date Range, report should display date between the user entered dates.
If none is entered report should display data for all dates.
Now, when the Transaction Date Range has same values in Start of Range and End of Range, we need to display the record for maximum(Transaction Date) under a particular account, irrespective of the dates specified, i.e if the user enters current date in Start of Range and End of Range and there will be no records for this date. In this scenario, report should display the maximum(Transaction Date) for that account.
I've tried all of I could, but ending up with a blank report.
Any suggestions will be of great help. Thanks in advance.
NareshHI Naresh,
Have you tried this,
add 'maximum' infront of this '...... {DBVW.DT} <= CurrentDate' condition
if(({@FrmBalDt}(NotEqualto)" " and {@ToBalDt}(NotEqualto)" ") and ({@FrmBalDt} = {@ToBalDt})
and MAXIMUM({DBVW.DT} )<= CurrentDate)
then maximum({@BalDate})
else {@BalDate}
if it is not working, Check where the condition is failing..
or else try this also
(not HasValue({?Client Id}) OR {DBVW.CLID} = {?Client Id}) and
(not HasValue({?Base Currency Code}) OR {DBVW.BCCYCOD} = {?Base Currency Code}) and
(not HasValue({?Account Type}) OR {DBVW.ACDES} = {?Account Type}) and
(not HasValue({?Legal Entity Name}) OR {DBVW.CUST} = {?Legal Entity Name}) and
(not HasValue({?Account Currency}) OR {DBVW.CCY} = {?Account Currency}) and
(not HasValue({?Account Number}) OR {DBVW.ACNO} in {?Account Number}) and
(not HasValue({?Account Group}) OR {DBVW.ACGRP} = {?Account Group}) and
(not HasValue({?Show Latest Statement on or before}) OR {DBVW.DT} <= {?Show Latest Statement on or before}) and
(if {?Activity Only} = "True" then ({DBVW.CT_CR} <>0 or {DBVW.CT_DB}0)
ELSE if {?Activity Only} = "False" then ({DBVW.CT_CR} >=0 or {DBVW.CT_DB}>=0)) and
(if {?Business Days Only} = "True" then (not(datepart("w",{DBVW.DT}) in 7,1) and
(not HasValue({?Balance Date Range}) OR {@BalDate} = {?Balance Date Range}))
else if {?Business Days Only} = "False" then ((not HasValue({?Balance Date Range})
Up to this copy paste of your formula
OR {@BalDate} = (if maximum({?Balance Date Range})>maximum({DBVW.DT} ) then maximum(date({DBVW.DT} )) else {?Balance Date Range}))))
i think this may work, without your second formula
regards,
Salah
Edited by: salahudheen muhammed on Sep 11, 2009 4:56 PM
Edited by: salahudheen muhammed on Sep 11, 2009 5:02 PM -
Function to list the month from a date range?
I would like to know what the function is that would take a look at a date range, and extract the month name
Here is how I would like it to come out:Hello
The following sample tables are along your original scheme using month name to filter the data.
2014 (excerpt)
A1 month
A2 =MONTHNAME(MONTH(B2))
A3 =MONTHNAME(MONTH(B3))
A4 =MONTHNAME(MONTH(B4))
B1 date
B2 2013-01-15
B3 2013-01-20
B4 2013-01-27
C1 category
C2 A
C3 B
C4 C
D1 amount
D2 100
D3 50
D4 20
January
A1 category
A2 A
A3 B
A4 C
A5 D
A6 E
A7 F
A8 G
A9 H
B1 totals
B2 =SUMIFS(2014::D,2014::A,C$1,2014::C,A2)
B3 =SUMIFS(2014::D,2014::A,C$1,2014::C,A3)
B4 =SUMIFS(2014::D,2014::A,C$1,2014::C,A4)
B5 =SUMIFS(2014::D,2014::A,C$1,2014::C,A5)
B6 =SUMIFS(2014::D,2014::A,C$1,2014::C,A6)
B7 =SUMIFS(2014::D,2014::A,C$1,2014::C,A7)
B8 =SUMIFS(2014::D,2014::A,C$1,2014::C,A8)
B9 =SUMIFS(2014::D,2014::A,C$1,2014::C,A9)
C1 January
C2
C3
C4
C5
C6
C7
C8
C9
Notes.
Formula in January::B2 can be filled down across B2:B9.
The target month name is defined in January::C1.
February table is the same as January table except for the value in C1.
And the following sample tables are using date per se instead of month name to filter the data. In this scheme, you don't need month column in source table but the retrieving formulae in destination table become more complex.
2014 (excerpt)
A1 date
A2 2013-01-15
A3 2013-01-20
A4 2013-01-27
B1 category
B2 A
B3 B
B4 C
C1 amount
C2 100
C3 50
C4 20
January
A1 category
A2 A
A3 B
A4 C
A5 D
A6 E
A7 F
A8 G
A9 H
B1 totals
B2 =SUMIFS(2014::C,2014::B,A2,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B3 =SUMIFS(2014::C,2014::B,A3,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B4 =SUMIFS(2014::C,2014::B,A4,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B5 =SUMIFS(2014::C,2014::B,A5,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B6 =SUMIFS(2014::C,2014::B,A6,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B7 =SUMIFS(2014::C,2014::B,A7,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B8 =SUMIFS(2014::C,2014::B,A8,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B9 =SUMIFS(2014::C,2014::B,A9,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
C1 2013-01-01
C2
C3
C4
C5
C6
C7
C8
C9
Notes.
Formula in January::B2 can be filled down across January::B2:B9.
The target month is defined in January::C1, which can be any date in target month, e.g., 2013-01-01, 2013-01-20, etc. The formulae in B will retrieve data with date in range: 2013-01-01 <= [date] <= 2013-01-31.
February table is the same as January table except for the value in C1.
Tables are built in Numbers v2.
Hope this may help,
H
EDIT: Replaced the last table with the correct one. (Formulae in B are correct) -
Using analytical function to calculate concurrency between date range
Folks,
I'm trying to use analytical functions to come up with a query that gives me the
concurrency of jobs executing between a date range.
For example:
JOB100 - started at 9AM - stopped at 11AM
JOB200 - started at 10AM - stopped at 3PM
JOB300 - started at 12PM - stopped at 2PM
The query would tell me that JOB1 ran with a concurrency of 2 because JOB1 and JOB2
were running started and finished within the same time. JOB2 ran with the concurrency
of 3 because all jobs ran within its start and stop time. The output would look like this.
JOB START STOP CONCURRENCY
=== ==== ==== =========
100 9AM 11AM 2
200 10AM 3PM 3
300 12PM 2PM 2
I've been looking at this post, and this one if very similar...
Analytic functions using window date range
Here is the sample data..
CREATE TABLE TEST_JOB
( jobid NUMBER,
created_time DATE,
start_time DATE,
stop_time DATE
insert into TEST_JOB values (100, sysdate -1, to_date('05/04/08 09:00:00','MM/DD/YY hh24:mi:ss'), to_date('05/04/08 11:00:00','MM/DD/YY hh24:mi:ss'));
insert into TEST_JOB values (200, sysdate -1, to_date('05/04/08 10:00:00','MM/DD/YY hh24:mi:ss'), to_date('05/04/08 13:00:00','MM/DD/YY hh24:mi:ss'));
insert into TEST_JOB values (300, sysdate -1, to_date('05/04/08 12:00:00','MM/DD/YY hh24:mi:ss'), to_date('05/04/08 14:00:00','MM/DD/YY hh24:mi:ss'));
select * from test_job;
JOBID|CREATED_TIME |START_TIME |STOP_TIME
----------|--------------|--------------|--------------
100|05/04/08 09:28|05/04/08 09:00|05/04/08 11:00
200|05/04/08 09:28|05/04/08 10:00|05/04/08 13:00
300|05/04/08 09:28|05/04/08 12:00|05/04/08 14:00
Any help with this query would be greatly appreciated.
thanks.
-peterafter some checking the model rule wasn't working exactly as expected.
I believe it's working right now. I'm posting a self-contained example for completeness sake.I use 2 functions to convert back and forth between epoch unix timestamps, so
I'll post them here as well.
Like I said I think this works okay, but any feedback is always appreciated.
-peter
CREATE OR REPLACE FUNCTION date_to_epoch(p_dateval IN DATE)
RETURN NUMBER
AS
BEGIN
return (p_dateval - to_date('01/01/1970','MM/DD/YYYY')) * (24 * 3600);
END;
CREATE OR REPLACE FUNCTION epoch_to_date (p_epochval IN NUMBER DEFAULT 0)
RETURN DATE
AS
BEGIN
return to_date('01/01/1970','MM/DD/YYYY') + (( p_epochval) / (24 * 3600));
END;
DROP TABLE TEST_MODEL3 purge;
CREATE TABLE TEST_MODEL3
( jobid NUMBER,
start_time NUMBER,
end_time NUMBER);
insert into TEST_MODEL3
VALUES (300,date_to_epoch(to_date('05/07/2008 10:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 19:00','MM/DD/YYYY hh24:mi')));
insert into TEST_MODEL3
VALUES (200,date_to_epoch(to_date('05/07/2008 09:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 12:00','MM/DD/YYYY hh24:mi')));
insert into TEST_MODEL3
VALUES (400,date_to_epoch(to_date('05/07/2008 10:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 14:00','MM/DD/YYYY hh24:mi')));
insert into TEST_MODEL3
VALUES (500,date_to_epoch(to_date('05/07/2008 11:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 16:00','MM/DD/YYYY hh24:mi')));
insert into TEST_MODEL3
VALUES (600,date_to_epoch(to_date('05/07/2008 15:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 22:00','MM/DD/YYYY hh24:mi')));
insert into TEST_MODEL3
VALUES (100,date_to_epoch(to_date('05/07/2008 09:00','MM/DD/YYYY hh24:mi')),
date_to_epoch(to_date('05/07/2008 23:00','MM/DD/YYYY hh24:mi')));
commit;
SELECT jobid,
epoch_to_date(start_time)start_time,
epoch_to_date(end_time)end_time,
n concurrency
FROM TEST_MODEL3
MODEL
DIMENSION BY (start_time,end_time)
MEASURES (jobid,0 n)
(n[any,any]=
count(*)[start_time<= cv(start_time),end_time>=cv(start_time)]+
count(*)[start_time > cv(start_time) and start_time <= cv(end_time), end_time >= cv(start_time)]
ORDER BY start_time;
The results look like this:
JOBID|START_TIME|END_TIME |CONCURRENCY
----------|---------------|--------------|-------------------
100|05/07/08 09:00|05/07/08 23:00| 6
200|05/07/08 09:00|05/07/08 12:00| 5
300|05/07/08 10:00|05/07/08 19:00| 6
400|05/07/08 10:00|05/07/08 14:00| 5
500|05/07/08 11:00|05/07/08 16:00| 6
600|05/07/08 15:00|05/07/08 22:00| 4 -
Function module for getting periods for date range
Hi,
Can anybody tell me the function module which will return the periods along with the year, when we give a date range.
e.g
01011999 to 120112000
so it shoud return peroids between these date with year. Its possible thru programatically, but i m checking if there is any FM, so i can use FM.
Thanks,Hi,
You can use function module which works exactly what you are expecting FIMA_DAYS_AND_MONTHS_AND_YEARS.
please reward points to useful answers.
Thanks,
Sriram Ponna. -
Function Module to Compare Date within date Range
Hi All,
Does anyone know Function Module to Compare Date within date Range...For example i need to find whether 08/02/2006 falls in between 07/15/2006 and 09/15/2006......data: datum type sy-datum value '20070802',
datum_low type sy-datum value '20070730',
datum_high type sy-datum value '20070930'.
If datum between datum_low and datum_high.
Endif.
Regards,
Rich Heilman -
Function module to calculate no of days between two date ranges
hi experts,
can some one please suggest a function module that can calculate no of days between specified date range.
for example : if i enter date range between 26.02.2011 to 20.05.2011, then it should calculate no of days between these dates.
Moderator message : Basic date questions not allowed. Read forum rules before posting. Thread locked.
Edited by: Vinod Kumar on May 25, 2011 10:57 AMHi,
Please search SDN.. there are lots of posts for teh same.
[http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations] -
Using function(s) to select date range in a computation.
Hello
Within my ApEx report, I would like to be able to have data returned from within a date range selected by the user. Under "Compute" there are lots of "Functions" (Least, Greatest, Last_Day, etc.) but so far I have not been able to find the right syntax for date range.
This seems so simple - any help appreciated.
Thanks
Paul S.I do not use APEX but is the BETWEEN operator available to you?
Normally to select a date range you just write code like
select ....
from table_t
where date_col between to_date(start_date,'format') and to_date(end_date,'format')
or
where date_col >= to_date(start_date,'format')
and date_col < to_date(end_date,'format') + 1
as this form eliminates worrying about the time component.
HTH -- Mark D Powell -- -
Hi guys,
i have a selection screen where i need to give range of date.
say from 01.01.1998 to 01.02.2007.
i need to pass this date range to 'Z' funtion module how can i do it.
do i need to define it in tables declaration. if yes what will be the reference type of this field.
I want this range of dates in function module.
Please explain.Hi ahmed
Let us assume s_date is the select option for the date range defined like
DATA: s_date for p0001-begda.
Now while calling the FM pass the s_date-low and s_date-high as 2 parameters for the FM.In the FM create 2 parameters begda and endda of type begda. Use the low value and high value in the FM to populate the range table and u can use this range table for further processing of the dates in the FM.The range table can be forwarded as follows:
r_date-low = begda.
r_date-high = endda.
also provide the sign and options for the ranges table. -
Function Module which will take Wekk No & Return date range (from & To dat)
Hello everyone,
I need a Function Module which will take Week No as an input Parameter & return me the date range
(From date & To date of that week) .
Thanks in advance!
Cheers!
Moderator message: date calculation questions = FAQ, please search before posting.
Edited by: Thomas Zloch on Nov 2, 2010 5:25 PMHi,
Please write the below logic..
data : v_date11 type sy-datum,
monday type sy-datum,
sunday type sy-datum,
v_count1 type i .
*v_count1 = 20 * 7. " Say U want details for 20th week , or give a parameter for week and multiply with 7*
v_date11 = '20100101'. " take the starting day of the year ....
v_date11 = v_date11 + v_count1. " add to the date
CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE' <-- call this FM
EXPORTING
DATE = v_date11
IMPORTING
WEEK = WEEK
MONDAY = MONDAY <-- will have the week starting day
SUNDAY = SUNDAY
Regards,
Srini. -
Function module find date Range input for scheduling a job
hi i have created a program for scheduling a back ground job for purchase order extract in that i have to get the last 7 days records when i schedule it on every sunday can any one tell me the function module which satisfies the requirment
Date Range input in my program to be calculated for past 7 days from current date (ie from Sunday to Saturday of the week.)Hi,
You can do it simply by
v_cdate TYPE sy-datum, " current system date
v_cdate = sy-datum - 7. " take date 7 days before current date
Pass this v_cdate in your logic
Hope it will help you.
Thanks
Arun Kayal -
Function Module for separating a date range into days
Hi all,
Does anyone know if there is a function module which gives back the list of days when we give a date range as input parameter to the function module. For example, we enter the range 10.07.2006 - 13.07.2006 and the function module gives back a table in form 10.07.2006, 11.07.2006, 12.07.2006, 13.07.2006.
Thanks,
SükrüHi suekrue,
1. Exactly for this purpose,
i have written an
INDEPENDENT FORM (subroutine)
wherein we pass
a) fromdate
b) todate
c) ITAB
2. and it gives all the dates in the internal table.
3. just copy paste
4.
data : itab type table of sy-datum with header line.
parameters : fromdate type sy-datum default '20060701'.
parameters : todate type sy-datum default sy-datum.
perform getdays tables itab using fromdate todate.
break-point.
FORM
form getdays
tables itab
using fromdate todate.
data : curdate type sy-datum.
curdate = fromdate.
do.
if curdate > todate.
exit.
endif.
itab = curdate.
append itab.
curdate = curdate + 1.
enddo.
endform. "getdays
regards,
amit m. -
Analytic functions using window date range
Here are my requirements:
For each FLT# Get the MIN and MAX CRSG_DT within 2½ hours period into the same bucket for each day
I am using Oracle 10gR2
CREATE TABLE TST_ANAL
FLT_NBR VARCHAR2(10),
CRSG_DT DATE ,
TNBR VARCHAR2(14)
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:31:57 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013438');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 08:31:02 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013446');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:30:34 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013440');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:32:07 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013427');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:32:40 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013433');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:35:40 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013429');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:32:45 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013434');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:32:50 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D200707001323');
COMMIT;
The desired output:
FLT_NBR CRSG_DT MIN MAX Bucket
2947 3/1/2007 5:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 5:35 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 7:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 7:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 17:30 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 17:32 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 19:31 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 20:31 3/1/2007 20:31 3/1/2007 20:31 3
I am sure an Analytic query is the optimal solution. I need help creating the query. So far, I have attempted to use the min() and then both First_value() over partition clause but I do not know how to specify the window clause using a logical date range to calculate the 2 1/2 hours.
A lot of documentation states that I can use an expression for the range between but I cannot get one even compile
Need Help or documentation that provide some assistance
ThanksI can get to the min and max, but for bucket, row_number() doesn't take the same windowing logical offset.
SQL> select flt_nbr,
2 crsg_dt,
3 min(crsg_dt) over (partition by flt_nbr,
4 trunc(crsg_dt)
5 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mn,
6 max(crsg_dt) over (partition by flt_nbr,
7 trunc(crsg_dt)
8 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mx
9 from tst_anal
10 /
FLT_NBR CRSG_DT MN MX
0002947 01-MAR-2007 05:32:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 05:35:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 07:32:45 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 07:32:50 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 17:30:34 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57
0002947 01-MAR-2007 17:32:07 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57
0002947 01-MAR-2007 19:31:57 01-MAR-2007 17:30:34 01-MAR-2007 20:31:02
0002947 01-MAR-2007 20:31:02 01-MAR-2007 19:31:57 01-MAR-2007 20:31:02
8 rows selected.
SQL> Had to user FIRST_VALUE and then calculate row_number() on that for bucket.
SQL>
SQL> select flt_nbr, crsg_dt, mn, mx, dense_rank() over (partition by flt_nbr,
2 trunc(crsg_dt)
3 order by rn) bucket
4 from (select flt_nbr,
5 crsg_dt,
6 min(crsg_dt) over (partition by flt_nbr,
7 trunc(crsg_dt)
8 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mn,
9 max(crsg_dt) over (partition by flt_nbr,
10 trunc(crsg_dt)
11 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mx,
12 FIRST_VALUE(crsg_dt) over (partition by flt_nbr,
13 trunc(crsg_dt)
14 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) rn
15 from tst_anal)
16 /
FLT_NBR CRSG_DT MN MX BUCKET
0002947 01-MAR-2007 05:32:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 05:35:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 07:32:45 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 07:32:50 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 17:30:34 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57 2
0002947 01-MAR-2007 17:32:07 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57 2
0002947 01-MAR-2007 19:31:57 01-MAR-2007 17:30:34 01-MAR-2007 20:31:02 2
0002947 01-MAR-2007 20:31:02 01-MAR-2007 19:31:57 01-MAR-2007 20:31:02 3
8 rows selected.
SQL> Cheers
Sarma. -
How to get top 11 values per date range
I want to get the top 11 values by date range.
Sample Data
CREATE TABLE SAMPLE_DATA
DOMAIN_NAME VARCHAR2(100),
QTD NUMBER,
LOAD_DATE DATE
-- Insert
BEGIN
FOR lc IN 1..20
LOOP
FOR ld IN 1..30
LOOP
INSERT
INTO SAMPLE_DATA VALUES
'DM_'
||lc,
round(dbms_random.value(0,1000)),
SYSDATE-ld
END LOOP;
END LOOP;
COMMIT;
END;
SELECT *
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM SAMPLE_DATA
WHERE LOAD_DATE = TRUNC(SYSDATE-3)
ORDER BY QTD DESC
WHERE ROWNUM <=10
UNION ALL
SELECT 'Others' DOMAIN_NAME,
SUM(QTD) QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT rownum rn,
DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM SAMPLE_DATA
WHERE LOAD_DATE = TRUNC(SYSDATE-3)
ORDER BY QTD DESC
WHERE rn > 10
GROUP BY LOAD_DATE
ORDER BY QTD DESC
-- Result
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/13
DM_1 1000 24/03/13
DM_20 933 24/03/13
DM_11 913 24/03/13
DM_3 743 24/03/13
DM_13 572 24/03/13
DM_12 568 24/03/13
DM_9 564 24/03/13
DM_6 505 24/03/13
DM_5 504 24/03/13
DM_2 480 24/03/13
Please, Help me get in one query this result using a range of date.
e.g
using LOAD_DATE BETWEEN '24/03/13' AND '25/03/13'
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/13
DM_1 1000 24/03/13
DM_20 933 24/03/13
DM_11 913 24/03/13
DM_3 743 24/03/13
DM_13 572 24/03/13
DM_12 568 24/03/13
DM_9 564 24/03/13
DM_6 505 24/03/13
DM_5 504 24/03/13
DM_2 480 24/03/13
Others 1948 25/03/13
DM_1 807 25/03/13
DM_8 764 25/03/13
DM_7 761 25/03/13
DM_11 656 25/03/13
DM_18 611 25/03/13
DM_17 523 25/03/13
DM_14 467 25/03/13
DM_19 447 25/03/13
DM_15 437 25/03/13
DM_6 380 25/03/13 Thank you in advance.I got the solution. Just sharing.
I used analytic functions that make my job easy.
Sample Data
DOMAIN_NAME QTD LOAD_DATE
DM_1 807 25/03/2013
DM_1 1000 24/03/2013
DM_2 226 25/03/2013
DM_2 480 24/03/2013
DM_3 244 25/03/2013
DM_3 743 24/03/2013
DM_4 48 25/03/2013
DM_4 413 24/03/2013
DM_5 164 25/03/2013
DM_5 504 24/03/2013
DM_6 380 25/03/2013
DM_6 505 24/03/2013
DM_7 761 25/03/2013
DM_7 212 24/03/2013
DM_8 764 25/03/2013
DM_8 308 24/03/2013
DM_9 354 25/03/2013
DM_9 564 24/03/2013
DM_10 214 25/03/2013
DM_10 367 24/03/2013
DM_11 656 25/03/2013
DM_11 913 24/03/2013
DM_12 37 25/03/2013
DM_12 568 24/03/2013
DM_13 332 25/03/2013
DM_13 572 24/03/2013
DM_14 467 25/03/2013
DM_14 87 24/03/2013
DM_15 437 25/03/2013
DM_15 450 24/03/2013
DM_16 238 25/03/2013
DM_16 299 24/03/2013
DM_17 523 25/03/2013
DM_17 143 24/03/2013
DM_18 611 25/03/2013
DM_18 145 24/03/2013
DM_19 447 25/03/2013
DM_19 464 24/03/2013
DM_20 91 25/03/2013
DM_20 933 24/03/2013 Top 11 QTD of DOMAIN_NAME per Data Range.
SELECT *
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT LOAD_DATE,
DOMAIN_NAME ,
QTD,
(DENSE_RANK() OVER (PARTITION BY LOAD_DATE ORDER BY QTD DESC )) AS RANK_QTD
FROM SAMPLE_DATA
WHERE trunc(load_date) BETWEEN '24/03/2013' AND '25/03/2013'
WHERE RANK_QTD <= 10
UNION ALL
SELECT 'Others',
SUM(QTD) AS QTD,
LOAD_DATE
FROM
(SELECT LOAD_DATE,
DOMAIN_NAME ,
QTD,
(DENSE_RANK() OVER (PARTITION BY LOAD_DATE ORDER BY QTD DESC )) AS RANK_QTD
FROM SAMPLE_DATA
WHERE trunc(load_date) BETWEEN '24/03/2013' AND '25/03/2013'
WHERE RANK_QTD > 10
GROUP BY LOAD_DATE
ORDER BY LOAD_DATE ASC,
QTD DESC
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/2013
DM_1 1000 24/03/2013
DM_20 933 24/03/2013
DM_11 913 24/03/2013
DM_3 743 24/03/2013
DM_13 572 24/03/2013
DM_12 568 24/03/2013
DM_9 564 24/03/2013
DM_6 505 24/03/2013
DM_5 504 24/03/2013
DM_2 480 24/03/2013
Others 1948 25/03/2013
DM_1 807 25/03/2013
DM_8 764 25/03/2013
DM_7 761 25/03/2013
DM_11 656 25/03/2013
DM_18 611 25/03/2013
DM_17 523 25/03/2013
DM_14 467 25/03/2013
DM_19 447 25/03/2013
DM_15 437 25/03/2013
DM_6 380 25/03/2013 -
No Data in Reports Details in Custom date range
Hello, iTunes U Public Site Manager Admins.
As the iTunes U Public Site Manager admin, I've been trying to access our institution's iTunes U Reports Details for a couple of days. (I send a monthly report of usage to our course/collection contributors.) When I custom the date range, under Details, there is zero entry; "No data available in table" message is shown.
This feature had been working well since Apple iTunes U added this enhancement on August 13, 2013. The report Details showed the exact stats for Browse, Subscribe, Download, Stream, and Enclosure for each course/collection in the custom date range.
Now under "Details", the data is shown only when the date range is Last 30 Days. It shows no data in custom date range when the Calendar is used to select a Start Date and End Date.
Has anyone else noticed this problem?
Thanks.
Q. WangErik.
I used your suggestion and it worked very well. This is how I did it.
Export the range of data that includes Feb. 1-Feb. 28, 2014 as .tsv file.
Open that file in Excel.
Add a blank column next to the Date column. Use function =Month() to just extract the month into the new column. Fill down the whole column. Then copy and paste special (value) into the same column (I have over 26,000 rows of data in the file.) Converting to Value will allow for the next step of PivotTable.
Create a PivotTable for the 26,000 rows of data. Use Month as the Report filter, iTunes_ID as the Row Labels, Select Browse, Subscribe, etc. as the Sum Values. (The result is a summary table with about 200 rows.)
I then do a Vlookup to my premade Master file to add Category (course, collection, resources) and Instructor Name to each of the 200 rows.
That will do it for my monthly report.
Thanks for your tip again. I did not know the .tsv file would have DATE for each item.
Sincerely,
Q. Wang
Maybe you are looking for
-
Hard drive damaged - replace it myself?
My computer crashed the other day, and a technician came over and after it wouldn't mount on his computer, and made some awful noises trying to start up, he declared the hard disk dead. I live in Costa Rica, so getting service is a pain. The tech off
-
Loding clob from file-ORA-22994
declare dest_clob CLOB; src_clob BFILE ; dst_offset number :=1; src_offset number :=1; lang_ctx number := DBMS_LOB.DEFAULT_LANG_CTX; warning number; type filesarray IS VARRAY(5) OF VARCHAR2(50); names filesarray; l_stmt CLOB; BEGIN names := filesarra
-
How do I get PS CC to recognize NIK Collection and Topaz Plugins?
These plugins worked, and still work, in PS CS5. But when I downloaded PS CC it does not recognize these plugins. How do I get them recognized in PS CC?
-
Apple Magic Mouse tracking speed
Is there a reason that every time I restart my 15" 2010 MBP that system preferences forgets my tracking speed for the magic mouse? It is very annoying to have to go into system preferences and changer it everytime I do a system restart. Operating
-
Just purchased CC today. Every time I try to launch Illustrator, I get an error from Windows that says "windows detected an error and will close the program. It will let me know if it finds a solution". I don't know what's wrong. I have all required