I’m trying to learn queries using Flux. I have sample data that has every instance of users (cardholders) badging into various locations. I want to see the breakdown of how many people were in any location per day.
My data is organized as follows:
- measurement: “Event”
- tags: location, door, Event_type, cardholder
- fields: badge
There is a one-for-one correspondence between a cardholder and a badge, but that doesn’t really matter. Also, there is a timestamp for each badge swipe.
With this query, I can get the total number of times someone was admitted to a location per day:
from(bucket: "testbucket1")
|> range(start: -60d, stop: -30d)
|> filter(fn: (r) => r._measurement == "Event")
|> filter(fn: (r) => r.Event_type == "Access Granted")
|> group(columns:["location"])
|> aggregateWindow(every: 1d, fn: count)
However, this gives me the total “Access Granted” count, so if a person badges in multiple times, each of those is included in the count. I’m trying to have just the number of unique people who badged in. So, if John badged in 3 times and Jane badged in twice, I want the count to show 2, not 5 as it shows now.
I tried playing with the unique() function, and I tried adapting the solution shown here (Flux - amount of unique TAGS by day) but haven’t figured out the magic yet. Any suggestions would be most welcome.
Thanks!