ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Issue with Date Time Filter and Functions

cjaneczko
13 - Pulsar

I am using the following formula to pull the last 6 months of data starting from the prior month backwards. Essentially I want a rolling 6 months. For some reason though its including data from the first day of this month and does not include data from the first day of July. The data starts on 7/2/2025 and goes through 1/1/2026. I want it to be 7/1/2025 - 12/31/2025. I was using the datetimefirstofmonth() in the formula first and it was giving the same data. I thought maybe it wasnt working properly so i created a column for the first of month using datetimefirstofmonth() to make sure the date is correct. What am I doing wrong and how can I back it out 1 more day.

 

[budat_mkpf] >= DateTimeAdd([First of Month], -6, "months")
AND 
[budat_mkpf] < [First of Month]

 

cjaneczko_0-1768312269642.png

cjaneczko_1-1768312347303.png

 

7 REPLIES 7
jrlindem
13 - Pulsar

If you always need it to be the first of the current month, then back 6 months, I would use DateTimeTrim() like this:

jrlindem_0-1768312749104.png

 

You can combine the formulas into one if you want, but I kept separate to illustrate. For the last day of the interval, you can just subtract 1 day from the First_Day_Current_Month field.

 

 

Hope this helps, -Jay

 

cjaneczko
13 - Pulsar

Need it to not include the current month. So it would be the last day of the prior month back 6 months. So 12/31/2025 - 7/1/2025 in this instance.

jrlindem
13 - Pulsar

@cjaneczko Using the same concepts though you can just backdate further to the right interval?  I can re-mock if you need, but let me know, -Jay

cjaneczko
13 - Pulsar

The formula I've got looks just like the one you posted. But for some reason its offset by a day. Its pulling 7/2/2025 - 1/1/2026. Should be pulling 7/1/2025 - 12/31/2025. 

cjaneczko
13 - Pulsar

I had to update the formula to the following in order for it to work. FirstofMonth was not working at all.

 

[budat_mkpf] >= DateTimeAdd(DateTimeLastOfMonth(), -7, "months")
AND
[budat_mkpf] < DateTimeAdd(DateTimeLastOfMonth(),-1,'month')
jrlindem
13 - Pulsar

Right, when you use the following formula:

 

DateTimeAdd([Date],-6,"months")

 

If Date = 7/15/2025 for example, taking 6 months away isn't truncating to the first day of the month, it's taking away the months but leaving the days.  So you have to handle that "first of the month" separately.

That's why I started with the: DateTimeTrim([Date], "month")

 

To get it to truncate to the first day.  Sounds like you got it figured out though?  -Jay

Pilsner
13 - Pulsar

Hello @cjaneczko,

 

I've taken a look at your formula, and I do agree that it initially looks like it should work. 

 

Having taken a closer look, I believe that the issue lies within the data types. Your column [First of Month] and the formula DateTimeAdd([First of Month], -6, "months"), both result in "DateTime" data types, whereas your [budat_mkpf] column is a Date data type. This appears to mean that they behave differently and actually have a hierarchy / ordering between them. I did some testing and found the following:

This was the input data I used for the tests:

Pilsner_0-1768577310822.png


1) Initially looking at the data my assumption was that 2026-01-02 = 2026-01-02 00:00:00 however that turned out not to be the case.

Pilsner_1-1768577729862.png



2) This first result suggested that the date / date time, must have a hierarchy. I filtered to values where the date time was less than the date:

Pilsner_2-1768577843959.png


3) And then to values where the date was less than the date time:

Pilsner_3-1768577873158.png


This then seemed to confirm my theory. It appears as if the date is treated as coming before ALL date time values on that given day, even when the time is 00:00:00. 

 

With this new understanding of the date vs date time ranking in mind, I can now see why your initial formula didn't quite behave as expected. The easiest way I found to get around this was to simply convert your Date time values, into dates. You can do this by wrapping the expressions in a ToDate() function, from within your filters formula:

Pilsner_4-1768578070334.png
Appreciate this may seem a little strange at first so I have attached the workflow containing both my testing and solution below. I hope this all makes sense but please let me know if you have any questions. 

Regards - Pilsner

Labels
Top Solution Authors