Average for a week
In most data warehouses there is some form of aggregation going on, sometimes in the presentation of database summary tables, sometimes in the query tool. Often this aggregation is additive over time: how many times did this IP address connect to that web page in a month, what is the total value of baked bean sales at store X in one week, or how many phone calls were routed between London and New York in July. These are often simply COUNT() or SUM() type aggregations.
Not all time-based aggregations are additive. Take stock, clearly if we have 1000 units in stock on Monday, 2000 on Tuesday, 1000 on Wednesday and so on then our weekly stock is not going to be 1000 + 2000 + 1000 +… But what is weekly stock? Different businesses have their own measures of weekly stock; a simple case is the average stock holding in the week, others take the closing stock level for the week (ie the daily stock on the final day of the trading week). One of our customers used to use a simple Oracle AVG() on daily stock to get the weekly average, but recently asked us to change it to something a lot more complicated. Stock data is received from the stores each day they are open, some stores open 7 days a week, others six or fewer. The new stock average is to be 1/7 of the sum of daily stock recorded for the week with any missing days filled by duplicating the stock levels for the preceding day. This was fun piece of SQL to develop and ended up using LAG analytics wrapped in case statements to select the dates used in the weekly average. Does this averaging technique actually give business advantage? I doubt it, there is often not much difference between AVG() and the custom calculation and I am unsure about how valid average is anyway; especially as the business can report negative stock holdings when they sell goods from new deliveries before they book them into stock!