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 August 31st. Request your voucher.
Using below code the if statemetn is throwing error (Token Idnentifier Expected), looking for any simple solutions or solution to get rid of the error
let
Source = Excel.Workbook(Web.Contents(Mflow/NewDOM/Balancing%20Report%20from%20test.xlsx"), null, true),
#"CWP Transction Logs Report_1_Sheet" = Source{[Item="CWP Transction Logs Report_1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Transction Logs Report_1_Sheet", [PromoteAllScalars=true]),
CheckNoData = Table.HasColumns(#"Promoted Headers",{"No Data Available"}),
= if CheckNoData = "True"
then
let
#"Promoted Headers" = #table(
type table {"LOG_ID", "TRADINGPARTNER_ID" }
)
in #"Promoted Headers"
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{ {"LOG_ID", Int64.Type}, {"TRADINGPARTNER_ID", type text} })
else
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{ {"LOG_ID", Int64.Type}, {"TRADINGPARTNER_ID", type text} })
in
#"Changed Type"
Solved! Go to Solution.
Hi @LeeSun ,
There's a couple of standard ways to handle this sort of issue, both covered very well by Chris Webb:
To ensure all columns are always present:
To handle source errors in general:
https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/
IMPORTANT: Make sure to read all the comments on both blogs as there's some crucial changes/updates suggested by other readers.
Pete
Proud to be a Datanaut!
Thanks Pete,
Given links has enabled me to complete my task. Below solution worked for me
let
Source = Excel.Workbook(Web.Contents("Mflow/NewDOM/Balancing%20Report%20from%20Conduent.xlsx"), null, true),
#"CWP Transction Logs Report_1_Sheet" = Source{[Item="CWP Transction Logs Report_1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"CWP Transction Logs Report_1_Sheet", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"LOG_ID", Int64.Type}, {"TRADINGPARTNER_ID", type text} }),
Custom1 = Table.SelectRows(#"Changed Type", each [ERROR_DESC] <> "Internal Outbound Service Error"),
AlternativeOutput = #table(
type table
[
#"LOG_ID"=Int64.Type,
#"TRADINGPARTNER_ID"=text
],
{}
),
TestForError= try #"Changed Type",
//If Source returns an error then return the alternative table output
//else return the value of the #"Changed Type" step
Output = if TestForError[HasError] then AlternativeOutput else Custom1
in
Output
Hi @LeeSun ,
There's a couple of standard ways to handle this sort of issue, both covered very well by Chris Webb:
To ensure all columns are always present:
To handle source errors in general:
https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/
IMPORTANT: Make sure to read all the comments on both blogs as there's some crucial changes/updates suggested by other readers.
Pete
Proud to be a Datanaut!