Solved

# Counting records by metric

• 6 replies
• 41 views

• New Participant
• 7 replies

A common hypothesis is that employees with less experience are involved in more accidents. As the following image shows, I can identify specific incidents within a given time frame, I can compute the employeeâ€™s length of service (time delta between the date-of-hire and the event date), and I can properly assign the incident to a length-of-service bucket. WHat I am struggliung with is how to count the incidents in each bucket. For this example, I would like to be able to show a bar or pie chart which shows bucket ==> count:

0 ==> 2

2 ==> 5

5 ==> 2

10 ==> 1

25 ==> 3

Any ideas?

icon

Best answer by Francisco Antunes 27 October 2023, 17:18

View original

### 6 replies

Hi Jay,

Â

Thanks for reaching out!

I appreciate the thorough explanation and the screenshot. I think I understand what you are looking to achieve here. Basically, you want to have a Pie/Bar chart showing the total number of injuries (each one defined byÂ Injury ID), viewed by the Length of Service.

Â

In this case, I think the solution would be to create a Pie/Bar chart where theÂ MetricÂ isÂ the COUNT(Injury ID),Â Viewed byÂ Length of Service. The results should be the count of injury per Length bucket.

Â

Please give that a shot and let me know if it works out!

Â

Best,

Francisco

The problem is that both the calculated length of service and the bucketÂ are metrics, not attributes. the BY feature only works with attributes.

Thanks for the extra info! Indeed, that would not work out.

Â

I gave it some thought, and hereâ€™s the idea I came up with:

Create a separate metricÂ countingÂ the IncidentÂ ID for each result or range of results from the Length of Service metric. Something like this:

`SELECT COUNT (Incident ID) WHERE (SELECT Length of Service by Bucket BY Incident ID) = 1`Â

or
`SELECT COUNT (Incident ID) WHERE (SELECT Length of Service by Bucket BY Incident ID) BETWEEN 5 AND 10`

Â

Youâ€™d end up with 4/5 such metrics (which is the downside of this method), one for each result range (defined by the WHERE conditional). Then, add all of them to the Metrics section of your Pie chart.Â I tested it on my end, and it should get you the results you are looking for!

Â

Let me know if that one works out better!

Â

Francisco

That looks like it might work, but I might not be able to test it for a day or so. Thanks.

Unfortunately, that solution does not work for me. I think the issue lies in mutilple date dimensions in play: Date (Event) and Date (Date of Hire). If Iâ€™m correct, weâ€™ll have to rethink our data model accordingly to turn the length-of-service bucket into an attribute.

Iâ€™m sorry to hear it didnâ€™t work out. Having Length-of-Service as an attribute would resolve this, for sure.

Feel free to let us know if you have any further questions, or run into any trouble while implementing this.

Â

Best,

Francisco