November 2, 2021
Hi all,
This seems like a simple one that I can't quite crack - I'm almost certainly missing something basic, but for the life of me I can't see it, so would appreciate some extra eyes!
I'm trying to add some error handling to this function I'm working on - it works fine in most cases. But some of the values I need to run it against will return an empty table in the middle of the function, and if that happens the subsequent steps give an error.
To deal with that, I thought I could use the branching logic described here: https://community.powerbi.com/.....ba-p/39998
Here is the relevant section of the code:
data = #"API call"[data],
logs = data[logs],
#"Converted to Table" = Table.FromList(logs, Splitter.SplitByNothing(), null, null, ExtraValues.Errror),
//Code to run if the table is not empty
#Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"message", "logged_at", "user"}, {"message", "logged_at", "user"}),
#"Add Date" = Table.AddColumn(#"Expanded Column1", "Date", each DateTime.FromText([logged_at], [Formate = "HH:mm d MMM yyyy"])),
//Test if table is empty
result = if Table.IsEmpty(#"Converted to Table") = true then null else #"Reorder Columns"
in
result
This throws a "Token Literal expected" error, and the "Show error" link in the advanced editor points to that final if statement as the source of the problem.
My understanding is that that error means that a value or function should come after the if, but Table.IsEmpty is a function! What am I missing here?
Any help much appreciated!
Ryan
Trusted Members
Moderators
November 1, 2018
November 2, 2021
That's what I though! By "debugger" do you mean the "Show error" tool in the Advanced Editor? When I clicked that it highlighted the "if" in the if statement at the end
Strangely, I had a duplicate version of the query that was working fine, so I copy-pasted one line at a time from it into the broken version, and now it runs. I'm sure there must have been some difference between the two (I kept the duplicate as a fallback because I was trying to make some changes to the version that broke) but I couldn't spot a single one as I replaced each line.
Nevertheless, it worked and the error is gone so \_(ツ)_/
Thanks for your help and sorry to waste your time!
1 Guest(s)