Created
November 22, 2023 19:05
-
-
Save ncalm/e154131bac98e843c28d8820c0b894fa to your computer and use it in GitHub Desktop.
SQL view and Power Query for replicating GROUPBY testing workbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Install Adventure Works DW 2019 from this link: | |
https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2019.bak | |
View below is used by Power Query in GROUPBY demonstrations | |
*/ | |
USE [AdventureWorksDW2019] | |
GO | |
/****** Object: View [dbo].[vSales] Script Date: 11/22/2023 12:02:03 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE VIEW [dbo].[vSales] | |
AS | |
SELECT | |
fis.OrderDate, | |
pc.EnglishProductCategoryName AS category, | |
ps.EnglishProductSubcategoryName AS sub_category, | |
p.EnglishProductName AS product, | |
fis.SalesAmount, | |
fis.OrderQuantity | |
FROM FactInternetSales fis | |
INNER JOIN DimProduct p ON fis.ProductKey = p.ProductKey | |
INNER JOIN DimProductSubcategory ps ON p.ProductSubcategoryKey = ps.ProductSubcategoryKey | |
INNER JOIN DimProductCategory pc ON ps.ProductCategoryKey = pc.ProductCategoryKey; | |
GO | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = Sql.Databases("YOURSERVERINSTANCE"), | |
AdventureWorksDW2019 = Source{[Name="AdventureWorksDW2019"]}[Data], | |
dbo_vSales = AdventureWorksDW2019{[Schema="dbo",Item="vSales"]}[Data], | |
#"Changed Type" = Table.TransformColumnTypes(dbo_vSales,{{"OrderDate", type date}}), | |
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"category", "Category"}, {"sub_category", "SubCategory"}, {"product", "Product"}}) | |
in | |
#"Renamed Columns" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment