我正在尝试在 PowerBI 和 DAX 中创建一个名为
IsTop25Office
的列,如果该行中的 Office 按其名称位于前 25 个计数中,则每行添加一个指示符列,并在该行中的旁边添加一个“是”如果是,如果不是,则“否”。
我拥有的是
IsTop25Office = IF(
RANKX(
ALL('Table'[officeName]), // Ensure ranking is done based on unique office names.
CALCULATE(COUNTROWS('Table'), ALL('Table'[officeName])), // Count rows for each officeName across the entire 'Table' table.
,DESC, Dense
) <= 25, "Yes", "No"
)
不幸的是,当我这样做时,无论 Office 是否位于前 25 名,我对所有行都得到“是”,并且没有“否”。我该如何解决这个问题?
这样做的动机是用它来动态过滤前 25 个(或任意 n 个)办公室。
您可以创建一个度量来计算第 25 位最高出勤率
25th Highest Attendance =
MINX(
TOPN(
25,
ALL('Table'),
'Table'[AttendanceCount],
DESC
),
'Table'[AttendanceCount]
)
然后在计算列中使用它:
IsTop25Office =
IF(
'Table'[AttendanceCount] >= [25th Highest Attendance],
"Yes",
"No"
)