PowerBI:return 满足任一 VAR 时的计算
PowerBI: return a calculation when either VAR is fulfilled
我在 PowerBI 中有这样一个 table:
我想实现:2018年,对19岁以上的总人数求和;对于 2018 年之后的每一年,将恰好 19 岁的人数相加。
我下面的代码 returns 出错 ("The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value"):
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 )
任何人都可以帮助我吗?感谢您的帮助!
这里的问题是 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 )
我在 PowerBI 中有这样一个 table:
我想实现:2018年,对19岁以上的总人数求和;对于 2018 年之后的每一年,将恰好 19 岁的人数相加。
我下面的代码 returns 出错 ("The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value"):
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 )
任何人都可以帮助我吗?感谢您的帮助!
这里的问题是 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 )