0

i'm trying to obtain a USD/EUR rate from the ECB site. it comes in XML, however when i use what i assume should be the xpath it yields an empty result and #N/A in googlesheets. obviously i'm defining the xpath wrong but i've tried several things and it's always empty:

here's the actual data api URL:

https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?startPeriod=2020-06-30&endPeriod=2020-06-30

when inputting this + xpath into importxml() i tried this:

=IMPORTXML("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?startPeriod=2020-06-30&endPeriod=2020-06-30", "/generic:Obs/generic:ObsValue[1]")

no go.

1 Answer 1

1

Use IMPORTDATA, QUERY and REGEXEXTRACT for this case :

=REGEXEXTRACT(QUERY(IMPORTDATA(B4);"select * WHERE Col1 starts with '<generic:ObsValue'");"=.(\d.\d+)")

Output :

USDEU

Sign up to request clarification or add additional context in comments.

7 Comments

done. yup worked like a charm and i learned a few things in the process, many thanks!
Unfortunately the use of REGEXEXTRACT turns any multi row result from QUERY into a single row answer. The answer is a neat trick for returning the top row but if you wanted the history of the data it doesn't work. I have yet to find an open source answer although there are paid solutions. You would think Google would expand the Google Visualization API Query Language to include some text wrangling regex functionality...
Use ARRAYFORMULA with REGEXEXTRACT and you're just fine. =ARRAYFORMULA(REGEXEXTRACT(QUERY(IMPORTDATA(B4);"select Col1 WHERE Col1 starts with '<generic:ObsValue'");"\d\.\d+"))
Lol - literally just found that on waking up this morning (went to bed thinking about it and dreamt a few possibilities!!) then came here to add it and you beat me to it!!
Also, there appear to be three columns returned when you select * as per the OP; if you use select Col1 instead, it allows you to place similar arrays in contiguous columns without getting an overwrite error from Excel
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.