This is a quick article about comparing month-to-date (MTD) sales from a sales database to a sales goal for use on it's own or with data visualization tools. This query assigns a goal of $1,000,000 as the sales goal for the month, adds up all sales for the month so far, and then compares it to where your sales should be at right now by showing 'Today's Target' so that that one can see at a glance if sales are on schedule. The results look like this: Sales Goal | Today's Target | Gross Sales ------------------------------------------------------ 1000000 | 515000 | 503000 The VariablesFirst we'll need to declare some variables. We don't necessary have to, but it makes the query more readable. More easily understandable by readers or by ourselves if we need to come back to it later. The variables seems self explanatory for me, but if you're reading this, chances are that you're still learning. We started there. Anyways here are the variables:
Here are the variables as they appear in the query: DECLARE @SalesGoal INT = '1000000' The QueryNext we put all the variables together to be used in the query. Keep in mind every database is unique, so elements such as the column names or database name will have to be changed on the schema in your environment. The select statement here selects the @SalesGoal variable we set, @TodaysTarget, and adds up all of the integers in the Gross Sales column as long as the DATE of the sale was after the start of the month and today. This assumes that your database has a date column and a Gross Sales column. SELECT @SalesGoal AS "Sales Goal", @TodaysTarget AS "Todays Target", SUM([Gross Sales]) as "Gross Sales" Again, here is the final result of the query: Sales Goal | Today's Target | Gross Sales ------------------------------------------------------ 1000000 | 515000 | 503000 And here is an example chart created in Excel to add some visualization to the data:
|
RepositoriesAuthorSheridan's interests are in technology, business, music, and adventures Categories
All
Archives
June 2019
|