Provided: Sales, Sales Summary Row, Sales Summary Column, Sales Summary Value, Sales Summary Operation, Show Totals, Sales Summary View, Sales Summary Series
Outputs: Sales Summary, Order Count

# Gallery sales

How did print sales change over the year? The sample starts with orders in both regions in Q1 and Q2. Only the North took an order in Q3, and only the South in Q4. The blank cells show where a region had no orders that quarter.

Sales = table(["Region", "Quarter", "Channel", "Prints", "Revenue"], [["North", "Q1", "Gallery", 3, £180.00], ["North", "Q1", "Online", 1, null], ["South", "Q1", "Online", 5, £200.00], ["North", "Q2", "Gallery", 4, £160.00], ["South", "Q2", "Online", 3, £150.00], ["North", "Q3", "Online", 2, £80.00], ["South", "Q4", "Gallery", 2, £120.00]])

Sales Summary Row = "Region"
Sales Summary Column = "Quarter"
Sales Summary Value = "Revenue"
Sales Summary Operation = "sum"
Show Totals = true
Sales Summary View = "Table"
Sales Summary Series = "Q1"
Order Count = count(Sales)

## Sales summary

choice "Rows" sets Sales Summary Row from columns(Sales[Region, Quarter, Channel |])
choice "Columns" sets Sales Summary Column from columns(Sales[Region, Quarter, Channel |])
choice "Values" sets Sales Summary Value from columns(Sales[Prints, Revenue |])
choice "Summarise by" sets Sales Summary Operation from {"Total": "sum", "Average": "mean", "Count values": "count", "Count orders": "rows"}
checkbox "Show grand totals" sets Show Totals
choice "Show as" sets Sales Summary View from ("Table", "Bar chart", "Line chart")

Sales Summary = pivot(Sales, Sales Summary Row, Sales Summary Column, "" if Sales Summary Operation = "rows" else Sales Summary Value, "count" if Sales Summary Operation = "rows" else Sales Summary Operation, Show Totals) if Sales Summary Row != Sales Summary Column

Last Series Column = count(columns(Sales Summary)) - (1 if Show Totals else 0) if not is_null(Sales Summary) else 0
Series Names = slice(columns(Sales Summary), 2, Last Series Column) if Last Series Column >= 2 else []
Active Series = Sales Summary Series if match_row(Series Names, Sales Summary Series) > 0 else Series Names[1] if count(Series Names) > 0
Sales Chart Data = pivot_series(Sales Summary, 1, Active Series, Show Totals) if Sales Summary View != "Table" and not is_null(Active Series)

='''Choose different headings for rows and columns.''' if is_null(Sales Summary)

=(Sales Summary if Sales Summary View = "Table" and not is_null(Sales Summary))

='''
choice "Chart series" sets Sales Summary Series from Series Names

**=Active Series** by **=Sales Summary Row**
''' if Sales Summary View != "Table" and count(Series Names) > 0

='''The selected series is no longer in this pivot. Showing the first available column.''' if Sales Summary View != "Table" and not is_null(Active Series) and Sales Summary Series != Active Series

='''
~~~chart
bar
table: Sales Chart Data
labels: Group
values: Value
title: Sales summary
~~~
''' if Sales Summary View = "Bar chart" and not is_null(Active Series) else '''
~~~chart
line
table: Sales Chart Data
labels: Group
values: Value
title: Sales summary
~~~
''' if Sales Summary View = "Line chart" and not is_null(Active Series)

='''Add an order below to chart a series.''' if Sales Summary View != "Table" and not is_null(Sales Summary) and count(Series Names) = 0

The North’s online Q1 order is awaiting a price. Choose **Count orders** to see both North orders in Q1, then **Count values** for revenue to see the one with a recorded price. Enter the missing price below and watch the revenue total update.

## Orders

The galleries recorded **=Order Count orders**. Each amount is the total revenue for that order in pounds.

field "Sales orders" sets Sales with columns [["North", "South"], ["Q1", "Q2", "Q3", "Q4"], ["Gallery", "Online"], 1, {"optional": £0.00}]
