Calculate the date of the previous month and the date before previous month using current date (data flow, ADF) - azure-data-factory-2

I have a date column which is the first day of each month (eg, 2020-01-01), I want to calculate the date of the previous month (eg, 2019-12-01) and the date before the previous month (eg, 2019-11-01). In the expression builder, do we have any function to handle it? Thank you

You can use subMonths function, something like:
subMonths(toDate('2020-01-01'), 1)
subMonths(toDate('2020-01-01'), 2)

Related

SQL if last day of pervious month has value change the beginning date of next month to start from that day

Need help with this sql code, I would like to roll back start day of new month if last day of pervious month has values.
Thanks
I would suggest nesting EOMONTH() in an IF statement.
Not sure what table(s) you're working with, but general layout would be:
IF(MAX(date_column) = EOMONTH(MAX(date_column), MAX(date_column), new_date)
Reference for EOMONTH():
https://www.sqlservertutorial.net/sql-server-date-functions/sql-server-eomonth-function/

Amazon Redshift- How to get start date of the Week from existing daily date field from the table?

I am trying to get start date of the week from existing daily date field from the same table. For example daily dates from 05/08/2022 to 05/14/2022 , the start of the week date output need to come as 05/08/2022 for all days in the week. week start on Sunday.
Also similar thing require to first date of the Month and quarter(3 month division)
The date_trunc() function performs this operation - https://docs.aws.amazon.com/redshift/latest/dg/r_DATE_TRUNC.html

How to get the data for the last 12 months and split and month-wise in HIVE?

Table format for the date column is "yyyyMMdd" and I'm using the following functions to convert into standard format so that HIVE day, months and year can be performed to get the respective values.
(from_unixtime(unix_timestamp(cast(created_day as STRING) ,'yyyyMMdd'), 'yyyy-MM-dd'))
To get the current year data, I would subtract the year obtained from all the records with the year returned by the current date and if it return zero, then it falls in this year.
(year(current_date()) - year(from_unixtime(unix_timestamp(cast(created_day as STRING) ,'yyyyMMdd'), 'yyyy-MM-dd'))) = 0
Problem: If the current date falls in January, I would get only January data month, but i need to get the data from February(last year) to January(current year)?
Also I need to scale this to obtain the last 24 months.
I always set my date range parameters outside of Hive and pass them as arguments as this lends itself to reproducibility and testability.
select <fields> from <table> where created_day between ${hiveconf:start_day} and ${hiveconf:end_day}

How do I summarise month to date forecast for current month in Power Pivot?

I have a table in a data model that has forecast figures for the next 3 months. What I want to do is to show what the forecast number for the current month to date is.
When I use the DATESMTD function like this:
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]),DATESMTD(DateTime[DateKey]))
I get the last month of my data summarised as a total. I assume that is because the DATESMTD function takes the last date in the column and that is 3 months away.
How do I make sure I get this current month MTD total rather then the end of the calendar? The formula should be clever enough to realise I am in May and want the May MTD not the August MTD.
Any ideas?
The way to do this is to do this:
Forecast_Transaction_MTD:=CALCULATE(sum('ATO Online'[2017 Transaction Forecast]), DATESINPERIOD('ATO Online'[Current Year],TODAY(),-day(TODAY()),day))
the last -day(TODAY()) gets the day number for the current day and subtract it from today's date. So, today is the 25 May. the -day(TODAY())),day)) extracts the day (25) and subtracts it from the current date to get me to the 1 May.
The rest of the formula just adds the total for the dates.

Calculation with WEEK in oracle

I am comparing two dates in oracle where I stuck at one point in which I have to compare my week with the current week.
Suppose today is 05-Jan-2015 and it's a first week and input date is 29_Dec-2014 and I'm executing below statement to compare:
ld_week BETWEEN FOCUS_WEEK-4 AND FOCUS_WEEK-1
where:
ld_week is the week from input date (last week of current year)
focus_week is week from current date (first week of next year)
hence (52 BETWEEN (1-4) AND (1-1)) always fails.
I am using below function to calculate the week.
FOCUS_WEEK := to_number(to_char(to_date(focus_day),'WW'));
Please let me know how to deal with it.
Your question is a bit vague. I believe you want to try
trunk(date '2014-12-29', 'd')
between
trunk(sysdate - 4*7 , 'd') and
trunk(sysdate - 1*7 , 'd')
With trunc(date, 'd') you obtain the start date of a week.