如何在第一列中使用给定的字符串匹配条件在Power Bi中创建新列,并从另一列获取值,创建新列?

时间:2019-10-30 04:41:36

标签: powerbi powerbi-desktop powerbi-embedded powerbi-datasource powerbi-custom-visuals

我的表如下

Col1 Col2

11_A    9
12_B    8
13_C    7
14_A    6
15_A    4

查询后我们需要的表

Col1  Col2  Col3

11_A    0   9
12_B    8   0
13_C    7   0
14_A    0   6
15_A    0   4

我的查询是

Col3 = 
LEFT( 'Table'[Col2], 
     SEARCH("A", 'Table'[Col1], 0, 
         LEN('Table'[Col1])
     )
)

2 个答案:

答案 0 :(得分:1)

转到查询设计器Add Column > Custom Column并使用以下表达式:

enter image description here

enter image description here

更新

为此,您需要两个表达式(两个新列):

一个是:

'Your Column3
=if Text.Contains([Col1], "A") = true then [Col2] else 0

第二个:

'Your Column2
=if Text.Contains([Col1], "A") = false then [Col2] else 0

答案 1 :(得分:1)

有很多方法可以解决这个问题, 我喜欢不编码的另一种简单方法是使用条件列:

  • 在PBI中选择Power Query Editor
  • 在屏幕边缘选择表格
  • 选择“添加列”标签
  • 选择条件列...
  • 命名您的专栏
  • 输入图片中的条件
  • 如果愿意,您可以添加几个条件
  • 如果需要,请不要忘记将列的格式设置为数字。

查看图片

Adding columns using Conditional Column