Forum Discussion
2 data sources - How to Catch ERROR dynamically and and execute alternative query?
Hi guys,
I am new to M Code and I was wondering if anyone could give me a help.
I wrote the code below to connect to a data source and look for the column "ForexExchange". If the column is not found the ERROR should be caught and it should connect to a second data source to extract the information from there.
let
get_bidAsk = (file as text) =>
let
Source = Web.Page(Web.Contents(file)),
Data3 = Source{3}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data3,{{"", type text}, {"ForexExchange", type text}, {"Last", type number}, {"Bid", type number}, {"Ask", type number}, {"Volume", type number}, {"Change %", Percentage.Type}, {"Currency", type text}, {"Time", type time}, {"2", type text}}),
TestForError = try Source,
Output = if TestForError[HasError] then
get_soleBidASK(file)
else
#"Changed Type" = Table.TransformColumnTypes(Data3,{{"", type text}, {"ForexExchange", type text}, {"Last", type number}, {"Bid", type number}, {"Ask", type number}, {"Volume", type number}, {"Change %", Percentage.Type}, {"Currency", type text}, {"Time", type time}, {"2", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{""}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ForexExchange", "Last", "Bid", "Currency", "Ask", "Volume", "Change %", "Time", "2"}),
#"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"2"})
in
Output
in
get_bidAsk
This is print ERROR I get from the function output.
It connects to the first data source and doesnt find the column "ForexExchange". I would need it to identify the ERROR using the try<> and then connect to the second datasource to extract the records there.
Thanks
1 Reply
- v-huizhn-msftMicrosoft Employee
Hi Guidera,
I am not specific about Power Query, I personally suggest you post your thread to Power Query forum to get dedicated support. And you can share the solution if you get workaround from the Power Query forum, more people will benefit from here.
Best Regards,
Angelia