How do I get the week ending date from week no. in GCP ?
SELECT
Session,
Store_Num,
Store_Name,
EXTRACT (WEEK(Monday) from Route_Date) as Weekno,
AVG(Planned_DPH) as Avg
FROM `TABLE`
WHERE Route_Date between current_date() - 60 and current_date()
and Store_Num = 8881
GROUP BY 1,2,3,4
ORDER BY Weekno
You can get the first day of weekno with PARSE_DATE function and %W format string.
%W - The week number of the year (Monday as the first day of the week) as a decimal number (00-53).
And by adding 6 more days to the first day of the week, you will get the week ending date.
Consider below sample query.
WITH sample_data AS (
SELECT DATE '2022-11-10' AS Route_Date
)
SELECT *,
PARSE_DATE('%Y%W', Year || Weekno) AS startday_of_weekno,
PARSE_DATE('%Y%W', Year || Weekno) + 6 AS lastday_of_weekno
FROM (
SELECT EXTRACT(WEEK(Monday) from Route_Date) as Weekno, -- 45
EXTRACT(YEAR FROM Route_Date) AS Year,
FROM sample_data
);
Query results
Related
Basis on below data I want to add a calculated column with Week Description
I've done it in excel by typing it manually.
Also my week is starting from Thursday and ends on Wednesday hence I've Used this function to get the weekday WEEKDAY('Calendar'[date],14)
Requesting you to help me with a dax code which can be used to create a new calculated column with week information as shown below in third column.
The logic would be : If the date is current week then the value will be "This Week" else if the
date is in last week then "This Week -1" else if the date is in last to last week then "This Week - 2" and so on.
The weekday can be calculated as following:
Weekday = WEEKDAY([Date] + 3)
We do a shift of 3 days to make Thursday the start of the week
Next, we get the WeekDesc in two steps, frist we calculate the difference between now and the date in weeks and as second step we use an if statement to create the correct sting (and logic).
WeerDesc =
var weeksPast = DATEDIFF(now(), [Date] + 3,WEEK)
return if ( weeksPast = 0, "This Week", "This Week" & weeksPast)
As you can see you can use variables in your DAX, I would recommend using them to keep the overview.
Enjoy
We can do this also in this way (as a measure if you need only label to display on rows):
DayOfWeek = WEEKDAY(SELECTEDVALUE('CAL'[Date]),14)
DiffToToday = DATEDIFF(SELECTEDVALUE('CAL'[Date]),TODAY(),DAY)
Label = CONCATENATE("This Week", (DIVIDE( CAL[DiffToToday] + CAL[DayOfWeek],7) -1) *-1 )
Of course, we can do all steps in one measure.
I need to make a total for each of the months based on the working days.
So far i have working days set as 1 if the day in the month is during Monday - Friday and 0 for Saturday and Sunday. I now need to total up the 1's and make it so that it is a single value for the month.
E.g Going the weekdays is 1 and weekend is 0, January will have 22 days on each row on the table in the data mode - January 1 = 232 January 2 = 22 etc. so i can use it to divide against my target which is set to the 1st of every month.
How can i do this??
try this. i haven't tested it.
=GROUPBY( FILTER(table, table[Working_Day]=1) , table[Month], ["new col", SUMX( CURRENTGROUP(), table[Month_Order])])
filter gives working day 1's data as table,then group by performed by month, then month order has been added and returns table.
What is the opposite of EOMONTH()? I am trying to find the beginning date of 12 months ago. Would it be EOMONTH(Current Date,12)-1?
Any direction would be great. TIA
To find the beginning of a month, go to the end of the month before and add a date to it (not sure if I understand the question)
Start of month one year ago = EOMONTH(TODAY(),-13)+1
In general, the opposit function is STARTOFMONTH:
=STARTOFMONTH('Date'[Current Date])
If you want to get the first day of the month 12 months ago:
= STARTOFMONTH ( DATEADD ( 'Date'[Current Date], -12, MONTH ) )
This measure will return the first date of the same month a year ago (i.e., for 2018-09-22, it will return 2017-09-01). Current month is included, so you will get a total of 13 months. If you need only 12 months total:
= STARTOFMONTH ( DATEADD ( 'Date'[Current Date], -11, MONTH ) )
If you are trying to compute something over a rolling 12 months period, this article should help:
12-month Rolling Average in DAX
In DAX, you could also use
= DATE(YEAR(Dates[Date])-1, MONTH(Dates[Date]), 1)
This backs up one year, keeps the month, and returns the first day of that month.
There is no straight opposite function for EOMONTH() in DAX. But you can still use EOMONTH() to get the first date of a month.
Last date of a month
= EOMONTH(Leaves[LeaveStart]
First date of a month
= EOMONTH(Leaves[LeaveStart],-1)+1
You can also just use 1 in place of date to get first day of a month, like:
= DATE(YEAR(Leaves[LeaveStart]), MONTH(Leaves[LeaveStart]), 1)
Please note that STARTOFMONTH() is opposite function for ENDOFMONTH() not for EOMONTH().
Date WeekNum Month Year
5/2/2018 Week 1 May 2018
6/1/2018 Week 1 June 2018
How would you get the WeekNum from the Date?
The WeekNumber needs to be week number of the particular month and not the Year.
One approach would be to take the day of the month and divide by seven:
WeekNum = ROUNDUP(DIVIDE(DAY(TableName[Date]), 7), 0)
You can use the next formula
1 + WEEKNUM(usage_users[row_date]) - WEEKNUM(STARTOFMONTH(usage_users[row_date]))
This gives you the number of the week.
basically you need to use STARTOFMONTH and WEEKNUM together:
Here is a good video explaining it also:
https://www.youtube.com/watch?v=Oq5WOmo94_Q
I have a date field coming form source paid_date and i want it to convert as
trunc(next_day(sysdate-1,'MON')).. I need to get the NEXT_DAY here and the filed data type is date-time.
Please share your inputs.
Unfortunately, as of now, there is no NEXT_DAY equivalent in Informatica. So you have to calculate it like this in expression.
TRUNC(
ADD_TO_DATE(
SYSDATE,
'DD',
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7
)
)
Explanation:
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7 - Calculates the number of days till next Monday.
ADD_TO_DATE(SYSDATE,'DD',...) - Adds the above no. of days to the input date
In this case you can use Add_To_Date function. Using this function you can get your exact date or month or year.
Formats of defining date,
Date – DD, DDD, DY and DAY
Month – MM, MON and MONTH
Year – YY, YYY and YYYY
Hour – HH, HH12 and HH24
Minute – MI
Seconds - SS
Syntax : ADD_TO_DATE (date_column, format, value)
Example: ADD_TO_DATE (Date, ‘DD’, 10)
Result:
10/01/2016 - 20/01/2016
As the format is provided as ‘DD’ and value as 10, the dates are displayed by increasing 10 days. This logics stands for date, month, year, minute, hour or seconds whatever defined in the syntax. To decrease the date value just add negative number (-10).
For you to get next day, just define
ADD_TO_DATE (Your column, ‘DD’, 1).
For more details on informatica just visit my blog,
http://etlinfromatica.wordpress.com/