BAQ Calculated field for Year-Quarter

I should know this one but am having issues. Hopefully easy for you experts out there…

I want a calculated field to display year-quarter for Customer.Estdate as follows:

2018-Q1
2018-Q2
2018-Q3
2018-Q4

Thanks in advance

Couldyou do something like
Case
when (DATEPART(quarter, Customer.EstDate) = ‘1’ and DATEPART(year, Customer.EstDate) = ‘2018’) then ‘2018-Q1’
when …
end

You could also concatenate the dateparts so that it;'s more flexible in the future too

Hi Randy,

This should give you exactly what you want:

CAST(YEAR(Customer.EstDate) AS VARCHAR) + ‘-Q’ + CAST(DATEPART(QUARTER, Customer.EstDate) AS VARCHAR)

Thanks. By the way I only work 2 days per week here hence the delay in my replies.

Maybe someone could explain why this gives me an error - trying to get a 2 digit month. I am a newbie at this syntax.

If DATEPART(MONTH, LaborDtl.ClockInDate) > 9 then
DATEPART(MONTH, LaborDtl.ClockInDate)
Else
‘0’ + DATEPART(MONTH, LaborDtl.ClockInDate)

I assume it is due to the fact that you are not casting the returned DATEPART functions to string, as this function returns an integer value.

IF DATEPART(MONTH, LaborDtl.ClockInDate) > 9
THEN CAST(DATEPART(MONTH, LaborDtl.ClockInDate) AS VARCHAR)
ELSE ’0’ + CAST(DATEPART(MONTH, LaborDtl.ClockInDate) AS VARCHAR)