reporting-services - PowerBI 计算列的多个 if 条件
问题描述
我正在努力创建一个计算列,如果满足条件,该列应该包含我指定的整数值。因此,从单个表中,我想检查几列的值,如果我指定的值存在于这些列中,则自定义列应返回我指定的整数值。例如
A栏、B栏、C栏
亚利桑那州, 3, 3109
科罗拉多州,4, 2353
。
.
.
加利福尼亚州,23, 6978
我想创建一个自定义列,如果列 a='california' && column b='3' && column c='3109' then 7 elseif column a='california' && column b='5' &&列 c='3109' 然后 8 elseif 等等。
我已经尝试了 PowerBi 中所有可能的功能,但它没有提供所需的输出。
任何类型的铅将不胜感激。
谢谢
解决方案
最好的方法是在查询编辑器中。转到Edit Queries > Add Column > Custom Column
并使用以下代码:
= if [Column A] = "california" and [Column B] = "3" and [Column C] = "3109" then 7
else if [Column A] = "california" and [Column B] = "5" and [Column C] = "3109" then 8
else if ...more conditions...
else 0 ' <- This one is for the case that no if condition is met and closes the if
请注意,如果Column B
和Column C
类型为 numberic,您必须在不带引号的情况下编写它。像这样:
= if [Column A] = "california" and [Column B] = 3 and [Column C] = 3109 ...
推荐阅读
- java - 从sql查询中获取结果后如何提取字符串和println
- xsd - XML Schema 验证模式不允许使用字符串
- maximo - 在 Maximo anywehere 进行更改后,Maximo 应用程序不会更新
- javascript - 在 Twilio flex 中列出我的电话号码清单
- python - 使用 Keras flow_from_directory 和我的方法的预处理方法是否相同?
- filebeat - Filebeat - kakfka 输出“和”或“正则表达式”条件不起作用
- javascript - Fetch to Express 返回旧数据
- r - 如何将数据框作为参数传递给函数?
- jupyter - Jupyterlab 不显示一些在 jupyter notebook 中可见的单元格
- java - 是否可以从具有限制的 Json 对象中获取值