I have a normal bar chart, with a SQL Server query like this:
SELECT
Timestamp AS "time",
Category,
SUM(Cost) AS Cost
FROM Metrics.dbo.Costs a
GROUP BY Timestamp, Category
ORDER BY Timestamp ASC
The data changes as the filter changes, of course. However i would like to “lock” this query to always be “this year so far”, basically ignoring the time filter control. Is that possible?
Try this, but this is not really a grafana issue by the way
declare @StartOfYear datetime = DATEADD(yy, DATEDIFF(yy, 0, getutcdate()), 0)
SELECT
Timestamp AS "time",
Category,
SUM(Cost) AS Cost
FROM Metrics.dbo.Costs a
where Timestamp between @StartOfYear and getutcdate()
GROUP BY Timestamp, Category
ORDER BY Timestamp ASC
I think maybe you misunderstood, or i didn’t explain correctly.
I know that’s how you write the SQL Server query, the issue is Grafana isn’t respecting that and because of the time filter on the dashboard, it’s “re-filtering” the data.
So even with your new query, if i have “Last 30 days” as my time filter in the UI, that’s all it will show. I want that time filter in the UI to be ignored.