Power BI - 处理不存在的参数并返回 table 中的有效参数数据
Power BI - handling non-existing arguments and returning data in table for valid arguments
我卡在了错误处理例程中。我有这个功能..
(LicenceNumber) =>
let
Source =
Web.Page(Web.Contents("http://mbsweblist.fsco.gov.on.ca/ShowLicence.aspx?M"
& Number.ToText(LicenceNumber) & "~")),
WebData = Source{1}[Data],
#"Extracted Text Before Delimiter" = Table.TransformColumns(WebData,
{{"Column1", each Text.BeforeDelimiter(_, ":"), type text}}),
#"Removed Top Rows" = Table.Skip(#"Extracted Text Before Delimiter",1),
#"Transposed Table" = Table.Transpose(#"Removed Top Rows"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table",
[PromoteAllScalars=true])
in
#"Promoted Headers"
其中 returns 数据到 table
let
Source = {13000246..13000250},
#"Convert to Table" = Table.FromList(Source,Splitter.SplitByNothing(),{"Licence Number"}),
#"Changed Type" = Table.TransformColumnTypes(#"Convert to Table",{{"Licence Number", Int64.Type}}),
#"Get WebData" = Table.AddColumn(#"Changed Type", "WebData", each try WebData([Licence Number]) otherwise #table({},{})),
#"Combine WebData" = Table.Combine(#"Get WebData"[WebData]),
#"Changed Types" = Table.TransformColumnTypes(#"Combine WebData",{{"Agent/Broker Name", type text}, {"Licence #", type text}, {"Brokerage Name", type text}, {"Licence Class", type text}, {"Status", type text}, {"Issue Date", type date}, {"Expiry Date", type date}, {"Inactive Date", type date}})
in
#"Changed Types"
我正在尝试错误处理我在源中传递无效值的情况,假设源 = {13009995..13009999},这是抛出错误 - "col X of table was not found"。我尝试使用以下错误处理逻辑,但它不起作用 ..
Empty = #table({{"Agent/Broker Name", type text}, {"Licence #", type text},
{"Brokerage Name", type text}, {"Licence Class", type text}, {"Status", type
text}, {"Issue Date", type date}, {"Expiry Date", type date}, {"Inactive
Date", type date}},{}),
Combine = Table.Combine({#"Get WebData"[WebData], Empty}),
我主要是一名业务分析师,无法修复此错误。请求帮助。用户 Olly 帮助我完成了主要查询
我建议创建一个空的 table 作为一个名为 EmptyTable
的单独查询,以便在您取回数据时匹配列。这是 M 代码:
let
Empty =
#table(
{
"Agent/Broker Name",
"Licence #",
"Brokerage Name",
"Licence Class",
"Status",
"Issue Date",
"Expiry Date",
"Inactive Date"
},
{}
)
in
Empty
现在在您的 #"Get WebData"
步骤中,只需将 #table({},{})
换成 EmptyTable
。
#"Get WebData" =
Table.AddColumn(
#"Changed Type",
"WebData",
each
try WebData([Licence Number])
otherwise EmptyTable
),
注意:当至少有一个有效的许可证号时,您的查询看起来工作正常。
我卡在了错误处理例程中。我有这个功能..
(LicenceNumber) =>
let
Source =
Web.Page(Web.Contents("http://mbsweblist.fsco.gov.on.ca/ShowLicence.aspx?M"
& Number.ToText(LicenceNumber) & "~")),
WebData = Source{1}[Data],
#"Extracted Text Before Delimiter" = Table.TransformColumns(WebData,
{{"Column1", each Text.BeforeDelimiter(_, ":"), type text}}),
#"Removed Top Rows" = Table.Skip(#"Extracted Text Before Delimiter",1),
#"Transposed Table" = Table.Transpose(#"Removed Top Rows"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table",
[PromoteAllScalars=true])
in
#"Promoted Headers"
其中 returns 数据到 table
let
Source = {13000246..13000250},
#"Convert to Table" = Table.FromList(Source,Splitter.SplitByNothing(),{"Licence Number"}),
#"Changed Type" = Table.TransformColumnTypes(#"Convert to Table",{{"Licence Number", Int64.Type}}),
#"Get WebData" = Table.AddColumn(#"Changed Type", "WebData", each try WebData([Licence Number]) otherwise #table({},{})),
#"Combine WebData" = Table.Combine(#"Get WebData"[WebData]),
#"Changed Types" = Table.TransformColumnTypes(#"Combine WebData",{{"Agent/Broker Name", type text}, {"Licence #", type text}, {"Brokerage Name", type text}, {"Licence Class", type text}, {"Status", type text}, {"Issue Date", type date}, {"Expiry Date", type date}, {"Inactive Date", type date}})
in
#"Changed Types"
我正在尝试错误处理我在源中传递无效值的情况,假设源 = {13009995..13009999},这是抛出错误 - "col X of table was not found"。我尝试使用以下错误处理逻辑,但它不起作用 ..
Empty = #table({{"Agent/Broker Name", type text}, {"Licence #", type text},
{"Brokerage Name", type text}, {"Licence Class", type text}, {"Status", type
text}, {"Issue Date", type date}, {"Expiry Date", type date}, {"Inactive
Date", type date}},{}),
Combine = Table.Combine({#"Get WebData"[WebData], Empty}),
我主要是一名业务分析师,无法修复此错误。请求帮助。用户 Olly 帮助我完成了主要查询
我建议创建一个空的 table 作为一个名为 EmptyTable
的单独查询,以便在您取回数据时匹配列。这是 M 代码:
let
Empty =
#table(
{
"Agent/Broker Name",
"Licence #",
"Brokerage Name",
"Licence Class",
"Status",
"Issue Date",
"Expiry Date",
"Inactive Date"
},
{}
)
in
Empty
现在在您的 #"Get WebData"
步骤中,只需将 #table({},{})
换成 EmptyTable
。
#"Get WebData" =
Table.AddColumn(
#"Changed Type",
"WebData",
each
try WebData([Licence Number])
otherwise EmptyTable
),
注意:当至少有一个有效的许可证号时,您的查询看起来工作正常。