Forum Discussion
DATA for multiple years
- 4 years ago
Hi Anonymous
Download this PBIX file with working solution
Here's the Power Query code
let GetWebPage = (Year) => let Source = Web.BrowserContents("http://planecrashinfo.com/" & Year & "/" & Year & ".htm"), #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE > * > TR > :nth-child(1)"}, {"Column2", "TABLE > * > TR > :nth-child(2)"}, {"Column3", "TABLE > * > TR > :nth-child(3)"}, {"Column4", "TABLE > * > TR > :nth-child(4)"}}, [RowSelector="TABLE > * > TR"]), #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Location / Operator", type text}, {"Aircraft Type / Registration", type text}, {"Fatalities", type text}}) in #"Changed Type", Years = {2020 .. 2022}, WebPages = List.Transform(Years, each GetWebPage(Text.From(_))), #"Converted to Table" = Table.FromList(WebPages, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Expanded Column1" = Table.ExpandTableColumn(#"Converted to Table", "Column1", {"Date", "Location / Operator", "Aircraft Type / Registration", "Fatalities"}, {"Date", "Location / Operator", "Aircraft Type / Registration", "Fatalities"}) in #"Expanded Column1"To specify which years you want data for, select the Years step, and change the numbers as highlighted in the formula bar. In this example I am getting data for years {2020 .. 2022}
Resulting in this table
Power Query may ask you to confirm security settings when you first run the query. Choose ignore if you have no security issues.
Regards
Phil
Hi Anonymous
Download this PBIX file with working solution
Here's the Power Query code
let
GetWebPage = (Year) => let
Source = Web.BrowserContents("http://planecrashinfo.com/" & Year & "/" & Year & ".htm"),
#"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE > * > TR > :nth-child(1)"}, {"Column2", "TABLE > * > TR > :nth-child(2)"}, {"Column3", "TABLE > * > TR > :nth-child(3)"}, {"Column4", "TABLE > * > TR > :nth-child(4)"}}, [RowSelector="TABLE > * > TR"]),
#"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Location / Operator", type text}, {"Aircraft Type / Registration", type text}, {"Fatalities", type text}})
in #"Changed Type",
Years = {2020 .. 2022},
WebPages = List.Transform(Years, each GetWebPage(Text.From(_))),
#"Converted to Table" = Table.FromList(WebPages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandTableColumn(#"Converted to Table", "Column1", {"Date", "Location / Operator", "Aircraft Type / Registration", "Fatalities"}, {"Date", "Location / Operator", "Aircraft Type / Registration", "Fatalities"})
in
#"Expanded Column1"
To specify which years you want data for, select the Years step, and change the numbers as highlighted in the formula bar. In this example I am getting data for years {2020 .. 2022}
Resulting in this table
Power Query may ask you to confirm security settings when you first run the query. Choose ignore if you have no security issues.
Regards
Phil
- Anonymous4 years agoNot applicable
Hi Philip Treacy,
Thanks a ton !!!!!, i have been struggling for a week with this , appreciate
regards,
dsmitha