Processing Timebased values - vbscript

I have a list of timebased values in the following form:
20/Dec/2011:10:16:29 9
20/Dec/2011:10:16:30 13
20/Dec/2011:10:16:31 13
20/Dec/2011:10:16:32 9
20/Dec/2011:10:16:33 13
20/Dec/2011:10:16:34 14
20/Dec/2011:10:16:35 6
20/Dec/2011:10:16:36 7
20/Dec/2011:10:16:37 16
20/Dec/2011:10:16:38 5
20/Dec/2011:10:16:39 7
20/Dec/2011:10:16:40 15
20/Dec/2011:10:16:41 12
20/Dec/2011:10:16:42 13
20/Dec/2011:10:16:43 11
20/Dec/2011:10:16:44 6
20/Dec/2011:10:16:45 7
20/Dec/2011:10:16:46 9
20/Dec/2011:10:16:47 14
20/Dec/2011:10:16:49 6
20/Dec/2011:10:16:50 11
20/Dec/2011:10:16:51 15
20/Dec/2011:10:16:52 10
20/Dec/2011:10:16:53 16
20/Dec/2011:10:16:54 12
20/Dec/2011:10:16:55 8
The second column contains value against each second. Values are there for complete month and for each and every second. I want to add these values:
Per minute basis. [for 00 - 59 seconds ]
Per hour basis [ for 00 - 59 minutes ]
Per Day basis. [ for 0 - 24 hours ]

Sounds like a job for Excel and a pivot table.
The trick is to parse the text date/time you have into something Excel can work with; splitting it on the colon will do just that. Assuming the value you have is in cell A2, this formula will convert the text into a real date:
=DATEVALUE(LEFT(A2,SEARCH(":",A2)-1))+TIMEVALUE(RIGHT(A2,LEN(A2)-SEARCH(":",A2)))
Then just create Minute, Hour and Day columns where you subtract out that portion of the date. For example, if the date from the above formula is in C2, the following will subtract out the seconds and give you just up to the minute:
=C2-SECOND(C2)/24/60/60
Then repeat the process for the next two columns to give you the hour and the day:
=D2-MINUTE(D2)/24/60
=E2-HOUR(E2)/24
Then all you have to do is create a pivot table on the data with rows Day, Hour, Minute and value Sum(Value).

Related

How to find the earliest date of the occurrence of a value for each year

I have a table with this structure:
STATION ID
YEAR
MONTH
DAY
RECDATE
VALUE
123456
1950
01
01
01-01-1950
95
123456
1950
01
15
01-15-1950
85
123456
1950
03
15
03-15-1950
95
123456
1951
01
02
01-02-1951
35
123456
1951
01
10
01-10-1951
35
123456
1952
02
12
02-12-1952
80
123456
1952
02
13
02-13-1952
80
And so on. There's a TMIN value for this station ID for every day of every year between 1888 and 2022. What I'm trying to figure out is a query that will give me the earliest date in each year that a value between -100 and 100 occurs.
The query select year, max(value) from table where value between -100 and 100 group by year order by year gives the year and value. The query select recdate, min(value) from table group by recdate order by recdate gives me every recdate with the value.
I have a vague memory of a query that practically partitions the data by a year or a date range so that the query would look at all the 1950 dates and give the earliest date for the value, then all the 1951 dates, and so on. Does anyone remember queries like that?
Thanks for any and all suggestions.
If I understood you correctly, this is your question:
What I'm trying to figure out is a query that will give me the earliest date in each year that a value between -100 and 100 occurs.
Then you posted 2 queries which return something, but I don't see relation to the question. What was their purpose? To me, they look like some random queries one could write against data in that table.
Therefore, back to the question: isn't that just
select min(recdate), --> "earliest date
year --> in each year
from that_table -- that a
where value between -100 and 100 --> value between -100 and 100 occurs"
group by year

Finding Max Weekly Average on a month

I am stuck on my query attempt. I have a table that lists test results with their dates. I need to run a query to return the highest weekly average for a particular month.
I have the first part figured out:
SELECT Effluent BOD5, WEEK(Date)
FROM bod
WHERE YEAR(Date) = 2020 AND MONTH (Date) = 4
ORDER BY WEEK(Date)
Returns:
Effluent BOD5 / WEEK(Date)
10 14
14 14
9 15
6 16
7 16
11 17
8 17
I need to get the result of 12 (which is the highest weekly average (week 14).
Any help would be great![enter image description here][1]
I messed around with this and figured it out! Here is what I used:
SELECT max(Total)
FROM
(SELECT week, avg(test) AS Total
From
(SELECT Effluent BOD5 test, WEEK(Date) week
FROM bod
WHERE YEAR(Date) = 2020 AND MONTH(Date) = 4
ORDER BY WEEK(Date),Effluent BOD5 desc)ab
GROUP BY week)ac

12 month rolling data from earliest invoice date - Hadoop

Seeking help with the following problem statement.
I/P Data Set:
customer id invoice date item id invoice amount Comment
1 10-Jan-2014 1 10 Start of 12 month window - 10th Jan 2014 to 10th Jan 2015
1 20-Jan-2014 2 20 Falls within 12 month window
1 21-Aug-2014 1 10 Falls within 12 month window
1 31-Dec-2014 1 10 Falls within 12 month window
1 20-Feb-2015 1 10 Start of new 12 month window as this is post 10th Jan 2015
1 30-Mar-2016 1 10 Start of new 12 month window as this is post 20th Feb 2016
Desired o/p
customer id invoice date item id invoice amount window sum(amount where item id = 1)
1 10-Jan-2014 1 10 1 10
1 20-Jan-2014 2 20 1 0
1 21-Aug-2014 1 10 1 20
1 31-Dec-2014 1 10 1 30
1 20-Feb-2015 1 10 2 10
1 30-Mar-2016 1 10 3 10
I tried using the following query in Hive to achieve the above output but the challenge is in resetting the next window once we have crossed the 12 month mark. (Please refer to rows 5 and 6 in the input data set). The need is for these records to be considered as start of a new window.
Following Query Used:
SELECT SUM(if(item_id = 1, invoice_amount, 0)) OVER (
PARTITION BY customer_id
ORDER BY invoice_date ASC
RANGE BETWEEN 31556926 PRECEDING AND CURRENT ROW
) FROM INVOICE_DETAILS;`

Adding new column and inserting values to an exisitng excelsheet using SSIS/SSRS

I have an existing excel template as like below :
DATE 7/28/2016 7/29/2016 July MTD YTD
Call Activity
IB_Calls_Offered 22 29 52 52 52
IB_Calls_Answered 22 29 52 52 52
Sale 6 3 9 9 9
Everyday when my SP get executed , I need to add a extra column (as Current Date) and fill the corresponding data.
Kindly Suggest me how to do it by using SSIS/SSRS

BIRT interpolate data in crosstab for rows/cols without data

Crosstab interpolate data so graph 'connects the dots'
I have trouble with my crosstab or graph not interpolating the data correctly. I think this can be solved, but I'm not sure. Let me explain what I did.
I have a datacube with the rows grouping data by weeknumber and the cols grouping data per recordtype. I added to flagbits to the dataset so I can see if a record is new or old. In the datacube I added a measure to sum these bits per row/col group. Thus effectively counting new and old records per week per coltype. I also added a sum of records per coltype.
In the crosstab I added two runningsums for the new and old records sums. In the crosstab I added a datacell to calculate the actual records per row/colgroup. Thus actual records = totalcoltype - runningsum(old) + runningsum(new)
So lets say there are 20 records in this set for a coltype.
In week 1: 3 old records, 2 new records. Then the running sum becomes 3 and -2. Actual = 20 - 3 + 2 = 19 (correct)
In week 2: no data. The runningsums are not visible. Actual = 20 - null + null = 20 (wrong)
In week 3: no data. The runningsums are not visible. Actual = 20 - null + null = 20 (wrong)
In week 4: 2 old records, 1 new recored. The runningsums becomes 5 and 3. Actual = 20 - 5 + 3 = 18 (correct)
In week 5: no data. The runningsums are not visible. Actual = 20 - null + null = 20 (wrong)
In week 6: 6 old records, 2 new records. The runningsums becomes 11 and 5. Actual = 20 - 11 + 5 = 14 (correct)
In week 7: no data. The runningsums are not visible. Actual = 20 - null + null = 20 (wrong)
So the graph will display:
19
20
20
18
20
14
20
If I add a condition to the actual calculation, it becomes:
19
null
null
18
null
14
null
The graph doesn't ignore the null values, but thinks they are 0. The graph is wrong.
Is there a way to let the graph realy ignore the null values?
Another solution is that the runningsums display the last know value or just add 0 if there is no data. Any idea how to do this?
Obviously, a correct graph would read:
19
19
19
18
18
14
14

Resources