Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Formula to calculate last day of February each year

sophievanluin
7 - Meteor

Hi there,

 

I'm building a workflow where I need to make several calculations which contain dynamic dates.

 

The formulas I used was:

 

[Feb Cur Year]

IF [Start] > DateTimeFormat(DateTimeAdd([Reporting Date],0, "years"), "%Y-02-29") THEN 0

ELSEIF !IsNull([End]) AND [End] <DateTimeFormat(DateTimeAdd([Reporting Date],0, "years"), "%Y-02-29") THEN 0

ELSE [FTE]*100
ENDIF

 

[Feb Next Year]

IF [Start] > DateTimeFormat(DateTimeAdd([Reporting Date],1, "years"), "%Y-02-28") THEN 0

ELSEIF !IsNull([End]) AND [End] <DateTimeFormat(DateTimeAdd([Reporting Date],1, "years"), "%Y-02-28") THEN 0

ELSE [FTE]*100
ENDIF

 

In the formulas above [Start] represents the starting date and [End] the ending date. [Reporting Date] represents that last day of the month that I would like to report on. So all data is related to this date.

 

 

See below some example data:

NameStartEndReporting DateFTEFeb Cur YearMar Cur YearFeb Next YearMar Next Year
Person 12020-01-012021-02-282020-11-3011001001000
Person 22020-01-012021-01-012020-11-300.8808000

 

 

In the scenario above, 'Feb Cur Year' is 2020-02-29 and 'Feb Next Year' is 2021-02-29

 

Now I've manually written the last days of the months in the formula tools, however, this is not applicable if I take for example 2021 and 2022, since both years go till the 28th.

 

How do change my formula so it automatically picks the last day of February for that year, so that I don't have to change it manually?

2 REPLIES 2
JosephSerpis
17 - Castor
17 - Castor

Hi @sophievanluin you can use the function datetimetrim which has the arguement of lastofthemonth so you could add that into your formula. Attached a workflow that use the datetimetrim function added to your formula.

MarqueeCrew
20 - Arcturus
20 - Arcturus

@sophievanluin 

 

Did you know that March 1st is the day after the last day of February?

 

If you have a known YEAR (string),

 

DateTimeAdd([Year]+"-03-01",-1,"Days") 

 

That is the last day of February ...

 

Cheers,

 

mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Labels
Top Solution Authors