Power Query Problems

Search PubMed and Retrieve Article Details with Excel Power Query

Khadija KhanKhadija Khan Dec 2, 2026 869 views

Question details

Build a refreshable Excel Power Query workflow that searches PubMed using worksheet keywords and retrieves counts, PMIDs, and article metadata.

Search PubMed and Retrieve Article Details with Excel Power Query
Product
Microsoft Excel Power Query and PubMed E-utilities
Device & OS
not provided
Scenario
A user wants to change search terms in Excel cells and refresh PubMed results without rebuilding the queries.
Observed behavior
The desired result is a publication count and a list of matching PMIDs with selected article details.
Before you start

Make sure Excel has Power Query and an internet connection. Decide which search terms and article fields you need, and test the PubMed XML response for a single PMID before expanding a full result set.

Solution 1Recommended

Create refreshable PubMed search and article-detail queries

Use a worksheet table for search terms, PubMed ESearch for counts and PMIDs, and EFetch for article XML.

ESearch returns the total match count separately from the PMID list. The retmax setting limits the number of IDs retrieved, not the total count.

The example joins nonblank terms with AND. Adjust the worksheet terms or the query expression if you need a different PubMed search.

1
Create the keyword table

Enter one search term per row under a Keyword header, select the cells, and choose Insert > Table. On the Table Design tab, name the table PubMedTerms.

2
Create the search query

Choose Data > Get Data > From Other Sources > Blank Query, open Advanced Editor, and replace its contents with the following M code. Name the query PubMedSearch and use Close & Load To to create a connection only: let Terms = Excel.CurrentWorkbook(){[Name="PubMedTerms"]}[Content][Keyword], CleanTerms = List.Select(List.Transform(List.RemoveNulls(Terms), each Text.Trim(Text.From(_))), each _ <> ""), SearchTerm = Text.Combine(CleanTerms, " AND "), Result = if SearchTerm = "" then error "Enter at least one keyword in PubMedTerms." else Json.Document(Web.Contents("https://eutils.ncbi.nlm.nih.gov", [RelativePath="entrez/eutils/esearch.fcgi", Query=[db="pubmed", term=SearchTerm, retmode="json", retmax="20"]])) in Result[esearchresult]

3
Load the count and PMID list

Create a new blank query in Advanced Editor with `= #table({"Count"}, {{PubMedSearch[count]}})` and load it to a worksheet. Create another blank query with `= Table.FromList(PubMedSearch[idlist], Splitter.SplitByNothing(), {"PMID"})` and load it to a worksheet. The count is the total number of matches; the list contains up to 20 PMIDs.

4
Fetch article XML

Create another blank query, open Advanced Editor, and enter the following code. It passes the returned PMIDs to EFetch and displays a message when there are no matches: let IDs = PubMedSearch[idlist], Result = if List.IsEmpty(IDs) then #table({"Message"}, {{"No matching PMIDs"}}) else Xml.Tables(Web.Contents("https://eutils.ncbi.nlm.nih.gov", [RelativePath="entrez/eutils/efetch.fcgi", Query=[db="pubmed", id=Text.Combine(IDs, ","), retmode="xml"]])) in Result

5
Expand and refresh the results

In the EFetch query preview, select nested Table links and use column expand buttons to find fields such as article title, journal, and publication date. Load the selected fields, then change the PubMedTerms cells and choose Data > Refresh All to run the workflow again.

Create refreshable PubMed search and article-detail queries
Optional article fields: Some articles have no keywords. Inspect the XML path for one PMID first, and use try ... otherwise null in custom M transformations when an optional field may be absent.
Free Microsoft Office alternative

Review PubMed result workbooks with WPS Office

WPS Office is a free, lightweight alternative for opening and working with Excel result files in a familiar spreadsheet interface. Move compatible workbooks between Office suites while using Excel for the Power Query workflow described above.

Review and organize exported PubMed result tablesOpen and edit Microsoft Excel XLSX and XLS filesWork in a familiar spreadsheet interfaceUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the publication count exceed the number of PMIDs?

ESearch returns the total match count, while retmax limits the IDs returned. Change retmax in the PubMedSearch query's Advanced Editor to retrieve more IDs, subject to PubMed's limits.

How do I search for new keywords?

Edit the Keyword cells in the PubMedTerms table, then select Data > Refresh All. The example combines nonblank rows with AND.

Why are keywords missing for some articles?

PubMed records do not all contain keyword fields. Inspect the EFetch XML for an individual PMID and use try ... otherwise null when accessing an optional field in M.

What should I check if Power Query reports a privacy or firewall error?

In Excel, open Data > Get Data > Data Source Settings and review the permissions and privacy levels for the workbook and the NCBI web source. Set appropriate levels for your environment before refreshing.

Can WPS Office run this Excel Power Query workflow?

Use Microsoft Excel Power Query to create and refresh the queries. WPS Office can open compatible Excel workbooks for reviewing and editing exported result tables.