End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Total revenue for multiple periods
Calculating deltas
Creating "revenue in quarters" reports
Summary

## 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: revenue_month, total_revenue, and delta_percentage.

In the first row, leave the delta value as NULL. Order the rows by month. Here's how you can count delta_percentage:

\frac{\textrm{total amount} - \textrm{total amount from preceding months}}{\textrm{total amount from preceding months}} \cdot 100

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 EXTRACT(month FROM order_date)))
/ CAST(LAG(SUM(amount), 1) OVER (ORDER BY EXTRACT(month FROM order_date)) AS decimal(10, 2)),
2) AS delta_percentage
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.21939702332019806, "perplexity": 11856.731746426418}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-45/segments/1603107890028.58/warc/CC-MAIN-20201025212948-20201026002948-00341.warc.gz"}