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.
Solved! Go to Solution.
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
Thanks Ben,
Worked like a charm. Big help.
What would this formula look like if my date is in this format yyyy-mm-dd?
Hi,
this should work if [date] is a Date-Type:
"Q" + ToString(
CEIL(DateTimeMonth([Date])/3)
)
+ " " + ToString(DateTimeYear([Date]))
Thanks so much for this string/formula - worked perfectly!
User | Count |
---|---|
19 | |
15 | |
15 | |
9 | |
8 |