I have a data set with repeating date values within a quarter, I'd like to select the closest date to the quarter end.
Existing data
The output I'm tryting to acheive would look like this
select
created_at,
account_id,
account_name,
Score,
DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, d.Timestamp) + 1, 0))
AS 'quarterend'
From xyz.database
I'm not sure what the best way is to filter out the unneeded values, had thought about a datediff caluation after creating a quarte end date and choose min score in a having or where clause subselect but could not get that to work. Thanks