How to get last day of previous month in DataStage? - datastage

I explored all the functions available in the transformer, but I couldn't find the exact function to get the last day of the previous month in standard format, i.e. dd/mm/yyyy. Please help me in this regard.
The field that needs to appear is in the COL_C field.
enter image description here
inside it I can't put anything that returns me this result

You can use DateOffsetByComponents to substract the current day.
Cut out the day part from your date and substract it with above function.
i.e. 16/12/2022 - 16 = 30/11/2022

Related

Difference between previous and current month

I'm trying to calculate the difference between current month and previous month.
The date field in my DB called C_DATE (dd/MM/YYYY), and I'm using in my sheet a date filter in the format: Year(C_DATE)&'-'& Num( Month(C_DATE),'00'). So when the user choose month (for example 2022-05), he will see the difference in the data between May and April.
I've already tried to calculate by:
count ({<Answer_num={">=6"}, C_DATE={">=$(=(MonthStart(Max(C_DATE))))<=$(=(MonthEnd(Max(C_DATE))))"}>}Answer_num) -
count ({<Answer_num={">=6"}, C_DATE={">=$(=(AddMonths( MonthStart(Max(C_DATE)),-1)))<=$(=(MonthStart(Max(C_DATE)))))"}>}Answer_num)
but i'm getting wrong outcome. is it maybe because of the date filter format? What can I do?
Thank you!
I think this is a matter of getting the date format correct and using the proper set operator. This may work:
=Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))<=$(=Date(MonthEnd(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
-
Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(AddMonths(MonthStart(Max(C_DATE)),-1), 'DD/MM/YYYY'))<=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
This adds the =Date(..., 'DD/MM/YYYY') expression to the set expressions so that the formatting matches the format of the [C_DATE] field. We also add the * set operator so that we get the intersection between the selection ($) and our ">=...<=..." set expression.
I'm sort of guess on the use of the intersection operator, it could be that the union operator (+) is the correct one to use in this case.

Google Sheets - IF Statement - Null date (1/1/2500) workaround

I am working on a large nested IF statement that checks several validation points for each row of my sheet. There are several date validations, including chronological order and certain fields not being future dates. However, our system requires that if we must null any dates for processing, that date becomes 1/1/2500, and no matter what I do I cannot seem to get the formula to ignore this date when accounting for future dates or chronology.
//The date cannot be later than the current date - I want this to ignore 1/1/2500
IF(K1<>1/1/2500,"",IF(AND(K1>TODAY()),"Date A cannot be future date",""))
//The two dates must be in chronological order, also ignoring 1/1/2500
IF(U1<>1/1/2500,"",IF(AND(U1>AA1,AA1),"Date A, Date B should be in chronological order",""))
The above approach does not seem to recognize 1/1/2500, even though I got it to work with other dates.
I also tried going with >12/31/2099 (ignore any date greater than 12/31/2099) but it just ignores every date.
Any help would be appreciated.
It looks as though it is failing because K1 is compared to 12/31/2099.
If you use an expression like this in a formula, it will interpret it as an arithmetic expression 12 divided by 31 divided by 2099, which is a very small number, so the greater than test will always be true.
Try starting the formula with Date to convert a year, month, and day into a date.
If(K1>date(2099,12,31)
and you should get the right answer.
See my previous answer for Excel.

How do we calculate difference and percent difference between two columns in tableau

]Difference and percent Difference must be calculated.
I cannot do Apr20-MAy20 because it is not always the same. I need to show the current month and previous month
So I did a relative filter to just show the current month and previous month.
So the difference of two columns should automatically change when the month changes.
Now how do I get the same month of prior year, how do I filter ?
I also need to calculate the difference of current year same month and previous year same month.
Thank you in advance for any help!
When I do table across difference, the difference value is overwriting the existing May and Apr month values as the below screen shot, how to show the difference in another column
Currently:
Below is Expected:
Sounds like you should create a custom filter for the dates. You want:
This month this year
This month last year
Last month this year
There are a number of ways you could do this. I'll give one example and will assume there aren't any future dates in your data set.
[DateFilter]: DATETRUNC('month',[YourDateField])>=DATETRUNC('month',DATEADD('month',-1,TODAY())) OR DATETRUNC('month',[YourDateField])=DATETRUNC('month',DATEADD('year',-1,TODAY()))
Put the to the filters shelf, set to True, and it should keep the months you want.
Then you can just use the standard table calculations to calculate Difference and Percent Difference.
Note, the formula isn't tested, just typed directly into here, let me know if it doesn't work
Based on your comments look at creating separate calculations for to YoY / MoM / etc calculation. That also means creating calculated fields to isolate the Current Month, Previous Month, etc.
For example, the current month:
[isCM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',TODAY())
The previous month:
[isPM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',DATEADD('month',-1,TODAY()))
Then month on month, something like:
[MoM]: (SUM([Measure])*INT([isCM]))/(SUM([Measure])*INT([isPM]))
To make your table check this article about using the placeholder technique to create tables in Tableau

DATE FORMATTING - COGNOS

I am using cognos version 10 and I need my dates to display in this format 'yyyy-mm' but it is showing dates like '2014-04' as '2014-4' so it is reading the dates out of order by producing '2014-11' first because it starts with a one. I need to add a zero to those double digit integers that way the months(specifically) will display in order.
here's an the code I've created in attempt:
_year( start_date ) ||'-'|| _month( start_date )
IF(_month(start_date) > 10)
THEN('0' +_month(start_date))
Short answer: Use yyyy-MM.
Your question lacks a lot of detail, so my response is based on considerable guess-work.
Are you asking about formatting, or do you want to transform the values? Formatting can be done without code. The code for your data item should be start_date.
Is this for a List column body? Where do you enter your format (yyyy-mm)? Are you using the Data format property?
In the Data format dialog, if you can't find another setting that will do what you want, you can enter a pattern into the Pattern property. If you look at the tips at the bottom of the Data format dialog, you'll notice that using yyyy-mm would give you a four digit year, a hyphen, and a two-digit minute. Perhaps you should try yyyy-MM. It works for me.
As for sorting: Even if you used yyyy-M for the pattern, 2014-04-22 (displayed as 2014-4), should sort before 2014-11-01 (displayed as 2014-11). The only reason the sort would be wrong is if it is using some other data besides the dates.

Number of days between past date and current date in Google spreadsheet

I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.