Power BI - 基本列引用

问题描述 投票:0回答:2

我不知何故无法弄清楚 IF 语句 Power Query M 中的列引用。

我想根据评估不同列上的字符串比较的条件替换列中的值。

= Table.TransformColumns(
    #"Previous step",
    {"Col_1", each if [Col_2] = "ghi" then null else _}
)

“Col_1” - 包含浮点数 Col_2 - 包含 4x 文本值

====================================================== ============= 在此示例中,如果 Col_2 中的字符串等于“ghi”,我想替换该值

Data:
Col_1 | Col_2
0     | abc
12    | def
100   | ghi

Expected result:
Col_1 | Col_2
0     | abc
12    | def
null  | ghi

====================================================== ============= 请指教...

我尝试了不同的尝试,谷歌搜索,甚至是 chatGPT 3.5 ...以及该死的列引用。

powerbi powerquery analytics
2个回答
0
投票

在 powerquery 中尝试一下。你需要更换

let Source =#table({"Column1", "Column2"},{{0,"abc"},{12,"def"},{300,"ghi"}}),
Update =Table.ReplaceValue(Source, each [Column1], each if [Column2] ="ghi" then null else [Column1] ,Replacer.ReplaceValue,{"Column1"})
in Update


0
投票

Table.TransformColumns
无法交叉引用其他列。相反,您可以使用
Table.ReplaceValue
,例如:

= Table.ReplaceValue(
    #"Previous step",
    each [Col_1],
    each if [Col_2] = "ghi" then null else [Col_1],
    Replacer.ReplaceValue, {"Col_1"} )
© www.soinside.com 2019 - 2024. All rights reserved.