Computing & Plot Yearly Sales for a Territory in AdventureWorksDW - Python.
The transaction of orders are stored in fact table named FactInternetSales in the Database AdventureWorksDW.
The column SalesAmount in the table FactInternetSales has the sales amount of the order in consideration.
The dimension table DimSalesTerritory has all the details of territories from which orders are being received.
As marked above the column SalesTerritoryKey is the joining column between the fact and dim table FactInternetSales and DimSalesTerritory. The column SalesTerritoryCountry has the country name. For our problem we will take United KIngdom as the territory for yearly sales analysis.
So, our final output which will be having yearly sales of the territory named United Kingdom will be having data from two tables i.e. FactInternetSales and DimSalesTerritory.
So, the sql query to fetch the desired details are as follows :
Year is the sql server inbuilt function to fetch the value of year from the date field. IN the query summation is performed on column SalesAmount of the table FactInternetSales . And hence, using the other columns in the group by clause which are present in select clause.
To learn how to connect python to sql server you can refer to the below Instrovate Technologies Blog:
Below is the python code to solve the problem :
Code Key Points:
After executing the above python program below is the outcome displayed :
Reach out to us if you are looking for Corporate Training to Build The Next Generation Analytical Workforce with an in-depth understanding of Exploratory Data Analysis , Data Visualisation, Data Analytics , AI First , Machine Learning & Deep Learning Training & Consulting helping them to take Data Informed Decision at each stage of the business.
We understand that At the present times , the Entire Industry is in a Tranformation stage with the Softwares being rebuilt with Artificial Intelligence Capabilities .
We need SMART WORKFORCE for the SMART SOFTWARES to reap the maximum return .
Whatsapp at +91-9953805788 or email at - email@example.com if you would like to know more .