Power Query Custom Function使用API,无结果时失败



我在Power Query中创建了一个自定义函数,该函数使用API在线检查所选列中的值是否存在于在线系统中。如果是,则返回在线的信息。但是,如果在线上不存在该值,则查询失败,并提示"查询中发生错误"。表达式。错误:枚举中没有足够的元素来完成操作。细节(列表):"。查询关闭,不再处理任何值。

任何想法如何让它忽略无结果查询和移动到下一个值?查询方式如下:

(MedStatus)=>
let
Source = Json.Document(Web.Contents("https://data.cms.gov/data-api/v1/dataset/9138d25a-5d85-4a12-b3c9-070e544486db/data?filter[NPI]=" & Text.From(MedStatus))),
Source1 = Source{0},
#"Converted to Table" = Record.ToTable(Source1),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table",
[PromoteAllScalars=true])
in
#"Promoted Headers"

当前使用Excel 365.

谢谢。

当没有找到值时,api返回空数组。

Source1上抛出错误,您可以使用try... otherwise来纠正错误。

如果Source{0}不存在,则返回空记录[]

let
Source = Json.Document(Web.Contents("https://data.cms.gov/data-api/v1/dataset/9138d25a-5d85-4a12-b3c9-070e544486db/data?filter[NPI]=" )),
Source1 = try Source{0} otherwise [], 
#"Converted to Table" = Record.ToTable(Source1),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true])
in
#"Promoted Headers"

最新更新