Web function

FILTERXML function

Extracts specific values from XML text using an XPath expression; also a popular trick for splitting text into pieces.

Available in Excel 2013 and later for Windows, including Microsoft 365 for Windows; not available in Excel for the web or Excel for Mac

Excel 2013 and laterNot in Google Sheets

Syntax

FILTERXML(xml, xpath)
ArgumentWhat it means
xmlRequiredValid XML text, for example an API response returned by WEBSERVICE or XML pasted in a cell.
xpathRequiredAn XPath query that says which elements to return, e.g. "//price" or "//item[sku='P-102']/qty".

Returns: The matching values. Numbers come back as numbers; several matches spill down a column.

How FILTERXML works

FILTERXML reads XML - the tag-based format used by many older web services, RSS feeds and data exports - and returns the parts you ask for. You describe what you want with an XPath expression: //qty means "every qty element anywhere", and //item[sku='P-102']/qty means "the qty inside the item whose sku is P-102". If several elements match, the results spill down.

It was designed as the partner of WEBSERVICE, which downloads the XML. But FILTERXML became famous for a side use: by replacing a delimiter with closing and opening tags using SUBSTITUTE, any comma-separated text becomes XML, and FILTERXML can then split it into separate cells. In Microsoft 365, TEXTSPLIT does that job more simply and works on every platform.

The XML must be well formed. A stray & or < in the text, or an unclosed tag, produces #VALUE!. FILTERXML only exists in Excel for Windows.

Examples

1Pick one value with a condition

B2fx=FILTERXML(A2, "//item[sku='P-102']/qty")
AB
1Order XML
2<order><item><sku>P-101</sku><qty>3</qty></item><item><sku>P-102</sku><qty>5</qty></item></order>5

Result: 5

The XPath finds the item element whose sku is P-102 and returns its qty. The result is a real number you can calculate with.

2List every SKU

B2fx=FILTERXML(A2, "//sku")
AB
1Order XML
2<order><item><sku>P-101</sku><qty>3</qty></item><item><sku>P-102</sku><qty>5</qty></item></order>P-101
3P-102

Two sku elements match, so the two codes spill into B2:B3.

3Split comma-separated text

B2fx=FILTERXML("<t><s>" & SUBSTITUTE(A2, ",", "</s><s>") & "</s></t>", "//s")
AB
1Regions
2North,South,EastNorth
3South
4East

SUBSTITUTE turns each comma into a closing and opening tag, wrapping every region in its own element. FILTERXML then returns each element on its own row.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!The XML is not well formed (for example it contains a bare &), or the XPath is invalid or matches nothing.Escape & as &amp; with SUBSTITUTE, check the XPath, and test on a small sample.
#NAME?The workbook is open in Excel for the web or Excel for Mac.Use Power Query (Data > Get Data) or TEXTSPLIT instead.

Tips

  • In the splitting formula, change the XPath from "//s" to "//s[2]" to return only the second item, or "//s[last()]" for the last one.
  • For JSON APIs FILTERXML does not help; use Power Query to parse JSON.

Google Sheets

Use IMPORTXML(url, xpath) for XML or HTML on the web; for XML already in a cell use REGEXEXTRACT.

FILTERXML in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishFILTRERXML
DutchXML.FILTEREN
FinnishSUODATA.XML
FrenchFILTRE.XML
GermanXMLFILTERN
HungarianXMLSZŰRÉS
ItalianFILTRO.XML
Norwegian (Bokmål)FILTRERXML
Portuguese (Brazil)FILTROXML
Portuguese (Portugal)FILTRARXML
RussianФИЛЬТР.XML
SpanishXMLFILTRO
SwedishFILTRERAXML
TurkishXMLFİLTRELE