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

Date to Quarter and Year

Stephenw_Keith
7 - Meteor

I have a date column 1/1/2017 that I need to convert to quarter and year 1Q 2017. What is the best way to do that? 

Thanks in advance.

5 REPLIES 5
BenMoss
ACE Emeritus
ACE Emeritus

Probably not the best way to go about this, but I don't think there are any 'quarter' capabilities with alteryx's default date time tools (though James Dunkerlys add on may have this level of detail in).

The following formula should suffice (presuming your date is in the format MM/DD/YYYY)

 

 


IF

tonumber(left([datefield],findstring([datefield],"/"))) < 4 then "1Q "

elseif

tonumber(left([datefield],findstring([datefield],"/"))) < 7 then "2Q "

elseif

tonumber(left([datefield],findstring([datefield],"/"))) < 10 then "3Q "

else "4Q "

endif

+ Right([datefield],4)

 

and if your date format is dd/mm/yyyy then the following should do...

 


IF

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 4 then "1Q "

elseif

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 7 then "2Q "

elseif

tonumber(substring([datefield],findstring([datefield],"/")+1,findstring(right([datefield],length([datefield])-(findstring([datefield],"/")+1)),"/"))) < 10 then "3Q "

else "4Q "

endif

+ Right([datefield],4)

See the attached workflow to see how I have implemented these.

Regards,
Ben

Stephenw_Keith
7 - Meteor

Thanks Ben,

Worked like a charm. Big help. 

tbrown06
6 - Meteoroid

What would this formula look like if my date is in this format yyyy-mm-dd?

Röntgen
5 - Atom

Hi, 

this should work if [date] is a Date-Type:

 

"Q" + ToString(
CEIL(DateTimeMonth([Date])/3)
)

+ " " + ToString(DateTimeYear([Date]))

hcampbe1
5 - Atom

Thanks so much for this string/formula - worked perfectly!

Labels
Top Solution Authors