is it possible to create a random cohort which contains 5% of our users in mixpanel?
kapa.ai for this JQL, can you please add in a breakdown using the field 'is festival', I want to see how many purchases per age group over time that are festivals (so 'is festival' = true) vs aren't ('is festival' = false)
function main() {
return join(
Events({
from_date: "2020-01-01",
to_date: "2025-12-31",
event_selectors: [{event: "Complete Purchase"}]
}),
People(),
{type: "inner"}
)
.filter(function(joined) {
// Filter for users where RA Area (user property) is London
return joined.user.properties["RA Area"] === "London";
})
.groupBy(
[
// Year of purchase
function(joined) {
return new Date(joined.event.time).getFullYear();
},
// Calculate age using Birthday from user profile with new buckets
mixpanel.numeric_bucket(
function(joined) {
if (!joined.user.properties.Birthday) return -1; // Handle missing Birthday
var birthDate = new Date(joined.user.properties.Birthday);
var purchaseDate = new Date(joined.event.time);
var age = purchaseDate.getFullYear() - birthDate.getFullYear();
// Adjust age if birthday hasn't occurred yet in the purchase year
if (purchaseDate.getMonth() < birthDate.getMonth() ||
(purchaseDate.getMonth() === birthDate.getMonth() &&
purchaseDate.getDate() < birthDate.getDate())) {
age--;
}
return age;
},
[0, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45] // Age buckets as requested
)
],
mixpanel.reducer.count()
);
}kapa.ai can you edit the JQL query so it filters only for 'RA Region Name' = 'London' function main() { return join( Events({ from_date: "2020-01-01", to_date: "2025-12-31", event_selectors: [{event: "Complete Purchase"}] }), People(), {type: "inner"} ) .groupBy( [ // Year of purchase function(joined) { return new Date(joined.event.time).getFullYear(); }, // Calculate age using Birthday from user profile with new buckets mixpanel.numeric_bucket( function(joined) { if (!joined.user.properties.Birthday) return -1; // Handle missing Birthday var birthDate = new Date(joined.user.properties.Birthday); var purchaseDate = new Date(joined.event.time); var age = purchaseDate.getFullYear() - birthDate.getFullYear(); // Adjust age if birthday hasn't occurred yet in the purchase year if (purchaseDate.getMonth() < birthDate.getMonth() || (purchaseDate.getMonth() === birthDate.getMonth() && purchaseDate.getDate() < birthDate.getDate())) { age--; } return age; }, [0, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45] // New age buckets as requested ) ], mixpanel.reducer.count() ); }
kapa.ai for this JQL, can you change it so it is broken down by quarter, year and not just year? function main() { return join( Events({ from_date: "2020-01-01", to_date: "2025-12-31", event_selectors: [{event: "Complete Purchase"}] }), People(), {type: "inner"} ) .groupBy( [ // Year of purchase function(joined) { return new Date(joined.event.time).getFullYear(); }, // Calculate age using Birthday from user profile with new buckets mixpanel.numeric_bucket( function(joined) { if (!joined.user.properties.Birthday) return -1; // Handle missing Birthday var birthDate = new Date(joined.user.properties.Birthday); var purchaseDate = new Date(joined.event.time); var age = purchaseDate.getFullYear() - birthDate.getFullYear(); // Adjust age if birthday hasn't occurred yet in the purchase year if (purchaseDate.getMonth() < birthDate.getMonth() || (purchaseDate.getMonth() === birthDate.getMonth() && purchaseDate.getDate() < birthDate.getDate())) { age--; } return age; }, [0, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45] // New age buckets as requested ) ], mixpanel.reducer.count() ); }
