Sales Analysis

The script below illustrates how a sales analysis dashboard can be composed with Envision.

Image

read "/sample/Lokad_Items.tsv"
read "/sample/Lokad_Orders.tsv" as Orders
read "/sample/Lokad_PurchaseOrders.tsv" as PO

show label "Sales analysis" a1f1 tomato

Orders.Channel = "default"
oend := max(Orders.Date)

// Default currency, and currency conversions
when date >= oend - 365
  currency := mode(Orders.Currency)
Orders.NetAmount = forex(Orders.NetAmount, Orders.Currency, currency, Orders.Date)
PO.NetAmount = forex(PO.NetAmount, \
  PO.Currency, currency, PO.Date)

// KPIs at the top
show label "Current year" a2c2
when date >= oend - 365
  show table "Turnover" d2 unit:" \{currency}" with sum(Orders.NetAmount)
  show table "Orders lines" e2 with sum(Orders.1)
  show table "Units" f2 with sum(Orders.Quantity)

show label "Previous year" a3c3
when date < oend - 365 & date >= oend - 2 * 365
  show table "Turnover" d3 unit:" \{currency}" with sum(Orders.NetAmount)
  show table "Orders lines" e3 with sum(Orders.1)
  show table "Units" f3 with sum(Orders.Quantity)

// Linecharts
Week.sold := sum(Orders.NetAmount)
when date >= monday(oend) - 52 * 7 & date < monday(oend)
  show linechart "Weekly sales volume" a4f6 tomato unit:" \{currency}" with
    Week.sold as "Current Year"
    Week.sold[-52] as "Previous year"

// Split by brand and by channel
show barchart "Sales per brand" a7c9 tomato unit:" \{currency}" with
  sum(Orders.NetAmount)
  group by Brand
  order by sum(Orders.NetAmount) desc

show barchart "Sales per channel" d7f9 tomato unit:" \{currency}" with
  sum(Orders.NetAmount)
  group by Orders.Channel
  order by sum(Orders.NetAmount) desc

// Top sellers, top rising
when date >= oend - 365
  show table "Top sellers (1 year)" a10c12 tomato with
    Id
    Name
    sum(Orders.NetAmount) as "Sold" unit:" \{currency}"
    sum(Orders.Quantity) as "Quantity"
    mode(Orders.Channel) as "Main channel"
    order by sum(Orders.NetAmount) desc

when date >= oend - 31
  show table "Top sellers (1 month)" d10f12 tomato with
    Id
    Name
    sum(Orders.NetAmount) as "Sold" unit:" \{currency}"
    sum(Orders.Quantity) as "Quantity"
    mode(Orders.Channel) as "Main channel"
    order by sum(Orders.NetAmount) desc