Free Trial

Alteryx Designer Desktop Discussions

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

Need to calculate & filter Date range

anonymous008_G
8 - Asteroid

Hi – I want to filter last 3 months of date range from input date column using As of Date column value. How would I do that in filter tool. I am not able to write the correct formula. Please. help me in this. 

 

In the expected output if my as of date is 06/30/2024 then I am expecting data to be filter from March month end to Jun month end i.e 03/31/2024 to 06/30/2024.

 

Input data:-  
    
acct_idinput_dateinput_valueAs of Date
1005/28/2021-50000008.26/30/2024
1007/22/2021-50000006/30/2024
1008/11/2021-385000006/30/2024
1003/31/2024375000006/30/2024
1004/10/202410000006/30/2024
1004/22/2024-10000006/30/2024
1004/30/202410000006/30/2024
1005/2/2024-10000006/30/2024
1005/15/20249800006/30/2024
1005/25/2024-72999006/30/2024
1006/30/202473001006/30/2024
1006/30/202472199086/30/2024
1006/30/2024-73001006/30/2024
1006/30/202355100000.26/30/2024
1006/30/2023551000006/30/2024
1006/30/2023-0.096/30/2024
    
Expected Output:-   
    
acct_idinput_dateinput_valueAs of Date
1003/31/2024375000006/30/2024
1004/10/202410000006/30/2024
1004/22/2024-10000006/30/2024
1004/30/202410000006/30/2024
1005/2/2024-10000006/30/2024
1005/15/20249800006/30/2024
1005/25/2024-72999006/30/2024
1006/30/202473001006/30/2024
1006/30/202472199086/30/2024
1006/30/2024-73001006/30/2024

 

 

7 REPLIES 7
DataNath
17 - Castor
17 - Castor

Hey @anonymous008_G, you'll want to use something along the following lines. If you don't want it to be inclusive then just remove the '=' so that it's purely '>':

 

DateTimeParse([input_date],'%m/%d/%Y')
>=
DateTimeAdd(DateTimeParse([As of Date],'%m/%d/%Y'),-3,'month')

 

Last3MonthsFilter.png

anonymous008_G
8 - Asteroid

@DataNath -- works as expected. Thanks a lot

anonymous008_G
8 - Asteroid

Hi @DataNath  – Also one more help needed regarding the same topic. I need to filter the data with one more condition that from the last 3-month range data I need to filter it with condition as wherever input code =41 and input date should -3-month end date of as of date. In this case this should be 03/31/2024.

I tried this syntax but output generating with 03/31/2024 and 06/31/2024. I need only 03/31 date in my final table.

[input_type_id]=41 OR (DateTimeParse([input_date],'%y/%m/%d')

=

DateTimeAdd(DateTimeParse([As of Date],'%y/%m/%d'),-3,'month'))

DataNath
17 - Castor
17 - Castor

Hey @anonymous008_G, without seeing your exact data (the example provided above doesn't have an [input_type_id] field), it sounds like you'll want to add this to the expression with an AND operand. Something like:

 

[input_type_id] = 41
AND
DateTimeParse([input_date],'%m/%d/%Y')
>=
DateTimeAdd(DateTimeParse([As of Date],'%m/%d/%Y'),-3,'month')
anonymous008_G
8 - Asteroid

Hi @DataNath - Apologies, i though now sample data is not needed. Below is sample data after using above custom filter which is filtering last 3 months data using as of date column. now i want to use one more custom filter and condition would be input_type_id is 41 and date would last quarter-end date of as of date column value. since as of date is 06/30/2024 then our code should filter for 03/31/2024. this is my requirement. 

acct_idinput_type_idinput_dateinput_valueAs of Date
1000113/31/202420000006/30/2024
100053/31/20243000006/30/2024
1000204/18/202455000006/30/2024
1000133/31/2024654986/30/2024
1000413/31/202418154986/30/2024
1000116/15/20241755147.46/30/2024
100055/30/20241694796.86/30/2024
1000206/30/20241634446.26/30/2024
1000136/30/20241574095.66/30/2024
1000416/30/202415137456/30/2024
1000113/31/20241453394.46/30/2024
100053/31/20241393043.86/30/2024
1000203/31/20241332693.26/30/2024
1000133/31/20241272342.66/30/2024
1000414/22/202412119926/30/2024
1000116/30/20241151641.46/30/2024
100056/30/20241091290.86/30/2024
1000206/30/20241030940.26/30/2024
1000136/30/2024970589.66/30/2024
1000415/22/20249102396/30/2024
1000323/31/2024849888.46/30/2024

 

DataNath
17 - Castor
17 - Castor

Ah ok @anonymous008_G, I see you're going for quarter ends now. In that case I think the following ought to work:

 

[input_type_id]=41
&&
DateTimeParse([input_date],'%m/%d/%Y')
=
ToDate(DateTimeTrim(DateTimeAdd(DateTimeParse([As of Date],'%m/%d/%Y'),-3,'month'),'lastofmonth'))
anonymous008_G
8 - Asteroid

@DataNath - Awesome, thanks a ton. 

Labels
Top Solution Authors