Average of conditional statement

Hi,

So I have this formula to calculate the true positives in my dataset.

Field_1 = distinct_countIf(id, Eve_status = “True Positive”)

Now I want to calculate the average of the above formula based on the time period.

So when I used this formula it is providing me the same answer.

Average(Field_1) = avg_over(Field_1,[created])

It is providing the same result as Field _1 and there is no different result.

Hi @samytar97,

What is the granularity of the “created” field? Is it seconds? If it’s seconds, your calculated field is calculating the average of all values of Field_1 in that 1 second period. If you have only 1 data point in that 1 second period, your average is the same as the Field_1 value.

If you want to use a different time period for the average, you need to create a field to calculate that period first before you use it in your calculation of the average.
Example: created_month = truncDate(‘MM’, created)

Hi @David_Wong,

So firstly in the dataset for the created it is something like this 2021-05-05T10:15:34.458Z.

Second as you mentioned I have created an field called as created_month = truncDate(“MM”,created_month)

Average(Field_1) = avgOver(field_1,[created_month])

So when i move the average(field_1) to the visualization it is not giving me the desired result.

Can you check and let me know whats wrong in this. Or to calculate the average should I be using something else instead of time period? Please guide here

Hi @samytar97,

What type of visual are you trying to create? What are the dimensions in your visual?

Hi @David_Wong

I m using a line chart here and in the X axis i m using the time period for the dimension.

In the line chart i m showing count of false positives and true positives. Along with that i would like to show average of false and true positives

Hi @samytar97,

If I’m understanding you correctly, you want to show the count of false positives and true positives by month and the average should be across all the months in your dataset. Is that right? If that’s the case, you don’t need to calculate the average. You can add it as a reference line like this:
image

Just aggregate by month on your x-axis.
image

Hi @samytar97,
It’s been awhile since we last heard from you, did you have any additional questions regarding your initial post?

If we do not hear back within the next 3 business days, I’ll go ahead and close out this topic.

Thank you!

Yes your understanding is correct and I’m marking this is as solution.

1 Like