group
The keyword group is used always used as group by within a tile block in Envision.
‘show .. with .. group by expr’, grouping at the tile-level
The group by option is similar to a by grouping, but applied to the whole tile-block.
table C = with
[| as Country, as Region, as UnitSold, as InEuros |]
[| "France", "Europe", 100, 10000 |]
[| "Germany", "Europe", 125, 12500 |]
[| "USA", "North America", 1000, 100000 |]
[| "Canada", "North America", 75, 7500 |]
show table "Units per Region" with
sum(C.UnitSold) as "Units" // implicit 'by C.Region'
sum(C.InEuros) as "€" // implicit 'by C.Region'
group by C.Region
// Units,€
// 225,22500
// 1075,107500
The group by is a syntactic sugar for:
table C = with
[| as Country, as Region, as UnitSold, as InEuros |]
[| "France", "Europe", 100, 10000 |]
[| "Germany", "Europe", 125, 12500 |]
[| "USA", "North America", 1000, 100000 |]
[| "Canada", "North America", 75, 7500 |]
table Regions = by C.Region // table 'Regions' is upstream of table 'C'
show table "Units per Region" with
sum(C.UnitSold) into Regions as "Units" // aggregate into an upstream table
sum(C.InEuros) into Regions as "€" // idem
‘show .. with .. group into T’, grouping into an explicit table
The group into option assigns a tile grouping target explicitly, similar to into for aggregations.
table Orders = with
[| as Product, as Qty |]
[| "apple", 3 |]
[| "apple", 7 |]
[| "orange", 2 |]
table Products[product] = by Orders.Product
Products.Sold = sum(Orders.Qty)
show table "Sales" with
product
Products.Sold
group into Products
Grouping by tuples
group by supports tuples. Columns that are constant within the group can appear without an explicit aggregator.
table Orders = with
[| as Product, as OrderDate, as Qty |]
[| "apple", date(2020, 4, 15), 3 |]
[| "apple", date(2020, 4, 16), 7 |]
[| "orange", date(2020, 4, 16), 2 |]
show table "Daily sales" with
Orders.Product
Orders.OrderDate
sum(Orders.Qty) as "Sold"
group by [Orders.Product, Orders.OrderDate]