• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with Power Query M Code to Load Data from Multiple Web Pages

anishms

Member
Dear Experts,

I’m posting this to seek help in retrieving data from multiple web pages that follow the same URL pattern. I used the following code (with Copilot’s suggestions) to load the pages from 1198 to 1242, but I couldn’t get it to work. Could someone please help me with the correct M code?

let
PageNumbers = {1198..1242},
BaseUrl = "https://www.cms.gov/icd10m/FY2024-version41.1-fullcode-cms/fullcode_cms/P",
Urls = List.Transform(PageNumbers, each BaseUrl & Text.From(_) & ".html"),
GetPageData = (url as text) =>
try
Web.Page(Web.Contents(url))
otherwise
null,
Pages = List.Transform(Urls, each GetPageData(_)),
CombinedTables = List.Transform(
Pages,
each if _ <> null and List.Count(_) > 3 then _{3}[Data] else null
),
FilteredTables = List.RemoveNulls(CombinedTables),
FinalTable = if List.Count(FilteredTables) > 0 then Table.Combine(FilteredTables) else #table({}, {})
in
FinalTable
 
Back
Top