Category variable name
month
Chart type
Series variable name
discountPercent
Title
Discount rate
Text
PREFIX schema: <https://schema.org/>

SELECT ?month (ROUND(SUM(?discount) * 1000 / SUM(?gross)) / 10 AS ?discountPercent)
WHERE {
    GRAPH ?orderGraph {
        ?order a schema:Order ;
               schema:orderDate ?orderDate ;
               schema:orderedItem ?orderItem .
        # the line's own price is net of discount; the catalogue price it was struck
        # against hangs off it as a ListPrice specification
        ?orderItem schema:orderQuantity ?quantity ;
                   schema:price ?net ;
                   schema:priceSpecification ?listPrice .
        ?listPrice schema:priceType schema:ListPrice ;
                   schema:price ?unitPrice .
        BIND(SUBSTR(STR(?orderDate), 1, 7) AS ?month)
        BIND(?quantity * ?unitPrice AS ?gross)
        BIND(?gross - ?net AS ?discount)
    }
    # The order book stops part-way through its final month, which would render as a
    # cliff rather than a trend. Drop that month — derived from the data, not pinned
    # to a date, so it stays correct if the dataset grows.
    {
        SELECT (SUBSTR(STR(MAX(?anyDate)), 1, 7) AS ?partialMonth)
        WHERE {
            GRAPH ?g { ?anyOrder a schema:Order ; schema:orderDate ?anyDate }
        }
    }
    FILTER (?month < ?partialMonth)
}
GROUP BY ?month
ORDER BY ?month
Title
Discount rate by month
Category variable name
month
Chart type
Series variable name
revenue
Title
Monthly sales trend
Category variable name
country
Chart type
Series variable name
revenue
Title
Revenue by country
Text
PREFIX schema: <https://schema.org/>

SELECT ?country (SUM(?sale) AS ?revenue)
WHERE {
    GRAPH ?orderGraph {
        ?order schema:orderedItem ?orderItem ;
               schema:orderDelivery ?delivery .
        ?orderItem schema:price ?sale .
        ?delivery schema:deliveryAddress ?address .
        ?address schema:addressCountry ?country .
    }
}
GROUP BY ?country
ORDER BY DESC(?revenue)
LIMIT 10
Title
Revenue by country
Text
PREFIX schema: <https://schema.org/>

SELECT ?month (SUM(?sale) AS ?revenue)
WHERE {
    GRAPH ?orderGraph {
        ?order a schema:Order ;
               schema:orderDate ?orderDate ;
               schema:orderedItem ?orderItem .
        ?orderItem schema:price ?sale .
        BIND(SUBSTR(STR(?orderDate), 1, 7) AS ?month)
    }
    # The order book stops part-way through its final month, which would render as a
    # cliff rather than a trend. Drop that month — derived from the data, not pinned
    # to a date, so it stays correct if the dataset grows.
    {
        SELECT (SUBSTR(STR(MAX(?anyDate)), 1, 7) AS ?partialMonth)
        WHERE {
            GRAPH ?g { ?anyOrder a schema:Order ; schema:orderDate ?anyDate }
        }
    }
    FILTER (?month < ?partialMonth)
}
GROUP BY ?month
ORDER BY ?month
Title
Sales by month