Instruction
Very well done! Let's try one more exercise before we move on.
Exercise
For each month of 2017, calculate the total monthly revenue from orders shipped to the USA and the percentage revenue change (delta) as compared to the previous month. Show three columns: RevenueMonth, TotalRevenue, and DeltaPercentage.
In the first row, leave the delta value as NULL. Order the rows by month. Here's how you can count DeltaPercentage:
Remember to round the result to the second decimal point.
Stuck? Here's a hint!
Use the following expression in the last column:
ROUND( 100 * (SUM(Amount) - LAG(SUM(Amount), 1) OVER (ORDER BY DATEPART(Month, OrderDate)) / CAST(LAG(SUM(Amount), 1) OVER (ORDER BY DATEPART(Month, OrderDate)) AS decimal(10,2))), 2) AS DeltaPercentage




