powerbi - PowerBI:当满足任一 VAR 时返回计算
问题描述
我在 PowerBI 中有这样的表:
我想实现: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 )
任何人都可以帮我解决这个问题吗?感谢你的帮助!
解决方案
这里的问题是 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 )
推荐阅读
- java - SQLite 检查重复的用户名
- r - 如何在R中像猫一样粘贴
- asp.net-core - 如何复制 Nuget 包?
- flutter - 按下 Flutter 的浮动操作按钮的简单对话框
- image - 通过管理员上传的图像保存在哪里?
- python - Python 检查单选按钮是 True 还是 False
- authentication - 用户退出会话时如何正确删除 cookie?
- php - Index.php重定向到别的地方,如何找到包含html代码的文件
- python - 抓取具有不同数据元素且所有 span 标签具有相同名称的页面
- python - 我怎么能在没有嵌套循环的情况下拆分逗号。不要在标签内拆分