In Grafana, how do we deal with queries that return 0 rows in a chart/panel? - grafana

I’m running into a problem that might be self inflicted but I’m a noob and I’m still stumbling thru this dashboard I inherited.
We are using Grafana 8.1.5. I inherited a dashboard with a panel that is giving this error message:
“failed to convert long to wide series when converting from dataframe: can not convert to wide series, input has null time values” error.
I think I know the cause but I don’t know how to fix it. The data source is from a MySQL database. When we select “All” under the dropdown “Org”, we don’t get this error and we get 8 rows back and are expecting 8 rows.
When we select one org (in this example “Data Protection”) under the dropdown “Org”, we do get the error and we get 5 rows back. I think because 3 queries return 0 rows, we are getting this error.
Each pie slice has its own SQL query to get data. For the queries that return 0 rows, I tried selecting some of the “Standard options” to fix it but it doesn’t seem to work. I tried to play around with the Min, Max, and “No Value” settings and enter values larger than 0 but I still get this error. The initial values for Min and Max were "auto" and "No Value" was blank but the screenshot is when I left them as "1" while I was messing with them.
What do I need to do to make the message go away? Is the message benign and I shouldn’t worry about it since it looks like we’re still printing out the pie chart?

Write SQL, which returns record with zero value instead of empty result. In theory zero value, won't be visible in the pie chart and you will have still record for dataframe transformation, so that one won't be failing.

So I accidentally stumbled across the answer. What happened is the query returned data formatted as "Time Series" instead of "Table". Because some of the data didn't have values for the specified time, the time value was Null.
Since it was Null, the chart returned this error message. The fix was to select "Table" as the format. Then the chart won't care about the time value being Null and the missing data appears as 0 in the legend and we don't get the error message anymore.

Related

Binary operation with two queries in Grafana not working

I'm using Infinity datasource plugin for showing stat values. I have two queries, both of them have similar json response, but values are different. In my case I'm getting root values like that: $.total.
Here's the result:
I want to get sum of those queries results and hide these values behind the sum, so I added transform "Add field from calculation", binary operation.
But nothing happen, values on dashboard does not change. The only way sum is working - when I choose same field left and right of plus sign - it sums "wrong assignee + wrong assignee" or "total issues + total issues" correct. If I change one of them to get real sum between different values - nothing. Maybe I'm doing something wrong?

Why does grafana display NaN for values that are clearly integers?

I created a SQL query that counts the number of servers running test jobs on a specific Jenkins server at a specified time. I'm trying to chart it on Grafana but for some reason, it's displaying the value as NaN.
The data source is a MySQL server. I'm running Grafana version 8.1.5. I went on the server (phpMyAdmin) to check the results of the query and I can see numbers.
When we look at the grafana chart/panel, the bars on the chart look like it matches the values, but the chart shows NaN instead of the value.
What setting do I need to change so that it can print the numeric value on the chart instead of displaying NaN?
EDIT: Looks like I didn't include enough info to my question.
Here's the query that's used, although, I don't know how feasible it is to include the tables with data to demo the issue:
SELECT COUNT(DISTINCT(tb_name)) as val, jenkins FROM (
SELECT
hw.collected_date AS mytime,
hw.jenkins AS jenkins,
hw.name AS tb_name
FROM hw_report as hw LEFT OUTER JOIN jenkins_owner jo
ON hw.jenkins = jo.jenkins
WHERE jo.org IN ('Enterprise Readiness')) as y
WHERE mytime = '2021-12-03 00:00:00'
GROUP BY jenkins
HAVING count(distinct(tb_name)) > '0'
Here are screenshots of my panel. The "Show values" setting is set to "Always", which II assume should show the values.
One thing I noticed is when I hover over the bar, it shows
COUNT(DISTINCT(name_cnt))
instead of a numeric value. Not sure if this is indicative of anything. I checked other charts in the dashboard that someone created and their bars either have a numeric value or it's just a column name (like name_cnt)
Sorry I'm a noob and didn't know what to configure, look up, or mention in my question. I accidentally came across the answer.
So it seems like I need to select something under the "Transform" tab for the panel. Calculation needs to be "Total" instead of "Count" and I need to hide the fields specified in my SQL query and show the "Total"

Show 0 for values with missing data

I have a dimension I am showing in a text table that can have one of 3 possibilities "A", "B", or "C" and I want at all times to have A, B and C shown in a text table even if one of them has 0 occurrences. The issue is that I am filtering this based on date, so it is possible that for example B may not exist, but I still want to have a 0 printed for B.
I have gone to Analysis -> Table layout -> show empty rows which will show "B", but in the count display it shows a blank. How can I get it to display a 0?
This problem is very famous among tableau users and I still did not see a generic tableau-only solution. All proper solutions start with injecting rows to your data which I assume you do not want this.
Below method will only work if you have a Date Dimension on the measure and no-data dates are not completely filtered-out; so you will be seeing zeros even though that date has no data as you may see on below screenshot.
When you filter out the no-data dates, unfortunately you will keep on seeing NULLs.
If you are using the SUM of Number of Records as your occurrences, then you may create a calculated field as below and use it in your pane:
ZN(LOOKUP(SUM([Number of Records]),0))
You can leave the Default Table Calculation as Automatic so the Results are computed along Table (accross).

How to filter data based on a time parameter in Access?

I have a query from another thread which goes through a list of different events and pulls out the most recent event and puts it into a list. The code I'm using is:
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1;
Cleaning1 is the column that has the different cleanings, and Date1 is the column that has the date the cleaning occurred, and CleaningLog is the name of the table. I currently have a macro in Access which is an OpenQuery, query. I am having it open the above query, and then having it view as a data sheet and it's in edit mode.
What I am stuck on, is getting a subsequent macro/query/vba code to take the datasheet the query produces and going through each item and determining if they're over due to be cleaned. I tried having a Make Table query, but the problem is, there is no user friendly way to refresh that table without having to delete it (I am having unskilled workers use this Access sheet).
I am wondering if there's a way to look at the most recent cleaning's date, what the query produces, and filter the dates out that are over due for a cleaning, specified by a parameter. I have been looking at this webpage to start playing with the notation, but I haven't been able to come up with much that is useful.
https://support.office.com/en-us/article/Examples-of-query-criteria-3197228C-8684-4552-AC03-ABA746FB29D8
Another problem that I am encountering is that each cleaning doesn't have the same time frame in which is needs to be cleaned.
Thank you in advance for any help!!
You should just be able to modify the query above to show entries with a max date lower than they should be. Below shows entries that haven't been cleaned in 30 days, for instance.
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1
HAVING Max(Date1) < Now() - 30;

How to make zero tablix data rows appear?

I am developing an SSRS 2008 report. I created a tablix, however, when I view this report one of the rows has zero entries. This row is not showing in the output. How can I make it show regardless of values so that it will just show "0" otherwise?
This was the expression I used for it:
=iif(CountDistinct(Fields!Client.Value)=0 or
isnothing(countdistinct(Fields!Client.Value)),0,
CountDistinct(Fields!Client.Value))
And I have tried grouping on different fields and also filtering on another field, but none of these make it appear when there is no data.
I think that the best you can do is ensuring that the dataset you are using has the record you want, even if it is null. For example, if you are grouping months, and you want all 12 months to appear in your tablix, then you need to make those months to exist in your dataset even if they have null values for all the other columns.