Hi there, I’m new to Grafana, and I’m having issues with my queries not honoring the $__timeFilter macro. Hopefully I’m just misunderstanding something, but it seems to not be working for me. I have a very simple database table:
mysql> DESC impacts;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | varchar(255) | NO | | NULL | |
| mass | int(11) | NO | | NULL | |
| recclass | varchar(255) | YES | | NULL | |
| reclat | decimal(8,6) | YES | | NULL | |
| reclong | decimal(9,6) | YES | | NULL | |
| year | datetime | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
The year field is obviously the dates I’m attempting to filter based on, and the field I’m mapping is the mass field. I have two panels on my dashboard, one graph and one single stat. The single stat is an average of the data from the mass field while the graph charts them across time. When I have no filtering going on both panels show data as I would expect, but as soon as I attempt to add a $__timeFilter macro the single stat becomes N/A and the graph ceases to plot any points along the X axis. Here’s my beginning query (which works) from the single stat panel:
SELECT
year AS "time",
mass
FROM impacts
ORDER BY year
It’s pretty straight forward, and shows 50.9 kg which matches the 50864.7143 value (grams) I get when I select avg(mass) directly in MySQL. As soon as I change my query to the following I get N/A in the single stat panel:
SELECT
year AS "time",
mass
FROM impacts
WHERE $__timeFilter(year)
ORDER BY year
I have also tried:
WHERE year >= $__timeFrom() AND year <= $__timeTo()
or
WHERE year BETWEEN $__timeFrom() AND $__timeTo()
Am I misunderstanding something here? The query doesn’t throw any errors, but it’s not getting data. This appears to line up with examples I’ve seen so I’m scratching my head trying to figure out why that would not work.
Thanks a lot for any help that can be offered. It is very much appreciated!
Ryan