hi @MichelDiz
Thanks for your guidance.
I created a seperate entity for “week” , below is the Query response for the same
my 32 week uid is same for the 2 seperate orders, becuase they both are purchased in the same week_id
but i’m stuck while applying group by in the query. Kindly help please
Below ones i tried, please guide what i applied wrong in groupby to get 2 distinct_weeks_shopped for my average_weekly_spend formula.
Query1.
{
users_orders(func: uid(0x88ba6)) {
customer.customer_name
customer.order {
ONSA as order.net_spend_amount
order.week{
week.week_id
}
}
total_spend as sum(val(ONSA))
#rough as ONSA1
avg_weekly_spend: math(total_spend/2)
}
}
Response 1
{
"data": {
"users_orders": [
{
"customer.customer_name": "Mohn Doe",
"customer.order": [
{
"order.net_spend_amount": 60,
"order.week": {
"week.week_id": "28"
}
},
{
"order.net_spend_amount": 80,
"order.week": {
"week.week_id": "32"
}
},
{
"order.net_spend_amount": 120,
"order.week": {
"week.week_id": "32"
}
}
],
"sum(val(ONSA))": 260,
"avg_weekly_spend": 130
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 96792,
"processing_ns": 1417424,
"encoding_ns": 65533,
"assign_timestamp_ns": 714638,
"total_ns": 2400078
},
"txn": {
"start_ts": 17554001
},
"metrics": {
"num_uids": {
"": 1,
"_total": 11,
"customer.customer_name": 1,
"customer.order": 1,
"order.net_spend_amount": 3,
"order.week": 3,
"week.week_id": 2
}
}
}
}
Query2:
{
users_orders(func: uid(0x88ba6)) {
customer.customer_name
customer.order {
ONSA as order.net_spend_amount
}
customer.order @groupby(week){
count(uid)
}
total_spend as sum(val(ONSA))
#rough as ONSA1
avg_weekly_spend: math(total_spend/2)
}
}
Response 2:
{
"data": {
"users_orders": [
{
"customer.customer_name": "Mohn Doe",
"customer.order": [
{
"order.net_spend_amount": 60
},
{
"order.net_spend_amount": 80
},
{
"order.net_spend_amount": 120
}
],
"sum(val(ONSA))": 260,
"avg_weekly_spend": 130
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 224887,
"processing_ns": 1428683,
"encoding_ns": 52710,
"assign_timestamp_ns": 1486957,
"total_ns": 3295485
},
"txn": {
"start_ts": 17554020
},
"metrics": {
"num_uids": {
"": 1,
"_total": 7,
"customer.customer_name": 1,
"customer.order": 2,
"order.net_spend_amount": 3
}
}
}
}