searching a keyword in DAX

亡梦爱人 提交于 2020-01-06 05:07:48

问题


I am trying to create a column in power BI that searches for a keyword in a column of a table and returns a category.

For example: in table 1 there is a column with feedback and if it contains any keyword in the keyword column of table 2 ( which is updated regularly) a TRUE value is returned.

The following code works great if the keyword is the only word in the sentence like "product broke after using it once" returns FALSE if looking for the keyword "broke" and the word "broke" used as the only word in the sentence returns TRUE

Column = if(
CONTAINS(Products,Products[feedback],RELATED(feedbackList[keywords]))
,"TRUE","FALSE")

So basically it only returns if the value is matched exactly and not as part of a sentence.

I hope someone can help, Thanks in advance


回答1:


assuming you are creating the calculated column in TableA, you already have a filter context in TableA so you only need to iterate over TableB in order to get the description you need.

Let me know if the following works:

ColumnMeasure =

calculate(

if(

countrows(values('Table B'[Colmn B2]))>1,

"More than 1 classification found",

values('Table B'[Colmn B2])

),

filter(

all('Table B'[Colmm B1]),

search('Table B'[Colmn B1],'Table A'[Colmn A1],1,0)<>0

  )

)

There are more similar examples here:

http://sqlblog.com/blogs/marco_russo/archive/2011/12/30/string-comparison-in-dax.aspx



来源:https://stackoverflow.com/questions/50230855/searching-a-keyword-in-dax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!