Forum Discussion
Plotting Average Lag Time For Every Monitoring Device
I have a fact table that looks like this that lists all the lag times for the monitoring devices at every ReportingDate increment:
Basically, I want to create a bar chart in Power Bi that shows average lag time(accumulated over all reporting dates) where each bar shows the number of devices in each of the following categories:
Average Minutes w/o Data between 0-15
- Average Minutes w/o Data between 15-30
- Average Minutes w/o Data between 30-45
- Average Minutes w/o Data between 45-60
- Average Minutes w/o Data between 60-1440
- Average Minutes w/o Data > 1440
How do you I accomplish that completely in PowerBi (i.e. without modifying in the source database)?
Inputs: I have a table ActiveMonitoringDeviceFact(on the screenshot in the original question), where MonitoringDeviceID is a foreign key. For each 15-minute incerement (Reporting Date also included in the screenshot), I may have only 1 occurence of a specific MonitroingDeviceID. For each of those increments there is lag time(NumMinutesSinceLastMeasurementReceived) (minutes it took measurements to get to the server (null or some numeric value)).
Output: Given all the attributes I mentioned above, I want to calculate average lag time for every MontoringDeviceID (over all the 15-minute increments in the Reproting Date) and assign every device to a specific group (0-15 average lag time, 15-30 average lag time, etc.) and build a bar chart based on the number of devices in each respective group.
Here's an SQL query that I think accomplishes that:
SELECT DISTINCT(MonitoringDeviceID), AVG(NumMinutesSinceLastMeasurementReceived),
CASE
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 0 AND 15 THEN '0-15 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 15 AND 30 THEN '15-30 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 30 AND 45 THEN '30-45 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 45 AND 60 THEN '45-60 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 60 AND 1440 THEN '60-1440 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) > 1440 THEN '>1440 Bin'
ELSE 'Undefined'
END AS FreqeuncyBin
FROM ActiveMonitoringDeviceFact
GROUP BY MonitoringDeviceID;
Thank you in advance.
4 Replies
- amitchandak
Super User
tiger98 , not very clear, see of these can help
https://www.daxpatterns.com/dynamic-segmentation/
https://www.daxpatterns.com/static-segmentation/
https://www.poweredsolutions.co/2020/01/11/dax-vs-power-query-static-segmentation-in-power-bi-dax-power-query/
https://radacad.com/grouping-and-binning-step-towards-better-data-visualization - dax
Community Support
Hi tiger98 ,
I am not clear about your requirement, if possible could you please inform me more detailed information(such as your expected output and your sample data )? Then I will help you more correctly.
Please do mask sensitive data before uploading.
Thanks for your understanding and support.
Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- tiger98Regular Visitor
Inputs: I have a table ActiveMonitoringDeviceFact(on the screenshot in the original question), where MonitoringDeviceID is a foreign key. For each 15-minute incerement (Reporting Date also included in the screenshot), I may have only 1 occurence of a specific MonitroingDeviceID. For each of those increments there is lag time(NumMinutesSinceLastMeasurementReceived) (minutes it took measurements to get to the server (null or some numeric value)).
Output: Given all the attributes I mentioned above, I want to calculate average lag time for every MontoringDeviceID (over all the 15-minute increments in the Reproting Date) and assign every device to a specific group (0-15 average lag time, 15-30 average lag time, etc.) and build a bar chart based on the number of devices in each respective group.
Here's an SQL query that I think accomplishes that:
SELECT DISTINCT(MonitoringDeviceID), AVG(NumMinutesSinceLastMeasurementReceived),
CASE
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 0 AND 15 THEN '0-15 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 15 AND 30 THEN '15-30 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 30 AND 45 THEN '30-45 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 45 AND 60 THEN '45-60 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) BETWEEN 60 AND 1440 THEN '60-1440 Bin'
WHEN AVG(NumMinutesSinceLastMeasurementReceived) > 1440 THEN '>1440 Bin'
ELSE 'Undefined'
END AS FreqeuncyBin
FROM ActiveMonitoringDeviceFact
GROUP BY MonitoringDeviceID;- sturlaws
Resident Rockstar