Generate Series of month and years - date

How do I generate a series of month and year dates which I can use as a parameter to pass to other data tables.
For example, I am currently using:
MonthYearSelector = GENERATESERIES(DATE(2019,1,1), DATE(2019,12,1),30)
However, this generates the following dates:
01 January 2019
31 January 2019
02 March 2019
...
What I want is the following list:
01 January 2019
01 February 2019
01 March 2019
....
MonthYearSelector = GENERATESERIES(DATE(2019,1,1), DATE(2019,12,1),30)

How about something like this?
MonthYearSelector =
VAR Years = SELECTCOLUMNS( {2018, 2019}, "Year", [Value] )
VAR Months = SELECTCOLUMNS( GENERATESERIES(1, 12, 1), "Month", [Value] )
RETURN
ADDCOLUMNS(
CROSSJOIN( Years, Months ),
"Date", DATE( [Year], [Month], 1 )
)
In the above, I use SELECTCOLUMNS just to rename the default Value column name.

Try this out.. It's basically give you start of the month & End of the Month... your choice to use..
Start of Month Dates =
GENERATE (
GENERATESERIES(1,48),
VAR inc = [Value]
RETURN ROW (
"date", DATE(2017,inc,1),
"Month End",EOMONTH(DATE(2017,inc,1),0)
)
)
Check this for details

Related

Power Bi : non-unique value in dateadd()

I'm trying to create a metric to give me the number of request between two relative dates.
I tested this:
Request M =
VAR StartDate = DATEADD('Request'[request_date],-20,DAY)
VAR EndDate = DATEADD('Request'[request_date],0,DAY)
RETURN
calculate(sum('Request'[request_count]),DATESBETWEEN('Request'[request_date], StartDate, EndDate))
And I have the error : "A table of multiple values was supplied where a single value was expected "
My column request_date looks like this :
5 july 2022
5 july 2022
5 july 2022
5 july 2022
6 july 2022
6 july 2022
7 july 2022
...
--> All my dates are present more than once.
So I tried to add a "firstdate", like this:
VAR StartDate = DATEADD(FirstDate('Request'[request_date]),-20,DAY)
VAR EndDate = DATEADD(FirstDate('Request'[request_date]),0,DAY)
This time I have no error, but I don't get the right value. Could you help me please ?
Add a (unique) Date table to your model and setup a one-to-many relation between 'Date'[date] and your 'Request'[request_date]
Then use
Request M =
VAR StartDate =
DATEADD('Date'[date], -20, DAY)
VAR EndDate =
DATEADD('Date'[date], 0, DAY)
RETURN
CALCULATE(
SUM('Request'[request_count]),
DATESBETWEEN('Date'[date], StartDate, EndDate)
)

How to use formatDateTime in Azure Data Factory?

I would like to format the pipeline trigger time in this format:
10-Mar-2021 08:31:59 AM
Here is the code I am using:
#formatDateTime(pipeline().TriggerTime, 'DD-MON-YYYY HH:MI:SS AM/PM')
However the date is coming out in this format:
'DD-3ON-YYYY 08:3I:SS A3/P3'
How can I resolve this?
The formatDateTime function uses the custom date format strings which you can see listed here. A detailed breakdown
dd - the day of the month from 01 to 31. Note this is lower case and this format gives a leading 0. Using d for no leading 0
MMM - the abbreviated name of the month, eg JAN, FEB, MAR. Note this is upper case
yyyy - the year as a four-digit number. Note this is lower case
hh - the hour using a 12-hour clock from 01 to 12. Note this is lower case. As you are using AM/PM it makes sense to have the 12-hour clock rather than 24 (ie 23:00 PM would not make sense). Note this is lower case
mm - the minute from 00 to 50. Note this is lower case
ss - the second from 00 to 50. Note this is lower case
tt - the AM/PM designator. Note this is lower case
So using this information, your code should be more like this:
#formatDateTime(pipeline().TriggerTime, 'dd-MMM-yyyy hh:mm:ss tt')
I have test the expression using a Set Variable activity and got the following results:
EEE : Day ( Mon )
MMM : Month in words ( Dec )
MM : Day in Count ( 324 )
mm : Month ( 12 )
dd : Date ( 3 )
HH : Hours ( 12 )
mm : Minutes ( 50 )
ss : Seconds ( 34 )
yyyy: Year ( 2020 ) //both yyyy and YYYY are same
YYYY: Year ( 2020 )
zzz : GMT+05:30
aa : ( AM / PM )

Given an ISO 8601 week number, get date of first day of that week in LibreOffice Calc spreadsheet

LibreOffice Calc spreadsheet offers a function ISOWEEKNUM to return the standard ISO 8601 week number of the specified date.
I want the opposite.
➠ Given a standard week number, give me the date of the first day of that week (the Monday date).
Passing integers is acceptable. Also nice if able to pass a string in standard format.
Like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42" ) ➝ date of Monday of week 42 in week-based year 2017
Ideally, I would be able to pass a number 1-7 for Monday-Sunday to specify the day-of-week for which I want a date. Something like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 , 1 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42-1" ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( 2017 , 42 , 7 ) ➝ as above, but Sunday
DATE_OF_ISOWEEKNUM( "2017-W42-7" ) ➝ as above, but Sunday
Example:
Formula:
=DATE(B$1,1,$A4*7)+(2-WEEKDAY(DATE(B$1,1,$A4*7)))-7*(ISOWEEKNUM(DATE(B$1,1,1))=1)
Calculate the date of day (weeknumber * 7) in the year.
Correct the day to be weekday Monday.
Correct to 7 days before, if the first day of the year is in the
first ISO weeknumber.

How to get the Date of the first day of a week given a time stamp in Hadoop Hive?

Besides writing a custom UDF to support this issue, is there any known methods of achieving this? I'm currently using Hive 0.13.
Starting with Hive 1.2, you can also do it like this:
select next_day(date_sub('2019-01-01', 7), 'MON')
Output:
2018-12-31
date_sub(m.invitationdate,pmod(datediff(m.invitationdate,'1900-01-07'),7))
This expression gives the exact solution to my question.
Regards,
Boris
This is the easiest and the best solution for fetching 1st day of the week's date:
For Current timstamp:
select date_sub(from_unixtime(unix_timestamp()), cast(from_unixtime(unix_timestamp(), 'u') AS int)) ;
For any given date or column:
select date_sub(from_unixtime(unix_timestamp('2017-05-15','yyyy-MM-dd')), cast(from_unixtime(unix_timestamp('2017-05-15','yyyy-MM-dd'), 'u') AS int)) ;
select date_sub(from_unixtime(unix_timestamp(colname,'yyyy-MM-dd')), cast(from_unixtime(unix_timestamp(colname,'yyyy-MM-dd'), 'u') AS int)) ;
Yes, you can do this without writing a UDF. If you look at at the Hive documentation under datetime functions, there is a function from_unixtime() that takes a unix timestamp and a string pattern. A couple of functions down on the documentation page, there is a link that explains the different patterns you can use in this function. So, from your timestamp, you can extract the day of the week and proceed accordingly.
Example Data:
1445313193
1445313100
1445313146
1445040000
1445040023
1445040111
The first three are Monday, 2015-10-19 and the last three are Friday, 2015-10-16.
Query:
select day_of_week
, date_var
, case when day_of_week = 'Sun' then date_var
when day_of_week = 'Sat' then date_sub(date_var, 6)
when day_of_week = 'Fri' then date_sub(date_var, 5)
when day_of_week = 'Thu' then date_sub(date_var, 4)
when day_of_week = 'Wed' then date_sub(date_var, 3)
when day_of_week = 'Tue' then date_sub(date_var, 2)
when day_of_week = 'Mon' then date_sub(date_var, 1)
else NULL
end as first_day_of_week_date
from (
select from_unixtime(timestamp, 'EEE') day_of_week
, from_unixtime(timestamp, 'yyyy-MM-dd') date_var
from db.table ) A
Output:
Mon 2015-10-19 2015-10-18
Mon 2015-10-19 2015-10-18
Mon 2015-10-19 2015-10-18
Fri 2015-10-16 2015-10-11
Fri 2015-10-16 2015-10-11
Fri 2015-10-16 2015-10-11
So, for today it returns yesterday, which was Sunday, and for last Friday, it returns the previous Sunday, the 11th. I am making the assumption that by "first day of a week", you mean Sunday; if not, you can adjust the code to mean Monday. Hope this helps.

Custom Function - Calculate date of first date of next quarter

I am trying to create a custom function of given a date in Filemaker, I would like it to determine if this week of fiscal year number is within the first week of quarter else it will calculate the first date next quarter. Our Fiscal year starts on July 1
So for defined requirements our FY starts on July 1 and Qtrs are on week # 1, 14, 27, 40 our weeks go from 1-52 and the week starts on Tuesday (Defined as day 3). If FY starts on Monday than the first week will be from Mon-Tues (Therefore a shortweek) then week 2 will be a full 7 day week.
Example---> If I have a date 09/09/2011 that would be week 11 in Q1, therefore since it is not the first week of the quarter I would like the following date for the next Qtr which would be Wk 14 first date of 9/27/2011. So my evaluation needs to determine whether the given date is within the first week of a qtr (weeks 1, 14, 27, 40) or provide the first week of the next qtr.
Also here is the initial CF I was working with from Brian Dunnings site.
https://www.briandunning.com/cf/147
I know this would be developed in filemaker but there maybe something developed in another language which may apply...
Thanks in advance
Try this as your starting point:
Let ( [
startFY = Date ( 7 ; 1 ; Year ( Datefield ) - ( Month ( Datefield ) < 7 ) ) ;
firstTuesday = startFY - Mod ( startFY - 2 ; 7 ) ;
fiscalWeek = Div ( Datefield - firstTuesday ; 7 ) ; //numbering starts at 0
targetWeek = 13 * Ceiling ( fiscalWeek / 13 )
] ;
firstTuesday + 7 * targetWeek
)
Note that the result is always a Tuesday; you may want to adjust this for the boundary cases of fiscal year start and end. The way it works now, you'll get a result of July 30, 2015 for both June 15, 2015 and July 6, 2015.