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

Month to Date and Year to Date in DB

Mansenie
7 - Meteor

Running into issues using in DB tools. I need to get the month to date average and the year to date average using in DB. I have tried to use (datetimeadd and datetimefirstofmonth) but it did not work using Formula in DB. Are there any work arounds i am not thinking of ?

5 REPLIES 5
BrandonB
Alteryx
Alteryx
You can use a formula to set each date to the first of that month and then summarize in dB and group by that date field in order to get the monthly value and then apply the same logic to get the yearly.
Mansenie
7 - Meteor

Right that is what i am trying to do but i can't figure out the syntax to get that first of the month or first of the year.

danilang
19 - Altair
19 - Altair

Hi @Mansenie 

 

The syntax that you use in-DB executes on the server and is dependent on the specific database you're connected to.  Which one are you using, Oracle, SQL server, Teradata, etc?

 

Dan   

Mansenie
7 - Meteor

I am using teradata and IBM DB2.

danilang
19 - Altair
19 - Altair

Hi @Mansenie 

 

Teradata uses Extract to return the month and year as integers

 

SELECT EXTRACT(YEAR FROM CURRENT_DATE);  
EXTRACT(YEAR FROM Date) 
----------------------- 
        2016  
SELECT EXTRACT(MONTH FROM CURRENT_DATE);  
EXTRACT(MONTH FROM Date) 
------------------------ 
          1        

 

 

Dan

Labels
Top Solution Authors