PowerBI:满足任一VAR时返回一个计算

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

我在PowerBI中有一个这样的表:

enter image description here

我想实现:对于2018年,将19岁以上的总人数相加;对于2018年之后的每一年,将恰好19岁的员工的总人数相加。

下面的我的代码返回一个错误(“表达式引用多个列。多个列不能转换为标量值”):

nineteen_years =
VAR age_test_2018 =
    FILTER ( 'table', 'table'[age] >= 19 && 'table'[year] = 2018 )
VAR age_test_later =
    FILTER ( 'table', 'table'[age] = 19 && 'table'[year] > 2018 )
RETURN
    CALCULATE ( SUM ( 'Union'[head count] ), age_test_2018 || age_test_later )

任何人都可以帮助我吗?感谢您的帮助!

powerbi dax var
1个回答
0
投票

这里的问题是age_test_2018和age_test_later是表。您不能对表使用OR运算符(||),它需要标量值(因此会出现错误)。

要修复它,您可以将表合并为一个,例如:

nineteen_years =
VAR age_test_2018 =
    FILTER ( 'table', 'table'[age] >= 19 && 'table'[year] = 2018 )
VAR age_test_later =
    FILTER ( 'table', 'table'[age] = 19 && 'table'[year] > 2018 )
VAR all_age_tests =
    UNION ( age_test_2018, age_test_later )
RETURN
    CALCULATE ( SUM ( 'Union'[head count] ), all_age_tests )
© www.soinside.com 2019 - 2024. All rights reserved.