我在这个用于功率查询的 M 代码函数中哪里出错了?

Where did I go wrong in this M-Code function for power-query?

我正在尝试编写一个 M 代码函数,我可以用它来过滤掉格式不符合 "A0000" 或 "B0000" 或 "C0000" 等的文本值.

我尝试在 Power-Query 中编写自定义函数,但我似乎无法理解这种语言的细微差别,而且文档和语法错误警告对于故障排除几乎毫无用处。

这是我目前所拥有的。当我单击显示错误按钮时,我收到一个错误 "Token Identifier Expected",突出显示第一行 if

有谁知道我哪里出了问题,我可能会尝试如何解决它?

let IsNewPN= (Argument) =>
    let
        /*M code to evaluate in the function goes here*/
        a= Text.Start(Argument,1),
        b= Text.End(Argument, Text.Length(Argument) - 1),

        if     a="A" or a="B" or a="C" or a="D" or a="E" or a="F" or a="H" or a="M" or a="Q" or a="W"
        then    x=1
        else    x=0

        if x=0 
        then Result = "FALSE"
        else    Result=try a & Text.InferNumberType(b) otherwise "FALSE"
    in
        Result
in
    IsNewPN

每一行的格式必须是 value = expression.

尝试将您的代码更改为:

let IsNewPN= (Argument) =>
    let
        /*M code to evaluate in the function goes here*/
        a= Text.Start(Argument,1),
        b= Text.End(Argument, Text.Length(Argument) - 1),

        x = 
        if     a="A" or a="B" or a="C" or a="D" or a="E" or a="F" or a="H" or a="M" or a="Q" or a="W"
        then    1
        else    0,

        Return = 
        if x=0 
        then "FALSE"
        else  try a & Text.InferNumberType(b) otherwise "FALSE"
    in
        Result
in
    IsNewPN

在此代码中,xReturn 是各自行的“令牌标识符”。


旁注:您可以使用以下方法简化您的大 or 表达式:

Text.Contains("ABCDEFHMQW",a)