I have a table where I only have week number and year (and another not timing variables).
Week number : I have it as 1, 2,3,4,5 up to 53.
Year : 2020, 2021, etc
Therefore for ever week-year I have a row.
Goal:
I have seen that in Tableau you can show by week too but showing the first day of the week (see screenshot).
How to create/convert a column/existing columns so that first day of week is shown as date instead.
Thanks,
You can do this. Try this formula:
DATETRUNC('week',DATEPARSE("w-yyyy",STR([Week])+"-"+ STR([Year])))
DATEPARSE converts your week and year to a date.
DATETRUNC returns the first date of each week.
Related
https://docs.google.com/spreadsheets/d/1Z9Wn9Kpe7nAR4nwfpPSNtvIAOkTtTp7IxV7WHp9a84M/edit?usp=sharing
I have a spreadsheet for the year. Every day is represented as its date and as its day of the week (bleu rows in the above spreadsheet). There is a blank column at the beginning of every month (ie, the "Febuary" column (greyed out in the above spreadsheet) doesnt increment the day of the week or the date).
What I want to do is, I want to look at either the day of the week or the date and write in above Sundays the week number. So "Wk01, Wk02, Wk03" up to Wk52. An example is marked in red on the link above. These "Wk"s would have 6 blanks between them (or 7 if the week is across the greyed out month column).
Use weeknum(), like this:
=arrayformula( if( B11:11 = "Sun", "Wk" & weeknum(B12:12), iferror(1/0) ) )
Currently have rows aggregated by week number.
SELECT to_char(date, 'IYYY-MM-IW') AS week, from TABLE GROUP BY week
The results will show the form "2021-07-29". Is it possible to change the week number such that it is the number week of the month (instead of year).
For example, instead of "2021-07-29", we convert to "2021-07-04" since the 29th week of the year is actually the 4th week of the month.
Quote from the manual
W week of month (1–5) (the first week starts on the first day of the month)
So you can use:
to_char(date, 'YYYY-MM-W')
For e.g 2021-10-18 this yields 2021-10-3 (third week in October)
I've been having a look around but I can't seem to find anything that answers this question. I want to calculate the date for the last week of every month. For example, the date for the last week of April 2021 is 26-04-2021. I want a date, not a week number.
I use Google Big Query, I do have a calendar table I could use to extract year and month.
Thanks,
Emily
Try date_trunc:
SELECT date_trunc(last_day(month1st, month), week(monday))
from unnest(GENERATE_DATE_ARRAY('2021-01-01', '2021-12-01', interval 1 month)) AS month1st;
I have the following data structure:
Then I have used the following Tableau function to convert week number and year to first day of the week:
DATE(DATETRUNC('week',DATEPARSE("w-yyyy",STR([Week Number])+"-"+ STR([year_axis]))))
Issue, is that when it gets to week 1 and year 2021, instead of showing the week 04/01/2021, it aggregates this data to the last week of December (28/12/2020).
Anyone knows why?
Thanks!
Yes, depending upon your locale, tableau starts a week either on Sunday or a Monday. Moreover, if a first day of a year is not Monday, then the dates before first Monday are considered as week 0 of that year.
Use of this calculation is suggested in this case (for newer versions of tableau desktop)
DATE(DATETRUNC('week',
IF ISOWEEKDAY(DATEPARSE("w-yyyy",STR([Week Number])+"-"+ STR([Year Axis]))) =1
then DATEPARSE("w-yyyy",STR([Week Number])+"-"+ STR([Year Axis]))
else DATEPARSE("w-yyyy",STR([Week Number]+1)+"-"+ STR([Year Axis]))
END
))
For those versions of tableau where ISOWEEKDAY is not listed, the following calculation is suggested
DATE(DATETRUNC('week',
IF DATEPART('weekday', DATEPARSE("w-yyyy",STR([Week Number])+"-"+ STR([Year Axis]))) =1
then DATEPARSE("w-yyyy",STR([Week Number])+"-"+ STR([Year Axis]))
else DATEPARSE("w-yyyy",STR([Week Number]+1)+"-"+ STR([Year Axis]))
END
))
If first day of Year is Monday then your calculated field otherwise week+1.
See the screenshot where both calculations are compared. (Note for year 2018)
I hope this solves your problem.
I am trying to get week numbers ( resetting at 1 for each month) as per ISO format for each month in 2019.For example I am interested in getting
All dates in July 2019: week 1 to 4,
All dates in Aug 2019 : week 1 to 4 and so on.
I first created the calculated field (Week_Number_ISO) to get the overall week number in year 2019.I used the following formula;
DATEPART('iso-week',[ Date]) which works as intended.
To get the monthly week number I used the following formula
INT((DATEPART('day',[Created Date])-DATEPART('iso-weekday',[Created Date])+7)/7)+1.
(Idea was to calculate the date of the first day of each week & then divide by 7 and take the integer part)
As per the ISO format, shouldn't July 29 to 31st be a part of week 4 for July?But the formula is showing it as week 5 for July 2019.I feel I am missing something in the formula or am missing something about ISO week number resetting at 1 for each month.
Can someone help me?
Here is an example of the dates in July 2019 and the associated week numbers.
Why would July 28th-July 31st 2019 be considered week 4?