Home > Blockchain >  Expression.Error There weren't enough elements in the enumeration to complete the operation. po
Expression.Error There weren't enough elements in the enumeration to complete the operation. po

Time:02-22

Below is m code from power query (Excel 2016) for stock tickers. If I enter proper tickers like MSFT it works perfectly but if I enter an incorrect ticker such as ddddddd I get the following error, "[Expression.Error] There weren't enough elements in the enumeration to complete the operation. " How do I bypass this error and enter 0 for the value? Can I use Try Otherwise somehow?

Thanks in advance!

(InputTicker as text) as table =>

let

Source = Web.Page(Web.Contents("https://finance.yahoo.com/quote/"&InputTicker&"/key-statistics?p="&InputTicker)),
    Data3 = Source{3}[Data],

#"Demoted Headers" = Table.DemoteHeaders(Data3),

#"Filtered Rows" = Table.SelectRows(#"Demoted Headers", each Text.Contains([Column1], "Forward Annual Dividend Yield"))
in

#"Filtered Rows"

CodePudding user response:

Try

 Data3 = try Source{3}[Data] otherwise #table({"First Column", "Second Column"}, {{"Forward Annual Dividend Yield",0}}),
  • Related