Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Filtering Current Month

ashaygnayak
6 - Meteoroid

Hi, 

I have a workflow which is based on a ODBC table with transactions from over 5 years. I want to prepare a daily report for the current month.

I have taken out the year and the month from these transaction dates as a filter to take out report for the current month. I applied the filter month and year manually. Is there a way to select the current month and year automatically. 

 

I tried applying DateTimeYear(DateTimeNow()) formulas but i am getting a parse error. 

ashaygnayak_0-1627529579872.png

 

4 REPLIES 4
BrandonB
Alteryx
Alteryx

Your parse error could be due to data type differences. You are correct that DateTimeYear(DateTimeNow()) will return 2021. Maybe wrap this with a ToString(), or wrap your column with ToNumber()

 

For example

ToNumber([Year]) = DateTimeYear(DateTimeNow()) 

 

in a filter tool

 

 

atcodedog05
22 - Nova
22 - Nova

Hi @ashaygnayak 

 

Additionally, as @BrandonB mentioned you can also compare the current month on the below way.

 

ToNumber([Month]) = DateTimeMonth(DateTimeNow())

 

Hope this helps : )

RolandSchubert
16 - Nebula
16 - Nebula

Hi @ashaygnayak ,

 

as @BrandonB already said, it seems to be a  data type problem - DateTimeYear(DateTimeToday()) and DateTimeMonth(DateTimeToday()) both return numeric values, while the fields [Year] and [Month] seem to be of type string.

 

An additional suggestion: You could use a Dynamic Input tool and select only current month's data from the database - depending on the size of your database table, this could speed up the process. 

 

In your Workflow, you would replace the Data Input tool by the Dynamic Input tool:

 

2021-07-29_08-30-29.jpg

 

The SQL query in the Dynamic Input tool would be like this:

 

2021-07-29_08-27-19.jpg

 

In "Modify SQL Query" you can add your current year/month to the SQL:

 

2021-07-29_08-28-24.jpg

 

Hope this is helpful in any way.

 

Best,

 

Roland

atcodedog05
22 - Nova
22 - Nova

Hi @ashaygnayak 

 

Adding to @RolandSchubert response similar to the above approach.

 

You can also directly implement it in the SQL query itself that way it will be extracting only required data and not complete data.

 

Where Year=YEAR(CURDATE()) and Month=MONTH(CURDATE())

 

You can use cast() if datatype needs to be changed

 

https://www.w3schools.com/sql/func_mysql_year.asp

https://www.w3schools.com/mysql/func_mysql_month.asp

https://www.w3schools.com/sql/func_sqlserver_cast.asp

 

Hope this helps : )

Labels