1347_en-US
Sum totals by month from date fieldIs there a simple way to create sum totals by month? I have a date field such as 01Apr2008 and I would like to tabulate by month.
I can display the date as only a month-year, such as 4/2008, but I can't use the tabulate function as it does it by day based on the underlying data.Re: Sum totals by month from date fieldI am not sure exactly what you want but you could make a month-only variable by adding a new column with the simple formula
Month(:Date) //assuming Date is the name of your date column
This will yield a numeric column with numbers 1-12. These can be recoded (use e.g. Recode in the Cols menu) to Jan-Dec if you prefer that. Use this column with Summary or Tabulate to get monthly statistics.
However, if you want summarize by both month and year then you could also make a Year(:Date) column and then group after both columns.
Alternatively make a a combined column with the formula (choose format m-y to avoid showing the date)
Date DMY( 1, Month( :Date ), Year( :Date ) )
Or by concatenating the month and year columns I described above using the column formula
Char( :Month ) || "-" || Char( :Year )
The last example gives a nominal month-year though, which may or may not be desired.Re: Sum totals by month from date fieldthat did the trick, thanks!Re: Sum totals by month from date fieldI think I just came up with a more elegant solution in a similar recent thread. I thought the problem seemed familiar, that I've been digging in to this not long ago. How ephemeral memory is! Glad you've found a solution.Re: Sum totals by month from date fieldCan you post or link to the more elegant solution. I'm trying to do something similiar with "Week-Year"
Thanks.Re: Sum totals by month from date fieldThere is a Week of Year function which assumes weeks begin on Sunday so you may get a week fragment at the beginning and another one (week 53) at the end of a year.
There is a Day of Year function which can be used to calculate a different Week of Year value which starts a full 7 day week on the first day of the year. There will be a 1 or 2 day week 53 fragment at the end of the year. That formula is:
Floor( (Day Of Year( :Date ) - 1) / 7 ) + 1
One way or the other you will have a new column of weeks of the year.
Message was edited by: mpbRe: Sum totals by month from date fieldRight - I'm actually trying to create a new variable that includes YEAR & WEEK of YEAR. The goal is to look at trends by WEEK across YEARS.
So we'd lke to get something like YYYWW or 200940. The variable needs to be stored as a numeric variable ideally.
Comments
There are no comments yet