How to horizontally use an arrayformula to increment the week number based on a range of days? - date

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) ) )

Related

Group date by week number in the form YYYY-MM-WW

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)

Group by week of the year in Tableau

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.

How do sum if the date is greater than 10 days from and including the upcoming Sunday?

I have 2 rows. One row has dates and the other row has numbers.
I want to build a google sheet formula that allows me to sum 10 days after the next Saturday. So if today is Monday 7/22/2019, I want the sum from Sunday (7/28/2019) through and including the next 9 days. If today was Tuesday (7/23/2019) the formula would return the same result, because it's always starting from the next Sunday.
Another way I'm looking at it is the sum of the 10 days after the current week number since google has the weeks beginning with Sunday.
Thanks for your help.
My current array formula is using weeknumber:
sumifs(rowwithnumbers,weeknum(rowwithdates),">"&weeknum(today()),weeknum(rowwithdates),"<="&weeknum(Today())+2))
but that gives me the next 14 days, which is close but not exactly what I want. I don't want to sum the next 2 weeks after the current week, I want to sum the next 1o days after the current week.
=ARRAYFORMULA(SUM(INDIRECT(
ADDRESS(2, MATCH(VLOOKUP(WEEKNUM(TODAY())+1, {WEEKNUM(ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))),ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))}, 2, 0), 1:1, 0), 4)&":"&
ADDRESS(2, MATCH(VLOOKUP(WEEKNUM(TODAY())+1, {WEEKNUM(ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))),ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))}, 2, 0), 1:1, 0)+9, 4))))
Although you could put it all in one formula, I think for clarity and debugging it would be good to use a separate sheet (call it "Dates") for the date calculations. Then use the results of the date calculations as arguments to your SUMIFS function.
In that case, the date calculation for the next Saturday is:
=IF(WEEKDAY(TODAY()) = 7, TODAY() + 7, TODAY() + 7-WEEKDAY(TODAY()))
That checks if today is a Saturday, and if it is, uses today plus 7 days. Otherwise, it just adds the number of days until the upcoming Saturday. If you store that cell in B2, for example, then you can calculate your end date with a simple:
=B2+10
If you store that in C2 of the "Dates" Sheet, and your value list is in a Sheet called "Values" with dates in column A and the numbers in column B, then your sum function is:
=SUMIFS(Values!$B:$B,Values!$A:$A, ">= " & Dates!B2, Values!$A:$A, "<= " & Dates!C2)
Here is a link to a Google Sheet showing all of above: Google Sheet

SSRS How to get 1st date in month with a 1 day lag?

There are plenty of solutions explaining how to get 1st day of the month of the current month or previous month. But I need my formula to be dynamic to factor in today's date -1 day lag.
For example, today on 8/1/2018 I do not want my parameter to display 8/1/2018, I would like it to have a 1 day lag so it is still displaying 7/1/2018.
Thank you in advance.
This expression will return the 1 of previous month
=dateadd("m",-1,dateserial(year(Today),month(Today),1))
This expression will return the 1 of current month
dateadd("m",0,dateserial(year(Today),month(Today),1))
Combining with DatePart to calculate whether current day is 1 of month then you can use SWITCH like so
=Switch(
DatePart("d",Now)= 1, dateadd("m",-1,dateserial(year(Today),month(Today),1)),
DatePart("d",Now)> 1, dateadd("m",0,dateserial(year(Today),month(Today),1))
)
Change the field's textbox properties like so

Crystal Reports: Display date range (month, first day of month, year to month, last day, year) based on field value

I need to display a date range based on the month before a date in a field. For example, if the date value (DOCDATE) is 6/6/18, I'd like the range to display as:
5/1/18 to 5/31/18
I was able to use LASTFULLMONTH with minimum and maximum constraints and it works fine for records in the current month, but I need to use DOCDATE as a control.
You can achieve this with the following formulas.
Note the formula names, because they are partly dependent on each other.
{#prevMonth}
Gets the previous month by subtracting one month from {#DOCDATE}
DateAdd("m", -1, {#DOCDATE})
{#startDate}
Gets the start-date (first day of previous month) by creating a new date from the year and month of {#prevMonth} and day 1.
Date(Year({#prevMonth}), Month({#prevMonth}), 1)
{#endDate}
Gets the end-date (Last day of previous month) by creating a new date from the year and month of {#DOCDATE} and day 1, minus one day
Date(DateAdd("d", -1, Date(Year({#DOCDATE}), Month({#DOCDATE}), 1)))
{#displayRange}
Shows the range.
CStr({#startDate}) & " to " & CStr({#endDate})