I am currently trying to set up a query in Grafana to display a graph. I have data in the database and my query returns the results I expect, but the graph seems to only display the smallest result.
Table [test_statements]
| ID | ReportTime | LapTime |
| 1 | 2018-03-29 13:02:06 | 2700 |
| 2 | 2018-03-29 13:03:06 | 2725 |
| 3 | 2018-03-29 13:04:06 | 1645 |
| 4 | 2018-03-29 13:05:06 | 2900 |
| 5 | 2018-03-29 13:06:06 | 3101 |
The template is structured as:
SELECT UNIX_TIMESTAMP(<time_column>) as time_sec,
<value column> as value,
<series name column> as metric
FROM <table name>
WHERE $__timeFilter(time_column)
ORDER BY <time_column> ASC
Current Query
SELECT
UNIX_TIMESTAMP(ReportTime) as time_sec,
LapTime as value,
'ReportTime' as metric
FROM test_statements
WHERE ReportTime > 0
ORDER BY ReportTime ASC
Here are my results:
I can see the ReportTime results are correct, but the graph is wrong.
Not sure what i'm doing wrong but a point in the correct direction would be helpful. Thanks.
Since there are no time scale labels on x-axis in screenshot
most likely you have Format as in graph editor's Metrics tab set to Series or Table instead of Time series.
Thus, what you see as y-axis value is the total (sum) of your individual datapoint values (approx. 7 * 2.7K) which is the default setting for series aggregation function. And x-axis is labeled with time series name(metric).
Related
I'm not too familiar with the more complex queries and I'm having an issue finding some examples to take apart to utilize..
Event Name | Due Date | Frequency |Frequency UOM
S-XYC-001 | 10/17/2020 | 360 | D
S-XYA-003 | 6/1/2020 | 90 | D
S-XYC-004 | 4/3/2020 | 180 | D
So, we have a set of work that has an initial due date provided, and an expected frequency along with a unit of measurement (I've converted all my frequencies into days as there was previously a mix of days, quarterlies, months..).
I've been asked to generate a forecast of events in 2020. So, using the above source table we'd expect our list to look like this:
Event Name | Due Date | Frequency | Frequency UOM
S-XYC-001 | 10/17/2020 | 360 | D
S-XYA-003 | 6/1/2020 | 90 | D
S-XYA-003 | 8/30/2020 | 90 | D
S-XYA-003 | 11/28/2020 | 90 | D
S-XYC-004 | 4/3/2020 | 180 | D
S-XYC-004 | 9/30/2020 | 180 | D
I'm really not quite sure what type of query to apply to get these results, Or honestly what to look for to get some examples I can utilize to do what I need to.
First, change your frequency to months - 12, 3, and 6 respectively - to obtain the correct result dates.
Then, create a small query and save it as Ten as it simply returns 0 to 9:
SELECT DISTINCT
Abs([id] Mod 10) AS N
FROM
MSysObjects;
Use that in this generic query that is capable of generating any sequence of date/time in the entire range of DateTime:
PARAMETERS
[Interval] Text ( 255 ),
[Number] IEEEDouble,
[Date] DateTime,
[Count] IEEEDouble;
SELECT
[Ten_0].[N]+[Ten_1].[N]*10+[Ten_2].[N]*100+[Ten_3].[N]*1000+[Ten_4].[N]*10000+[Ten_5].[N]*100000+[Ten_6].[N]*1000000+[Ten_7].[N]*10000000 AS Id,
DateAdd([Interval],Fix([Number])*([Ten_0].[N]+[Ten_1].[N]*10+[Ten_2].[N]*100+[Ten_3].[N]*1000+[Ten_4].[N]*10000+[Ten_5].[N]*100000+[Ten_6].[N]*1000000+[Ten_7].[N]*10000000),[Date]) AS [Date]
FROM
Ten AS Ten_0,
Ten AS Ten_1,
Ten AS Ten_2,
Ten AS Ten_3,
Ten AS Ten_4,
Ten AS Ten_5,
Ten AS Ten_6,
Ten AS Ten_7
WHERE
((([Ten_0].[N]+[Ten_1].[N]*10+[Ten_2].[N]*100+[Ten_3].[N]*1000+[Ten_4].[N]*10000+[Ten_5].[N]*100000+[Ten_6].[N]*1000000+[Ten_7].[N]*10000000)<[Count])
AND
(([Interval]) In ("s","n","h","d","w","ww","m","q","yyyy"))
AND
((Fix([Number])*([Ten_0].[N]+[Ten_1].[N]*10+[Ten_2].[N]*100+[Ten_3].[N]*1000+[Ten_4].[N]*10000+[Ten_5].[N]*100000+[Ten_6].[N]*1000000+[Ten_7].[N]*10000000) Mod IIf(Fix([Number])=0,1,Fix([Number])))=0)
AND
((Ten_0.N)<=[Count]\1)
AND
((Ten_1.N)<=[Count]\10)
AND
((Ten_2.N)<=[Count]\100)
AND
((Ten_3.N)<=[Count]\1000)
AND
((Ten_4.N)<=[Count]\10000)
AND
((Ten_5.N)<=[Count]\100000)
AND
((Ten_6.N)<=[Count]\1000000)
AND
((Ten_7.N)<=[Count]\10000000));
Save it as DatesSequence.
This you can run with the parameters:
Interval: "m"
Number: 3, 6, or 12
Date: Due Date
Count: The count of future event dates to list
Results:
You could modify the query to filter out dates later than 2020.
so I am trying to use MySQL to look at the values of our database, and spit out the sum of the values in a column between 2 date ranges. Currently I have gotten it to at least select the correct range of dates using the code:
SELECT fuelDate, SUM(gallons)
FROM fuel566243
WHERE fuelDate BETWEEN '2019-01-04' AND '2019-01-24'
GROUP BY fuelDate
ORDER BY fuelDate
The issue with this code, is in the SUM column that gets generated, it just displays all the values of the gallons column, but doesn't add them up. Is there a way to do this in SQL and output a result? Or is it easier to just use a foreach loop to cycle through the array and add the values using PHP?
When I run the code above, it gives me this output. How do I then get the sum of the gallons column shown below? Is there a way to do that in SQL? Or would I need to use a loop to add the values using PHP?
| fuelDate | Gallons | |
| 2019-01-04 | 53.8885 | |
| 2019-01-15 | 198.1700 | |
| 2019-01-17 | 167.2750 | |
| 2019-01-23 | 176.5620 | |
| 2019-01-24 | 181.0240 | |
The GROUP BY defines the rows that are being returned. You have included gallons as an aggregation key, so you have specified that you want a separate row for each value.
Simply remove the key from the GROUP BY and the SELECT:
SELECT fuelDate, SUM(gallons)
FROM fuel566243
WHERE fuelDate BETWEEN '2019-01-04' AND '2019-01-24'
GROUP BY fuelDate
ORDER BY fuelDate;
If you want the total during the period, then you want an aggregation with no GROUP BY:
SELECT SUM(gallons)
FROM fuel566243
WHERE fuelDate BETWEEN '2019-01-04' AND '2019-01-24';
I am trying to include a cumulative total column in a matrix on a report.
This is the expression I am using at the moment:
=RunningValue(Ceiling((SUM(Fields!MINUTES.Value)/60)*4)/4,Sum,"RowGroup")
The problem is the total seems to reset on each day.
I have 3 groups on the report: Parent is Day of month, type, then sub type.
I want it so that the sub types will accumulate across the days:
So 1st june/holiday/annual = 2 - cumulative = 2
.. 2nd june/holiday/annual = 1 - cumulative = 3
rowgroup in the expression above is the 3rd level sub type group in the matrix.
Whatever I try I cannot get it to total up over the days, like i said above it seems to not carry over to the next day.
Below is a sample dataset:
+------+------------+---------+----------+---------+
| User | Date | Type | Subtype | Minutes |
+------+------------+---------+----------+---------+
| 158 | 13/02/2015 | Holiday | Annual | 90 |
| 158 | 13/02/2015 | Meeting | Training | 300 |
| 158 | 13/02/2015 | Lunch | Lunch | 60 |
| 158 | 03/06/2015 | Holiday | Annual | 120 |
| 158 | 03/06/2015 | Meeting | Meeting | 285 |
| 158 | 04/06/2015 | Holiday | Sick | 120 |
| 158 | 04/06/2015 | Holiday | Annual | 200 |
+------+------------+---------+----------+---------+
My matrix column group is the user.
The row groups are date, then type, then subtype.
I then have a total column outside the column grouping.
I'm now trying to add in to the report a cumulative total based on the type and sub-type columns, that sums up the minutes.
As an example (looking at the holiday, annual entries):
03/06/2015 - 120 minutes
13/02/2015 - 90 minutes = 210 minutes
04/06/2015 - 200 minutes = 410 minutes.
Taken from the MSDN page for RunningValue, adding a scope to your expression will have this effect.
The value for RunningValue resets to 0 for each new instance of the scope. If a group is specified, the running value is reset when the group expression changes. If a data region is specified, the running value is reset for each new instance of the data region. If a dataset is specified, the running value is not reset throughout the entire dataset.
To fix the issue, simply remove the scope:
=RunningValue(Ceiling((SUM(Fields!MINUTES.Value)/60)*4)/4,Sum)
This will have the total run across all days (As days are your top-most level). If this is incorrect could you perhaps give us an example of what the report is currently doing, and what you want it to do?
I have a view set up like the below table, which is pulling data from multiple other tables using JOINS. Basically I'm trying to replicate a Crystal Report that breaks up the data below into Job # - Weekly (hrs) - TotalToDate(hrs) - Budget(hrs)
And this is broken up per department. The way the report does it is it'll display the hours for the last week, then the total hours to date then the budgeted hours set for that department.
Table doesn't reflect above - just an example of what DB table looks like.
+-----------+------------+---------------+--------+---------------------+
| Job | Work_Date | Work_Center | Est_Total_Hrs | Act_Run_Hrs |
+-----------+------------+---------------+--------+------+--------------+
| 5666 | 2014-02-23 | SURFACE | 155 | 5 |
| 5666 | 2014-02-16 | SURFACE | 155 | 3 |
| 5666 | 2014-02-23 | DESIGN | 200 | 6 |
| 5666 | 2014-02-16 | DESIGN | 200 | 4 |
| 5666 | 2014-02-23 | SURFACE | 150 | 2 |
| 5666 | 2014-02-16 | SURFACE | 150 | 2 |
| 5666 | 2014-02-23 | DESIGN | 300 | 8 |
+-----------+------------+---------------+---------------+--------------+
Also, theres a lot of different job numbers, and when I pull up more than 1 job in Crystal it'll show the report like the picture above but with all jobs I want to retrieve.
How would I go about pulling this data so it shows up the same way in the Crystal Report? I want to create a view that looks the same. Is there a way to see how Crystal does it? When I click "Show Query" it shows me the below query which I had to re-write a little bit for it to work in SQL Server and in Adminer.
Query I'm using to pull ALL data for all Jobs within an updated Work_Date in the last 90 days.
SELECT Job_Operation.Work_Center
,Job_Operation.Job_Operation
,Job_Operation_Time.Work_Date
,Job_Operation.Est_Total_Hrs
,Job_Operation_Time.Act_Run_Hrs
,Job_Operation_Time.Act_Setup_Hrs
,Job.Description
,Job_Operation_Time.Overtime_Hrs
,Job_Operation_Time.Act_Setup_Hrs
,Job.Job
,Job.Description
,Job_Operation_Time.Labor_Burden
,Job_Operation.Est_Setup_Labor
,Job_Operation.Est_Run_Labor
,Job_Operation.Est_Labor_Burden
,Job_Operation.Operation_Service
FROM Job AS Job
LEFT OUTER JOIN Job_Operation AS Job_Operation ON Job.Job = Job_Operation.Job
LEFT OUTER JOIN Job_Operation_Time AS Job_Operation_Time ON Job_Operation.Job_Operation = Job_Operation_Time.Job_Operation
WHERE DATEDIFF(day, Work_Date, GETDATE()) < 90 ORDER BY Work_Date Desc
Crystal will take the data from a query and does its internal manipulation as per the design of the report, So if you need the table exactly as you view the report then along with the query in crystal report you need to make some changes.
Suggestions:
Your report has only 6 columns but you query has more than 10 columns so you need to change the query so that it has only 6 columns.
Report has data according to the week but query has hourly data so you need to write some functions in query so that you manage to get weekly data from hour data
You said when you take more than 1 ID you get in the given format then in that case add some group by conditions to the resultant query so that all data is grouped. for e.g if you need only one ID then group by ID so that there is only one record for a ID.
Try adding some group by conditions some date formulas to get exact output
I am looking to to use an SSRS line chart to graph ending run times of jobs. I am using runtime on the y-axis and date on the x-axis. The graph looks like a flat line and the times do not show up on the y-axis, but integers show.
I also want to put a target line at a specific time to show our SLA time.
Here is example of data I am trying to graph, but I want a line.
+-------+----------+
| y | x |
+-------+----------+
| 10:05 | 3/1/2009 |
| 11:00 | 3/2/2009 |
| 10:15 | 3/3/2009 |
+-------+----------+
+-------+----------+----------+----------+
| 11:00 | | x | |
| 10:45 | | | |
| 10:30 | | | |
| 10:15 | | | x |
| 10:00 | x | | |
+-------+----------+----------+----------+
| | 3/1/2009 | 3/2/2009 | 3/3/2009 |
+-------+----------+----------+----------+
Lets say you have table Times with Date and Hours.
Declare Report parameter #LimitHourParam decimal - for target time.
Set query of dataset:
SELECT Date, SUM(Hours) AS Hours, 'Actual Hours' AS LimitHour
FROM Times
GROUP BY Date
UNION ALL
SELECT DISTINCT Date, #LimitHourParam AS Hours, 'Hours Limit' AS LimitHour
FROM Times
So you will get in result hours grouped by dates and some hour limit for unique each date.
Place Chart control in report page.
Go to Chart Properties->Data
Press "Add Values"
Erase value of Label and set Value to
=Sum(Fields!Hours.Value)
Go to "Point Labels" tab of "Edit Chart Value" dialog, check "Show point labels", set Data label to
= String.Format("{0}:{1}", (Fields!Hours.Value / 1) - (Fields!Hours.Value Mod 1), (Fields!Hours.Value Mod 1)*60/1 - (Fields!Hours.Value Mod 1)*60 Mod 1)
Add Category Groups, set "Group On" expression to
=Fields!Date.Value
Add Series Group, set both "Group On" expression and Label values to
=Fields!LimitHour.Value
Go to Chart Properties->X Axis, set labels format dd/mm/yyyy
Result should look like this: