PowerBI 计算列的多个 if 条件

PowerBI multiple if conditions for a calculated column

我正在努力创建一个计算列,如果满足条件,该列应包含我指定的整数值。因此,我想从单个 table 中检查几列的值,如果我指定的值存在于这些列中,那么自定义列应该 return 是我指定的整数值。例如

A 列、B 列、C 列

亚利桑那州, 3, 3109
科罗拉多州,4, 2353
.
.
.
加利福尼亚州,23, 6978

我想以这样的方式创建自定义列 如果列 a='california' && 列 b='3' && 列 c= '3109' 那么 7 elseif column a='california' && column b='5' && column 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 BColumn C 类型为 numberic,则必须不带引号。像这样:

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