There are a few ways to format your dates into quarters:
Select Quarter(<date>) will result in a date field of the first day of the quarter.
EX: 03/07/2022 will return 01/01/2022, 08/09/2020 will return 07/01/2020
This is ideal when you want your quarter field to remain in date format. This comes in handy when aggregating and then graphing values over a quarter by keeping your X-axis as a date.
If you want a quarter field that results in Q1/Q2/Q3/Q4 then use the following function:
Select Case when date_format(<date>, MM) < 4 then Q1 when date_format(<date>, MM) < 7 then Q2 when date_format(<date>, MM) < 10 then Q3 Else Q4 End
Ex: 03/07/2022 will return Q1, 08/09/2020 will return Q3
You can edit this function to result in a numerical 1-4 by removing each 'Q' from the case statement.
You can also differentiate the year by adding a year field select date_format(<date>,YYYY). You can leave this field separate or concat the year and quarter fields in a subsequent step.
Please sign in to leave a comment.