The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I'm using PowerQuery to try get the contents of a list on 1,000 plus SharePoint sites.
So I have retrieved the list of site URLs and constructed the list URL, and now want to get the contents of each list, merged into one long aggregated list.
So I have written a function, and I'm using that mostly just fine. The problem is that sometimes a particular site doesn't have the list I am looking for. It doesn't exist. And I cannot find a way to trap the error.
Expression.Error: We cannot convert a value of type Table to type Function
My function returns a "table", andsometimes "error". If I try "replace errors" it can't because it's a table, not just a text or number.
let
Source = (SiteURL as any) =>
let
aSource = OData.Feed(SiteURL , null, [Implementation="2.0"]),
"Removed Other Columns" = Table.SelectColumns(aSource,{ "CostTypeFree1"},MissingField.UseNull)
"Distincted" = Table.Group(#"aSource", {"CostTypeFree1"}, {{"Count", each Table.RowCount(_), type number}}),
"Removed Columns" = Table.RemoveColumns(Distincted,{"Count"}),
in
#"Removed Other Columns"
in
Source
So... my question: How do I handle the fact that sometimes a list doesn't exist, and then return something useful.
I'm thinking maybe some sort of
Try this web request. If I get a 404 then "No" else "ok"
It would be so nice if I could just use something like this:
let
response = Web.Contents(
"https://api.census.gov/data/2018/pep/population?get=POP&for=state"
),
json = Json.Document(response)
in
json
... but unfortunately in a SSO MFA environment, such simple efficient solutions don't seem possible.
Here's another attempt:
let
Source = (theurl as any) =>
let
aTest = try OData.Feed(theurl, null, [Implementation="2.0"]),
test = Table.AddColumn(aTest, "ListCheck", each if aTest [HasError] then "List doesnt exist" else "ok")
in
test
in
Source
// An error occurred in the query. Expression.Error: We cannot convert a value of type Record to type Table.
// Details:
// Value=[Record]
// Type=[Type]
Solved! Go to Solution.
You need an otherwise to go with your try
aSource = try OData.Feed(SiteURL , null, [Implementation="2.0"]) otherwise null
If it is the Removed Other Columns step that generates the error, you could add a step to add a column with Table.RowCount( ) after aSource, and then filter out any rows where the table does not have >=1 rows.
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
You need an otherwise to go with your try
aSource = try OData.Feed(SiteURL , null, [Implementation="2.0"]) otherwise null
If it is the Removed Other Columns step that generates the error, you could add a step to add a column with Table.RowCount( ) after aSource, and then filter out any rows where the table does not have >=1 rows.
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.