Skip to content

Instantly share code, notes, and snippets.

let
Source = Web.Page(Web.Contents("http://www.geohive.com/earth/world1.aspx")),
Data1 = Source{1}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data1,{{"entity World", type text}, {"code 900", Int64.Type}, {"mid-2015 est. 7,349,472,099", Int64.Type}, {"population growth in 2015 est. 1.132%", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"population growth in 2015 est. 1.132%"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"mid-2015 est. 7,349,472,099", "population"}, {"code 900", "ISO numerical"}}),
#"Indexed Table" = Table.AddKey( #"Renamed Columns", {"ISO numerical"},true)
in
#"Indexed Table"
let
Source = Web.Page(Web.Contents("https://countrycode.org/")),
Data0 = Source{0}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data0,{{"COUNTRY", type text}, {"COUNTRY CODE", type text}, {"ISO CODES", type text}, {"POPULATION", Int64.Type}, {"AREA KM2", Int64.Type}, {"GDP $USD", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"GDP $USD", "GDP"}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Renamed Columns","GDP",Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.None, false),{"GDP.1", "GDP.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"GDP.1", type number}, {"GDP.2", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Multipler", each
if [GDP.2]="Million" then 1000000 else
if [GDP.2]="Billion" then 1000000000 else
let
Source = Excel.Workbook(File.Contents("C:\Users\PeterReid\OneDrive\Blogs\development\BI\Ashley\currencies.xlsm"), null, true),
Portfolio_Table = Source{[Item="Portfolio",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Portfolio_Table,{{"CountryCode", type text}, {"Symbol", type text}, {"Last Trade Price Only", type number}, {"Last Trade Date", type text}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"CountryCode", "Last Trade Price Only"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Last Trade Price Only", "Rate"}}),
#"Indexed Table" = Table.AddKey( #"Renamed Columns", {"CountryCode"}, true)
in
#"Indexed Table"
@petermreid
petermreid / AshleyParseFiles.cs
Last active March 14, 2023 02:14
parse .dmp file into CSV
namespace ParseFiles
{
class Program
{
static string destExt = @".csv";
static string sourceExt = @".dump";
static string sourceDirectory = @"E:\Ashley\Dump\";
static string destDirectory = @"E:\Ashley\CSV\";
static void Main(string[] args)
@petermreid
petermreid / AshleyTransactions.m
Last active October 23, 2015 19:35
Ashley Madison transformation
let
Source = Csv.Document(File.Contents("E:\Ashley\CSV\Transactions.csv"),[Delimiter=",",Encoding=1252]),
#"Promoted Headers" = Table.PromoteHeaders(Source),
#"Kept First Rows" = Table.FirstN(#"Promoted Headers",100000),
#"Removed Other Columns" = Table.SelectColumns(#"Kept First Rows",{"AMOUNT", "BRAND", "CARD ENDING", "FIRST NAME", "DATE", "ERROR CODE", "TYPE", "CITY", "COUNTRY", "STATE", "ZIP"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"AMOUNT", type number},{"BRAND", type text}, {"CARD ENDING", Int64.Type},{"FIRST NAME", Int64.Type}, {"DATE", type datetime},{"ERROR CODE", Int64.Type}, {"TYPE", type text}, {"CITY", type text}, {"COUNTRY", type text}, {"STATE", type text}, {"ZIP", type text}}),
#"Remove Error Rows" = Table.SelectRows(#"Changed Type", each [ERROR CODE] is null),
#"Removed Error Columns" = Table.RemoveColumns(#"Remove Error Rows",{"ERROR CODE"}),
#"Add DateTime Column" = Table.RenameColumns (#"Removed Error Columns",{{"DATE", "Da
ut ports to variables
dataset1 <- maml.mapInputPort(1) # class: data.frame
#Create the AgeGroup bins
dataset1$AgeGroup <- ifelse(is.na(dataset1$Age), NA, ifelse(dataset1$Age < 2, "Baby", ifelse(dataset1$Age < 16, "Young", ifelse(dataset1$Age > 60, "Old", "Middle"))))
#Parse the Name for Title
getTitle <- function(name) {return (sub(" ", "", unlist(strsplit(name, "[,.]"))[2]))}
dataset1$Title=apply(matrix(dataset1$Name),1,getTitle)
#Aggregate the family memebrs together
dataset1$FamilyMembers=dataset1$SibSp+dataset1$Parch
@petermreid
petermreid / gist:3183e16d56555cc38f53
Last active August 29, 2015 14:24
Titanic Age Group
# Map 1-based optional input ports to variables
dataset1 <- maml.mapInputPort(1) # class: data.frame
# Sample operation
dataset1$AgeGroup <- ifelse(dataset1$Age < 16, "Young", ifelse(dataset1$Age > 60, "Old", "Middle"))
# Select data.frame to be sent to the output Dataset port
maml.mapOutputPort("dataset1");
@petermreid
petermreid / historical
Created June 24, 2015 10:29
Yahoo Historical Prices
let
Source = Csv.Document(Web.Contents("http://ichart.finance.yahoo.com/table.csv?s=CPU.AX&a=00&b=4&c=2014&d=07&e=01&f=2015&g=d&ignore=.csv"),[Delimiter=",",Encoding=1252]),
#"First Row as Header" = Table.PromoteHeaders(Source),
#"Changed Type" = Table.TransformColumnTypes(#"First Row as Header",{{"Date", type date}, {"Open", type number}, {"High", type number}, {"Low", type number}, {"Close", type number}, {"Volume", Int64.Type}, {"Adj Close", type number}})
in
#"Changed Type"
@petermreid
petermreid / portfolio
Last active August 29, 2015 14:23
Yahoo Quotes Portfolio
let
PortfolioSource = Excel.CurrentWorkbook(){[Name="Portfolio"]}[Content],
#"sParam" = Text.Combine(Table.ToList(Table.SelectColumns(PortfolioSource, "Symbol")),","),
#"Fields" = Excel.CurrentWorkbook(){[Name="FieldLookup"]}[Content],
#"DisplayFields" = Table.SelectRows(#"Fields",each [Display]=true),
#"fParam" = Text.Combine(Table.ToList(Table.SelectColumns(#"DisplayFields", "f")),""),
#"DisplayColumns" = Table.ToList(Table.SelectColumns(#"DisplayFields", "Name")),
#"TypeNames" = Table.SelectRows(Table.SelectColumns(#"DisplayFields", {"Name","Type"}), each [Type]="number"),
@petermreid
petermreid / web.config
Last active August 29, 2015 14:12
SharePoint Application Request Router
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{CACHE_URL}" pattern="^(https?)://" />
<add input="{HTTP_HOST}" pattern="^(.*sharepoint.*|.*msocdn.*)" />