首页 > 解决方案 > 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 中所有可能的功能,但它没有提供所需的输出。

任何类型的铅将不胜感激。

谢谢

标签: reporting-servicespowerbidaxpowerbi-desktop

解决方案


最好的方法是在查询编辑器中。转到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 BColumn C类型为 numberic,您必须在不带引号的情况下编写它。像这样:

 = if [Column A] = "california" and [Column B] = 3 and [Column C] = 3109 ...

推荐阅读