【问题标题】:Index Column With Exception - POWER BI / DAX / M有异常的索引列 - POWER BI / DAX / M
【发布时间】:2020-12-04 11:13:04
【问题描述】:

我有一列具有唯一的国家值,我只需要创建一个索引列。

问题是在这个栏目中我有一个“国家”是“其他”,我需要这个国家出现在最后。

let
    Source = Table.SelectColumns(Orders,"Country"),
    #"Removed Duplicates" = Table.Distinct(Source),
    #"Add Index" = Table.AddIndexColumn(#"Removed Duplicates", "CountryId", 1, 1, Int64.Type)
in
    #"Add Index"

“添加索引但是当/with Country="Other" 放在最后。

谢谢你

【问题讨论】:

    标签: powerbi powerquery m


    【解决方案1】:

    我能想到的最简单的方法是添加一个新列来替换"Other" 的索引(然后删除旧的索引列)。

    Table.AddColumn(#"Add Index", "NewIndex", each
        if [Country] = "Other" then List.Max(#"Add Index"[CountryId]) + 1 else [CountryId]
    )
    

    【讨论】:

    • 完美,谢谢。如果我需要使用多个条件,您可以调整代码吗?示例:如果“其他”或“错过”
    • 您可以在列定义中插入一个附加子句,例如 else if [Country] = "Miss" then List.Max(#"Add Index"[CountryId]) + 2
    • 哦,我明白了,太好了。你能看看我遇到的其他类似问题吗? stackoverflow.com/questions/65145128/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 2022-06-10
    • 2017-06-21
    • 2021-12-18
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多