Advanced examples
- Last UpdatedApr 15, 2026
- 5 minute read
The examples below use two shared datasets so you can follow the numbers end-to-end.
Reference data — sales dataset
Seven sale records, each with root-level properties salesperson (string), region (string), and amount (integer, "count" UoM):
|
ID |
salesperson |
region |
amount |
|---|---|---|---|
|
sale1 |
alice |
north |
500 |
|
sale2 |
bob |
south |
300 |
|
sale3 |
alice |
south |
200 |
|
sale4 |
bob |
north |
400 |
|
sale5 |
alice |
north |
700 |
|
sale6 |
bob |
south |
100 |
|
sale7 |
charlie |
north |
600 |
Reference data — bakery dataset
Three baking records, each with root-level properties item (string), cooktime (TimeSpan), and quantity (integer, "count" UoM), plus a flour component with brand (string) and count (integer, "count" UoM):
|
ID |
item |
cooktime |
quantity |
flour.brand |
flour.count |
|---|---|---|---|---|---|
|
b1 |
cupcake |
25 min |
5 |
Gold Medal |
1 |
|
b2 |
cookie |
10 min |
12 |
King Arthur |
10 |
|
b3 |
cupcake |
35 min |
10 |
Kirkland |
5 |
Example 1 — Simple summary, no grouping
Summarize cooktime across all bakery records that have a quantity ≥ 0:
SummarizeQueryEventsRequest {
Filters: [
{ Property: { PropertyId: "quantity", Operation: GreaterThanOrEquals, Value:
0, Uom: "count" } }
]
PropertiesToSummarize: [
{ PropertyId: "cooktime" }
]
}
All three records match the filter. cooktime is a TimeSpan, so values are converted to seconds (25 min = 1500 s, 10 min = 600 s, 35 min = 2100 s).
Response — a single ResourceSummary with no group fields:
|
Count |
cooktime.Count |
Min |
Max |
Average |
Sum |
Uom |
|---|---|---|---|---|---|---|
|
3 |
3 |
600 |
2100 |
1400 |
4200 |
second |
Example 2 — Group by a root property
Break down sales by region:
SummarizeQueryEventsRequest {
Filters: [
{ Property: { PropertyId: "amount", Operation: GreaterThanOrEquals, Value:
0, Uom: "count" } }
]
GroupByProperties: [ { PropertyId: "region" } ]
PropertiesToSummarize: [ { PropertyId: "amount" } ]
}
Response — one ResourceSummary per distinct region. Each entry's GroupProperties[0].GroupProperty.Value is the region string:
|
Group: region |
Count |
amount.Count |
Min |
Max |
Average |
Sum |
|---|---|---|---|---|---|---|
|
north |
4 |
4 |
400 |
700 |
550 |
2200 |
|
south |
3 |
3 |
100 |
300 |
200 |
600 |
Example 3 — Group by a component property and summarize a root property
Group bakery records by the flour brand (inside the flour component) and aggregate root-level cooktime:
SummarizeQueryEventsRequest {
Filters: [
{ Property: { PropertyId: "quantity", Operation: GreaterThanOrEquals, Value:
0, Uom: "count" } }
]
GroupByProperties: [ { PropertyId: "brand", TypeId: "flour" } ]
PropertiesToSummarize: [ { PropertyId: "cooktime" } ]
}
Each of the three records has a distinct brand, so each forms its own group. Resources that have no flour component (or no brand property within it) would be excluded from all summaries entirely.
Response — one ResourceSummary per brand, GroupProperties[0].TypeId = "flour":
|
Group: flour.brand |
Count |
cooktime.Count |
Min |
Max |
Average |
Sum |
Uom |
|---|---|---|---|---|---|---|---|
|
Gold Medal |
1 |
1 |
1500 |
1500 |
1500 |
1500 |
second |
|
King Arthur |
1 |
1 |
600 |
600 |
600 |
600 |
second |
|
Kirkland |
1 |
1 |
2100 |
2100 |
2100 |
2100 |
second |
Example 4 — Multiple group-by properties (compound key)
Group sales by salesperson AND region simultaneously:
SummarizeQueryEventsRequest {
Filters: [
{ Property: { PropertyId: "amount", Operation: GreaterThanOrEquals, Value:
0, Uom: "count" } }
]
GroupByProperties: [
{ PropertyId: "salesperson" },
{ PropertyId: "region" }
]
PropertiesToSummarize: [ { PropertyId: "amount" } ]
}
Response — one ResourceSummary per (salesperson, region) pair. Each entry's GroupProperties contains two elements. Charlie has no south sales so no entry is produced for (charlie, south):
|
Group: salesperson |
Group: region |
Count |
amount.Count |
Min |
Max |
Average |
Sum |
|---|---|---|---|---|---|---|---|
|
alice |
north |
2 |
2 |
500 |
700 |
600 |
1200 |
|
alice |
south |
1 |
1 |
200 |
200 |
200 |
200 |
|
bob |
north |
1 |
1 |
400 |
400 |
400 |
400 |
|
bob |
south |
2 |
2 |
100 |
300 |
200 |
400 |
|
charlie |
north |
1 |
1 |
600 |
600 |
600 |
600 |
Reference data — Operations dataset
Two operation records with a shifts relationship pointing to shift records. Shift records store the productivity property being summarized.
Operations (the records being queried — Name starts with "op"):
|
ID |
operationstate |
amount |
shifts relationship |
|---|---|---|---|
|
oper1 |
ready |
5.5 |
→ shift1, shift2 |
|
oper2 |
waiting |
10.2 |
→ shift1, shift3, shift4 |
Shifts (relationship targets):
|
ID |
supervisor |
productivity (count) |
|---|---|---|
|
shift1 |
john |
7 |
|
shift2 |
john |
37 |
|
shift3 |
sean |
73 |
|
shift4 |
john |
24 |
Example 5 — Group by relationship target
Group the two operation records by each individual shift they are linked to via the shifts relationship:
SummarizeQueryEventsRequest {
Filters: [ { Property: { PropertyId: "Name", Operation: StartsWith, Value: "op"
} } ]
GroupByRelationships: [ { RelationshipId: "shifts" } ]
PropertiesToSummarize: [ { PropertyId: "amount" } ]
}
Both oper1 and oper2 link to shift1, so shift1's group aggregates both records. The remaining shifts are each referenced by only one operation. ResourceSummary.GroupRelationships[0].Target.TargetId identifies the specific shift.
Response — one ResourceSummary per distinct shift target:
|
Group: shifts target |
Count |
amount.Count |
Min |
Max |
Average |
Sum |
|---|---|---|---|---|---|---|
|
shift1 |
2 |
2 |
5.5 |
10.2 |
7.85 |
15.7 |
|
shift2 |
1 |
1 |
5.5 |
5.5 |
5.5 |
5.5 |
|
shift3 |
1 |
1 |
10.2 |
10.2 |
10.2 |
10.2 |
|
shift4 |
1 |
1 |
10.2 |
10.2 |
10.2 |
10.2 |
Example 6 — External relationship groups (parent-to-children)
Summarize shift records grouped by which operation they belong to. The shift records don't store a back-reference to their parent operation, so provide the parent→children mapping via InRelationshipGroups. Here the resources being queried and summarized are the shift records (not the operations):
SummarizeQueryEventsRequest {
Filters: [ { Property: { PropertyId: "productivity", Operation: GreaterThanOrEquals,
Value: 0, Uom: "count" } } ]
PropertiesToSummarize: [ { PropertyId: "productivity" } ]
InRelationshipGroups: {
"oper1": { Id: "shifts", Targets: [ { TargetId: "shift1" }, { TargetId: "shift2"
} ] },
"oper2": { Id: "shifts", Targets: [ { TargetId: "shift1" }, { TargetId: "shift3"
}, { TargetId: "shift4" } ] }
}
}
shift1 belongs to both oper1 and oper2, so it contributes to both groups independently. ResourceSummary.InRelationshipGroups carries the group key ("oper1" or "oper2").
Response — one ResourceSummary per group key:
|
Group: key |
Count |
productivity.Count |
Min |
Max |
Average |
Sum |
Uom |
|---|---|---|---|---|---|---|---|
|
oper1 |
2 |
2 |
7 |
37 |
22 |
44 |
count |
|
oper2 |
3 |
3 |
7 |
73 |
34.67 |
104 |
count |
External groups can also be combined with GroupByProperties to produce a summary per (group key, property value) pair.
Example 7 — UoM conversion
Summarize multiple properties, requesting specific output units per property:
SummarizeQueryEventsRequest {
Filters: [ ... ]
PropertiesToSummarize: [
{ PropertyId: "length", Uom: "ft" }, // stored in metres, converted to feet
{ PropertyId: "width", Uom: "cm" }, // stored in inches, converted to centimetres
{ PropertyId: "height" } // no Uom — uses stored unit
]
}
Conversions are applied before aggregation, so Min, Max, Sum, and Average are all in the requested unit. PropertySummary.Uom reflects the output unit. See When no UoM is specified about mixing incompatible units.
Example 8 — Summarizing multiple properties simultaneously
Multiple entries in PropertiesToSummarize produce multiple PropertySummary entries inside the same ResourceSummary:
PropertiesToSummarize: [
{ PropertyId: "cooktime" },
{ PropertyId: "quantity", Uom: "count" }
]
Using the bakery dataset with no grouping:
|
property |
Count |
Min |
Max |
Average |
Sum |
Uom |
|---|---|---|---|---|---|---|
|
cooktime |
3 |
600 |
2100 |
1400 |
4200 |
second |
|
quantity |
3 |
5 |
12 |
9 |
27 |
count |
If one property fails (for example, is non-numeric), its error is reported in SummaryErrors while the other properties still produce valid summaries.