在 DAX 中结合 SELECTCOLUMNS 和 ORDER BY

Combine SELECTCOLUMNS and ORDER BY in DAX

这行得通,它选择了多个列:

evaluate SELECTCOLUMNS(branches,
         "The branch code", branches[code], 
           "The branch name", branches[name], 
           "The branch city", branches[city])

这也有效:

evaluate branches
    order by branches[name]
    start at "Co"

但是如果我想把两者结合起来,我会得到一个错误:

evaluate ( SELECTCOLUMNS ( branches,
    "The branch code", branches[code],
    "The branch name", branches[name],
    "The branch city", branches[city]) )
    order by branches[name]
    start at "Co"

A single value for column 'name' in table 'branches' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

错误说的是聚合,但我不需要聚合。问题是什么以及如何解决?

函数SELECTCOLUMNS returns a table,ORDER BY指的是这个新的table,而不是原来的table“分支”。由于 new table 不包含字段 [name],您会收到错误消息。要修复它,只需参考新 table:

中的字段
EVALUATE
SELECTCOLUMNS (
    branches,
    "The branch code", branches[code],
    "The branch name", branches[name],
    "The branch city", branches[city]
)
ORDER BY [The branch name]
START AT "Co"