how to compute the date max of an event ?
Hi Philippine D., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To compute the date max (or maximum timestamp) of an event in Mixpanel, you can use JQL (JavaScript Query Language) with the built-in reducer functions. Here are a couple of approaches:
Using mixpanel.reducer.max()
You can use the mixpanel.reducer.max()
function to find the maximum value of the event timestamp: LBKSfunction main() { return Events({ from_date: "2016-01-01", to_date: "2016-01-07" }) .reduce(mixpanel.reducer.max("time")); }LBKS
This will return the maximum timestamp value among all events in the specified date range. The "time" property represents the event timestamp in milliseconds since Unix epoch.JQL Builtins
Using a custom reducer function
Alternatively, you can create a custom reducer function to find both the earliest and latest timestamps: LBKSfunction main() { return Events({ from_date: "2016-01-01", to_date: "2016-01-07" }) .reduce(function(accumulators, items){ var result = { earliest: null, latest: null }; for (var i = 0; i < accumulators.length; i++) { result.earliest = minimum(result.earliest, accumulators[i].earliest); result.latest = Math.max(result.latest, accumulators[i].latest); } for (var j = 0; j < items.length; j++) { result.earliest = minimum(result.earliest, items[j].time); result.latest = Math.max(result.latest, items[j].time); } return result; }); }LBKS// Helper function to return minimum value (ignoring null) function minimum(x,y) { if (x === null) { return y; } if (y === null) { return x; } return Math.min(x,y); }LBKS
This approach gives you both the earliest and latest timestamps in a single query.<https://docs.mixpanel.com/docs/reports/apps/jql#reducereducer-functions|JQL Transformations>
Using mixpanel.reducer.max_by()
If you want to find the entire event with the maximum timestamp (not just the timestamp value), you can use mixpanel.reducer.max_by()
: LBKSfunction main() { return Events({ from_date: "2016-01-01", to_date: "2016-01-07" }) .reduce(mixpanel.reducer.max_by("time")); }LBKS
This will return the complete event object that has the maximum timestamp.JQL BuiltinsThese approaches will help you compute the maximum date/timestamp of events in your Mixpanel data.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
is it possible not using JQL but reports ?