У меня возникли проблемы с получением исторических данных о курсах валют из API ЕЦБ: https://data.ecb.europa.eu/help/api/overview
Я абсолютный новичок и до сих пор мне удавалось узнать текущие курсы валют только через https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
Конечный результат, которого я хотел бы достичь, примерно такой (курсы обмена евро):
... назад к 1 января 2000 г. (или, если информация не существует так давно: настолько далеко, насколько она существует)
Я работаю в Power Query M (PowerBI).
Сейчас я использую следующий запрос, однако он не выводит то, что мне действительно нужно. Выводит это:
let
url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",
Source = Xml.Tables(Web.Contents(url)),
ExpandedSender = Table.ExpandTableColumn(Source, "Sender", {"name"}, {"Sender.name"}),
ExpandedEurofxref = Table.ExpandTableColumn(ExpandedSender, "http://www.ecb.int/vocabulary/2002-08-01/eurofxref", {"Cube"}, {"Eurofxref.Cube"}),
ExpandedCube = Table.ExpandTableColumn(ExpandedEurofxref, "Eurofxref.Cube", {"Cube"}, {"Cube.Cube"}),
ExpandedCubeCube = Table.ExpandTableColumn(ExpandedCube, "Cube.Cube", {"Cube", "Attribute:time"}, {"Cube.Cube.Cube", "Date"}),
ExpandedRate = Table.ExpandTableColumn(ExpandedCubeCube, "Cube.Cube.Cube", {"Attribute:currency", "Attribute:rate"}, {"Currency", "Rate"}),
FilteredCurrencies = Table.SelectRows(ExpandedRate, each [Currency] = "USD" or [Currency] = "GBP"),
ReplacedComma = Table.TransformColumns(FilteredCurrencies, {{"Rate", each Text.Replace(Text.From(_), ".", ","), type text}}),
USDDate = Table.SelectRows(ReplacedComma, each [Currency] = "USD"){0}[Date],
EURRow = Table.FromRecords({
[Currency = "EUR", Rate = "1", Date = USDDate]
}),
CombinedTable = Table.Combine({ReplacedComma, EURRow}),
#"Removed Columns" = Table.RemoveColumns(CombinedTable,{"subject", "Sender.name"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Currency", "Currency_name"}})
in
#"Renamed Columns"
Был бы очень признателен за помощь. Спасибо большое <3 -Л
Вставьте эту последнюю процедуру в конец кода...
...
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Currency", "Currency_name"}}),
#"Coluna em pivô" = Table.Pivot(#"Renamed Columns", List.Distinct(#"Renamed Columns"[Currency_name]), "Currency_name", "Rate", List.Max)
in
#"Coluna em pivô"
Пришлось искать источник, в котором есть все, посмотреть, то ли это вам нужно. Если ответ помог, отметьте его, этот ответ полезен. Евро всегда равен 1. Если вам нужен столбец евро, поместите новый столбец со значением 1. В другом коде вашим источником является ежедневный отчет.
let
url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-sdmx.xml",
Source = Xml.Tables(Web.Contents(url)),
Table = Source{1}[Table],
Table1 = Table{0}[Table],
Table2 = Table1{1}[Table],
#"Obs Expandido" = Table.ExpandTableColumn(Table2, "Obs", {"Attribute:TIME_PERIOD", "Attribute:OBS_VALUE"}, {"Obs.Attribute:TIME_PERIOD", "Obs.Attribute:OBS_VALUE"}),
#"Linhas Filtradas" = Table.SelectRows(#"Obs Expandido", each ([#"Attribute:CURRENCY"] = "GBP" or [#"Attribute:CURRENCY"] = "USD")),
#"Colunas Reordenadas" = Table.ReorderColumns(#"Linhas Filtradas",{"Obs.Attribute:TIME_PERIOD", "Obs.Attribute:OBS_VALUE", "Attribute:CURRENCY", "Attribute:FREQ", "Attribute:CURRENCY_DENOM", "Attribute:EXR_TYPE", "Attribute:EXR_SUFFIX", "Attribute:TIME_FORMAT", "Attribute:COLLECTION"}),
#"Colunas Removidas" = Table.RemoveColumns(#"Colunas Reordenadas",{"Attribute:FREQ", "Attribute:CURRENCY_DENOM", "Attribute:EXR_TYPE", "Attribute:EXR_SUFFIX", "Attribute:TIME_FORMAT", "Attribute:COLLECTION"}),
#"Coluna em pivô" = Table.Pivot(#"Colunas Removidas", List.Distinct(#"Colunas Removidas"[#"Attribute:CURRENCY"]), "Attribute:CURRENCY", "Obs.Attribute:OBS_VALUE"),
#"Linhas Classificadas" = Table.Sort(#"Coluna em pivô",{{"Obs.Attribute:TIME_PERIOD", Order.Descending}})
in
#"Linhas Classificadas"
или
let
url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml",
Source = Xml.Tables(Web.Contents(url)),
#"Sender Expandido" = Table.ExpandTableColumn(Source, "Sender", {"name"}, {"Sender.name"}),
#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref Expandido" = Table.ExpandTableColumn(#"Sender Expandido", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref", {"Cube"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube"}),
#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube Expandido" = Table.ExpandTableColumn(#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref Expandido", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube", {"Cube"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube"}),
#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube Expandido" = Table.ExpandTableColumn(#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube Expandido", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube", {"Cube", "Attribute:time"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Attribute:time"}),
#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube Expandido" = Table.ExpandTableColumn(#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube Expandido", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube", {"Attribute:currency", "Attribute:rate"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube.Attribute:curr", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube.Attribute:rate"}),
#"Colunas Removidas" = Table.RemoveColumns(#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube Expandido",{"subject", "Sender.name"}),
#"Colunas Renomeadas" = Table.RenameColumns(#"Colunas Removidas",{{"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube.Attribute:curr", "Currency"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Cube.Attribute:rate", "Rate"}, {"http://www.ecb.int/vocabulary/2002-08-01/eurofxref.Cube.Cube.Attribute:time", "Time"}}),
#"Colunas Reordenadas" = Table.ReorderColumns(#"Colunas Renomeadas",{"Time", "Currency", "Rate"}),
#"Linhas Filtradas" = Table.SelectRows(#"Colunas Reordenadas", each ([Currency] = "GBP" or [Currency] = "USD")),
#"Coluna em pivô" = Table.Pivot(#"Linhas Filtradas", List.Distinct(#"Linhas Filtradas"[Currency]), "Currency", "Rate"),
#"Linhas Classificadas" = Table.Sort(#"Coluna em pivô",{{"Time", Order.Descending}}),
#"Valor Substituído" = Table.ReplaceValue(#"Linhas Classificadas",".",",",Replacer.ReplaceText,{"USD"}),
#"Valor Substituído1" = Table.ReplaceValue(#"Valor Substituído",".",",",Replacer.ReplaceText,{"GBP"})
in
#"Valor Substituído1"
Это прекрасно, большое спасибо за вашу помощь. ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml ecb.europa.eu/stats/eurofxref/eurofxref-sdmx.xml Я даже сам не смог найти эти URL-адреса при попытке. Очень проницательно. Еще раз спасибо.
Спасибо! Это изменило столбцы и строки на тот формат, который я описал в своем исходном сообщении, однако мне все еще не хватает исторических данных, я получаю только одну запись за сегодня. Может быть, у вас тоже есть идея?