Combining year-month data to continuous month variable (lubridate) - rstudio

ExampleI've got the following dataset year-month variable going from 1995 to 1999 and months 1 to 12.
The months start at 1 again at each new year. I want to create a continous month variable from 1 to 60, i can't find the correce lubridate code for this, any suggestions?
Much appreciated,
Best regards, Joris

Related

Problems with .resample('M')

I am using pandas & I have a dataframe with Date, Item#, Qty and 12 months of sales data. I want to do a std dev calc to understand the monthly variability for each Item#.
The problem is for many Item#'s the sales are sporadic: I may only sell Item XYZ in Feb and Mar, and zero the rest of the months of the year.
I am using this code to do the heavy lifting:
df.groupby('Item#').resample('M').sum()
For some Item#'s it is forcing zeros into the empty months (GOOD!), but in many cases it is just showing, say, two months of data, instead of 12, which then makes the std dev calculation incorrect.
Can someone help me understand why this behaviour of the .resample method? How can I workaround this problem?
Many thanks in advance for your help!

Is there library to convert number of days in a specific year to month and date?

I have an information which contains specific year and number of days. For example, 2000137 means May 16, 2000 because May 16 is the 137th day of year 2000. I need those numbers like 2000137 in the format 2000-05-16. I can do such conversion by considering how many days are in each month and how many days are in each year but I need to take the leap years into consideration and it seems too tedious to implement such code.
I wonder if there is simple function in Excel or Python to do such conversion.
You can achieve the above using Python's fromordinal and toordinal functions in the datetime library.
Try the following:
from datetime import date
ip=2000137
year=ip//1000
days=ip%1000
#days until that year
days_till_year=date(year,1,1).toordinal()
days_till_input=days_till_year+days-1
print(date.fromordinal(days_till_input))
The output would be:
2000-05-16

Next 6 months Data In OBIEE

I want to display Next 6 months Data from Current Month in OBIEE 11g.I tried with addmonths() but it shows all years in data,and if i filter on current year it will not shows months in next year.
It all depends - and that why someone voted down your question; it's just not very precise.
What do you want to compare it with? A month number? A month name?
Do you have what's needed? Do you have a properly formed time dimension?
The unclean approach is to use TIMESTAMPADD butwith that you're just curing the symptom, not the root cause.
TIMESTAMPADD(SQL_TSI_MONTH, 6, NOW())

Decimal places on dates, Crystal Reports

Good morning,
I'm currently working on a custom date for a label. It needs to read the last 2 numbers of the current year, followed by the number of day it is within the current year (8/3/2016 would be day 216). So if I were to print a label, the date on 8/3/2016 should read 16216. The following is the current code in the formula:
toText(CurrentDate,"yy") & DateDiff ("d", #1/1#, today) + 1
For reasons I'm unfamiliar with, this returns 16216.00. My question is how do I get rid of the decimal places with this being a text field?
If taken by themselves, toText(CurrentDate,"yy" returns 16 and DateDiff ("d", #1/1#, today) + 1 does return 216. It's only when concatenated that the decimal places appear. Is there a better way to do this?
I'm fairly new to using Crystal, so any help would be appreciated.
Thanks, guys.
You are looking for the Julian date. You have a couple of options
SELECT DATEPART(yy, #date), DATEPART(dy, #date)
SELECT RIGHT(CAST(DATEPART(yy, #date) AS char(4)),2)
The link below goes into much further detail
http://blogs.msmvps.com/robfarley/2009/03/25/converting-to-and-from-julian-format-in-t-sql/

Retrieve data based on current ISO week and backwards

I have to work with data retrieved and grouped on a weekly basis (ISO week) and my DB is structured on a daily basis (field: DATE). I need to write down a code which is rolling, so that given the current date, it calculate the week and the retrieve data in the previous 3 weeks, too.
So I write in the WHERE clauses:
TO_DATE(TO_CHAR(DATE, 'YYYYWW')) BETWEEN TO_DATE(TO_CHAR(TO_DATE(running_date, 'YYYYMMDD'), 'YYYYWW'), 'YYYYWW')-3 AND TO_DATE(TO_CHAR(TO_DATE(running_date, 'YYYYMMDD'), 'YYYYWW'), 'YYYYWW')
It doesn't seems to work though.
Any suggestions on how to handle the problem?
Thanks a lot!
You have to subtract 21 days when you want to recive the previous 3 weeks. If you subtract 3 then you recive only the last three days.
You need to use 'IW', not 'WW' as the format mask for ISO week. From the Oracle docs:
IW = Week of year (1-52 or 1-53) based on the ISO standard.
WW = Week of year (1-53) where week 1 starts on the first day of the year and
continues to the seventh day of the year.

Resources