Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
john121
Frequent Visitor

Dynamic Connection to Web URL containing YYYY-YY

My Url link - http://www.quanthockey.com/khl/seasons/2017-18-khl-players-stats.html

 

I need to paas 2 parameters both which are year , first parameter in format yyyy and second in yy.

I'm having issue how to pass the second parameter.

 

(year,yr as number)=>

let
Source = Csv.Document(Web.Contents("http://www.quanthockey.com/khl/seasons/" & ""&Number.ToText(year)&"" & "-" & ""&Number.ToText(year)&"" & ".csv"),[Delimiter=",", Columns=17, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text},
{"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}, {"Column13", type text}, {"Column14", type text}, {"Column15", type text}, {"Column16", type text}, {"Column17", type text}})
in
#"Changed Type"

 

The above query is not running correctly for me.

Let me know what is the issue.

 

Thanks for the help

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @john121 

 

The url in your custom function is not valid. It cannot access such a csv file. 

vjingzhang_0-1657100163706.png

 

If you want to get data from the html table in this url link - http://www.quanthockey.com/khl/seasons/2017-18-khl-players-stats.html, you can use the Web connector directly. Go to New source > Web, enter above url link and select Anonymous for authentication. In Navigator window, select the html table that has all data. 

vjingzhang_1-1657100723244.png

This is the code generated automatically. 

let
    Source = Web.BrowserContents("https://www.quanthockey.com/khl/seasons/2017-18-khl-players-stats.html"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE[id='statistics'] > * > TR > :nth-child(1)"}, {"Column2", "TABLE[id='statistics'] > * > TR > :nth-child(2)"}, {"Column3", "TABLE[id='statistics'] > * > TR > :nth-child(3)"}, {"Column4", "TABLE[id='statistics'] > * > TR > :nth-child(4)"}, {"Column5", "TABLE[id='statistics'] > * > TR > :nth-child(5)"}, {"Column6", "TABLE[id='statistics'] > * > TR > :nth-child(6)"}, {"Column7", "TABLE[id='statistics'] > * > TR > :nth-child(7)"}, {"Column8", "TABLE[id='statistics'] > * > TR > :nth-child(8)"}, {"Column9", "TABLE[id='statistics'] > * > TR > :nth-child(9)"}, {"Column10", "TABLE[id='statistics'] > * > TR > :nth-child(10)"}, {"Column11", "TABLE[id='statistics'] > * > TR > :nth-child(11)"}, {"Column12", "TABLE[id='statistics'] > * > TR > :nth-child(12)"}, {"Column13", "TABLE[id='statistics'] > * > TR > :nth-child(13)"}, {"Column14", "TABLE[id='statistics'] > * > TR > :nth-child(14)"}, {"Column15", "TABLE[id='statistics'] > * > TR > :nth-child(15)"}, {"Column16", "TABLE[id='statistics'] > * > TR > :nth-child(16)"}, {"Column17", "TABLE[id='statistics'] > * > TR > :nth-child(17)"}}, [RowSelector="TABLE[id='statistics'] > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Rk", Int64.Type}, {"", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Pos", type text}, {"GP", Int64.Type}, {"G", Int64.Type}, {"A", Int64.Type}, {"P", Int64.Type}, {"PIM", Int64.Type}, {"+/-", Int64.Type}, {"PPG", Int64.Type}, {"SHG", Int64.Type}, {"GWG", Int64.Type}, {"G/GP", type number}, {"A/GP", type number}, {"P/GP", type number}})
in
    #"Changed Type"

 

To convert it into a custom function with dynamic year parameters, you can use below code

(year, yr as number)=>
let
    Source = Web.BrowserContents("https://www.quanthockey.com/khl/seasons/"&Number.ToText(year)&"-"&Number.ToText(yr)&"-khl-players-stats.html"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE[id='statistics'] > * > TR > :nth-child(1)"}, {"Column2", "TABLE[id='statistics'] > * > TR > :nth-child(2)"}, {"Column3", "TABLE[id='statistics'] > * > TR > :nth-child(3)"}, {"Column4", "TABLE[id='statistics'] > * > TR > :nth-child(4)"}, {"Column5", "TABLE[id='statistics'] > * > TR > :nth-child(5)"}, {"Column6", "TABLE[id='statistics'] > * > TR > :nth-child(6)"}, {"Column7", "TABLE[id='statistics'] > * > TR > :nth-child(7)"}, {"Column8", "TABLE[id='statistics'] > * > TR > :nth-child(8)"}, {"Column9", "TABLE[id='statistics'] > * > TR > :nth-child(9)"}, {"Column10", "TABLE[id='statistics'] > * > TR > :nth-child(10)"}, {"Column11", "TABLE[id='statistics'] > * > TR > :nth-child(11)"}, {"Column12", "TABLE[id='statistics'] > * > TR > :nth-child(12)"}, {"Column13", "TABLE[id='statistics'] > * > TR > :nth-child(13)"}, {"Column14", "TABLE[id='statistics'] > * > TR > :nth-child(14)"}, {"Column15", "TABLE[id='statistics'] > * > TR > :nth-child(15)"}, {"Column16", "TABLE[id='statistics'] > * > TR > :nth-child(16)"}, {"Column17", "TABLE[id='statistics'] > * > TR > :nth-child(17)"}}, [RowSelector="TABLE[id='statistics'] > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Rk", Int64.Type}, {"", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Pos", type text}, {"GP", Int64.Type}, {"G", Int64.Type}, {"A", Int64.Type}, {"P", Int64.Type}, {"PIM", Int64.Type}, {"+/-", Int64.Type}, {"PPG", Int64.Type}, {"SHG", Int64.Type}, {"GWG", Int64.Type}, {"G/GP", type number}, {"A/GP", type number}, {"P/GP", type number}})
in
    #"Changed Type"

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @john121 

 

The url in your custom function is not valid. It cannot access such a csv file. 

vjingzhang_0-1657100163706.png

 

If you want to get data from the html table in this url link - http://www.quanthockey.com/khl/seasons/2017-18-khl-players-stats.html, you can use the Web connector directly. Go to New source > Web, enter above url link and select Anonymous for authentication. In Navigator window, select the html table that has all data. 

vjingzhang_1-1657100723244.png

This is the code generated automatically. 

let
    Source = Web.BrowserContents("https://www.quanthockey.com/khl/seasons/2017-18-khl-players-stats.html"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE[id='statistics'] > * > TR > :nth-child(1)"}, {"Column2", "TABLE[id='statistics'] > * > TR > :nth-child(2)"}, {"Column3", "TABLE[id='statistics'] > * > TR > :nth-child(3)"}, {"Column4", "TABLE[id='statistics'] > * > TR > :nth-child(4)"}, {"Column5", "TABLE[id='statistics'] > * > TR > :nth-child(5)"}, {"Column6", "TABLE[id='statistics'] > * > TR > :nth-child(6)"}, {"Column7", "TABLE[id='statistics'] > * > TR > :nth-child(7)"}, {"Column8", "TABLE[id='statistics'] > * > TR > :nth-child(8)"}, {"Column9", "TABLE[id='statistics'] > * > TR > :nth-child(9)"}, {"Column10", "TABLE[id='statistics'] > * > TR > :nth-child(10)"}, {"Column11", "TABLE[id='statistics'] > * > TR > :nth-child(11)"}, {"Column12", "TABLE[id='statistics'] > * > TR > :nth-child(12)"}, {"Column13", "TABLE[id='statistics'] > * > TR > :nth-child(13)"}, {"Column14", "TABLE[id='statistics'] > * > TR > :nth-child(14)"}, {"Column15", "TABLE[id='statistics'] > * > TR > :nth-child(15)"}, {"Column16", "TABLE[id='statistics'] > * > TR > :nth-child(16)"}, {"Column17", "TABLE[id='statistics'] > * > TR > :nth-child(17)"}}, [RowSelector="TABLE[id='statistics'] > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Rk", Int64.Type}, {"", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Pos", type text}, {"GP", Int64.Type}, {"G", Int64.Type}, {"A", Int64.Type}, {"P", Int64.Type}, {"PIM", Int64.Type}, {"+/-", Int64.Type}, {"PPG", Int64.Type}, {"SHG", Int64.Type}, {"GWG", Int64.Type}, {"G/GP", type number}, {"A/GP", type number}, {"P/GP", type number}})
in
    #"Changed Type"

 

To convert it into a custom function with dynamic year parameters, you can use below code

(year, yr as number)=>
let
    Source = Web.BrowserContents("https://www.quanthockey.com/khl/seasons/"&Number.ToText(year)&"-"&Number.ToText(yr)&"-khl-players-stats.html"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE[id='statistics'] > * > TR > :nth-child(1)"}, {"Column2", "TABLE[id='statistics'] > * > TR > :nth-child(2)"}, {"Column3", "TABLE[id='statistics'] > * > TR > :nth-child(3)"}, {"Column4", "TABLE[id='statistics'] > * > TR > :nth-child(4)"}, {"Column5", "TABLE[id='statistics'] > * > TR > :nth-child(5)"}, {"Column6", "TABLE[id='statistics'] > * > TR > :nth-child(6)"}, {"Column7", "TABLE[id='statistics'] > * > TR > :nth-child(7)"}, {"Column8", "TABLE[id='statistics'] > * > TR > :nth-child(8)"}, {"Column9", "TABLE[id='statistics'] > * > TR > :nth-child(9)"}, {"Column10", "TABLE[id='statistics'] > * > TR > :nth-child(10)"}, {"Column11", "TABLE[id='statistics'] > * > TR > :nth-child(11)"}, {"Column12", "TABLE[id='statistics'] > * > TR > :nth-child(12)"}, {"Column13", "TABLE[id='statistics'] > * > TR > :nth-child(13)"}, {"Column14", "TABLE[id='statistics'] > * > TR > :nth-child(14)"}, {"Column15", "TABLE[id='statistics'] > * > TR > :nth-child(15)"}, {"Column16", "TABLE[id='statistics'] > * > TR > :nth-child(16)"}, {"Column17", "TABLE[id='statistics'] > * > TR > :nth-child(17)"}}, [RowSelector="TABLE[id='statistics'] > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Rk", Int64.Type}, {"", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Pos", type text}, {"GP", Int64.Type}, {"G", Int64.Type}, {"A", Int64.Type}, {"P", Int64.Type}, {"PIM", Int64.Type}, {"+/-", Int64.Type}, {"PPG", Int64.Type}, {"SHG", Int64.Type}, {"GWG", Int64.Type}, {"G/GP", type number}, {"A/GP", type number}, {"P/GP", type number}})
in
    #"Changed Type"

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

amitchandak
Super User
Super User

@john121 , check this can help

https://blog.crossjoin.co.uk/2016/08/16/using-the-relativepath-and-query-options-with-web-contents-i...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors