SELECT
DATE(alarm_active) AS 'Date',
message AS 'Message',
unit AS 'Conveyor',
area AS 'Location',
COUNT(*) AS 'Count',
SUM(TIMESTAMPDIFF(MINUTE, alarm_active, alarm_off)) AS 'Lost Time in Mins',
WEEK(DATE(alarm_active), 3) - WEEK('2024-08-24', 3) + 20 AS 'Fiscal_Week'
FROM
alarm_history
WHERE
alarm_active >= CONCAT(CURDATE(), ' 05:30:00') -- Filters from 5:30 AM today
AND alarm_active < CONCAT(CURDATE(), ' 23:59:59') -- Filters up to 11:59 PM today
AND area IN ('WeighLabel', 'PalletAccum', 'HandStack', 'South Corridor')
AND message LIKE '%jam%'
GROUP BY
DATE(alarm_active),
message,
unit,
area,
WEEK(DATE(alarm_active), 3) - WEEK('2024-08-24', 3) + 20
HAVING
SUM(TIMESTAMPDIFF(MINUTE, alarm_active, alarm_off)) >= 3
ORDER BY
DATE(alarm_active) DESC,
unit DESC;
A Bar Chart typically contains a single string column that gets used as the Domain with as many other columns representing the Range axis values. The order of the dataset matters, and the string values used for the domain should be in the first column of the dataset.
I would add a script source that takes the query results and formats it into something that the bar chart is wanting. Once you format the data, assign it to its own data source so you have both the original and the bar chart format.
SELECT
area AS 'Location',
COUNT(*) AS 'Total Count',
SUM(TIMESTAMPDIFF(MINUTE, alarm_active, alarm_off)) AS 'Total Lost Time in Mins'
FROM
alarm_history
WHERE
alarm_active >= CONCAT(CURDATE(), ' 05:30:00') -- Filters from 5:30 AM today
AND alarm_active < CONCAT(CURDATE(), ' 23:59:59') -- Filters up to 11:59 PM today
AND area IN ('WeighLabel', 'PalletAccum', 'HandStack', 'South Corridor')
AND message LIKE '%jam%'
GROUP BY
area
HAVING
SUM(TIMESTAMPDIFF(MINUTE, alarm_active, alarm_off)) >= 3
ORDER BY
'Total Lost Time in Mins' DESC;
If you want to use start and end date parameters you would modify the query like so
alarm_active between ? and ?
The ? place holder will automatically bring up selection windows at the bottom where you can choose which parameter to use to substitute into each place holder.