Forum Discussion
How to search and count multiple keywords from a column using DAX
Hello All,
I need help with DAX. I tried creating calculated columns and mesures with search() but it is not giving me correct result.
Created below dummy table to somehow simplify my question.
For Example below is my table. I have to search and count for vowels "a","e","i","o","u".
If I get max 3 or more vowels in my search string, i will score it with 3 pts(maximum).
If 2 vowels, score it 2 pts.
if 1 vowels, score it 1 pts.
else 0 pts.
Note: Have to consider only unique vowels in a string. Duplicates should be considered as 1.
| IssueNo | SearchText |
| 1 | dream |
| 2 | each |
| 3 | cat |
| 4 | jeep |
| 5 | adiue |
| 6 | aeon |
Output :
| Issue No | Search Text | Count Vowels Score |
| 1 | dream | 2 |
| 2 | each | 2 |
| 3 | cat | 1 |
| 4 | jeep | 1 |
| 5 | adiue | 3 |
| 6 | aeon | 3 |
Thanks In Advance.
Anonymous - Try this:
Column = VAR __Vowels = { "a", "e", "i", "o", "u" } VAR __Table = SELECTCOLUMNS(ADDCOLUMNS(GENERATESERIES(1,LEN([SearchText]),1),"Letter",MID([SearchText],[Value],1)),"Letter",[Letter]) VAR __Intersect = INTERSECT(__Table,__Vowels) RETURN COUNTROWS(DISTINCT(__Intersect))PBIX is attached below signature. Table 6.
- Anonymous6 years ago
HI Anonymous ,
Create a Calculated Column
Count = VAR a =SUBSTITUTE('Table'[SearchText], "a", "",1) VAR e = SUBSTITUTE( a, "e", "",1) VAR u = SUBSTITUTE( e,"u", "",1) VAR i = SUBSTITUTE( u, "i","",1) VAR o = SUBSTITUTE( i,"o", "",1) var l = LEN('Table'[SearchText])-LEN(o) RETURN SWITCH( TRUE(), l>=3 ,3, l>=2,2, l>=1,1, 0 )Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button) Anonymous - You know, if it really is just three words you are trying to find, you could do this:
Column 1 = IF(FIND("when",[Column],,0)>0,1,0)
Column 2 = IF(FIND("then",[Column],,0)>0,1,0)
Column 3 = IF(FIND("given",[Column],,0)>0,1,0)
Column 4 = [Column 1] + [Column 2] + [Column 3]
15 Replies
- amitchandak
Super User
Anonymous , refer if this can help
https://excelkingdom.blogspot.com/2015/03/how-to-find-count-vowels-and-consonants.html
- Greg_Deckler
Community Champion
Anonymous - Try this:
Column = VAR __Vowels = { "a", "e", "i", "o", "u" } VAR __Table = SELECTCOLUMNS(ADDCOLUMNS(GENERATESERIES(1,LEN([SearchText]),1),"Letter",MID([SearchText],[Value],1)),"Letter",[Letter]) VAR __Intersect = INTERSECT(__Table,__Vowels) RETURN COUNTROWS(DISTINCT(__Intersect))PBIX is attached below signature. Table 6.
- AnonymousNot applicable
Hi Greg, I tried this in my table, but for all rows it is giving me Blank() .
Basically I am searching the below 3 keywords from my JIRA ticket's Acceptance Criteria.
"given", "when" , "then".
Is this case sensitive? For me it can be "given" or "Given" or "GIVEN"
Where is it going wrong?
AC Conformance =VAR __ACtext = { "given", "when", "then" }VAR __Table = SELECTCOLUMNS(ADDCOLUMNS(GENERATESERIES(1,LEN([Acceptance Criteria]),1),
"Letter",MID([Acceptance Criteria],[Value],1)),"Letter",[Letter])VAR __Intersect = INTERSECT(__Table,__ACtext)RETURNCOUNTROWS(DISTINCT(__Intersect))TIA- Greg_Deckler
Community Champion
Anonymous - Can you give me an example of your actual data (sample representative) Obviously there are multiple words involved so you will need to change how I was doing the __Table creation.
- AnonymousNot applicable
HI Anonymous ,
Create a Calculated Column
Count = VAR a =SUBSTITUTE('Table'[SearchText], "a", "",1) VAR e = SUBSTITUTE( a, "e", "",1) VAR u = SUBSTITUTE( e,"u", "",1) VAR i = SUBSTITUTE( u, "i","",1) VAR o = SUBSTITUTE( i,"o", "",1) var l = LEN('Table'[SearchText])-LEN(o) RETURN SWITCH( TRUE(), l>=3 ,3, l>=2,2, l>=1,1, 0 )Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)- AnonymousNot applicable
Anonymous
Hi Harsh.
Basically I am searching the below 3 keywords from my JIRA ticket's Acceptance Criteria.
"given", "when" , "then"
So how do I make it case sensitive?
For me it can be "GIVEN", "Given","given" from the Acceptance Criteria field.
I wrote this DAX but it is just giving me value (0,1,2,3) randomly .
Not actually matching the condition.
Count =VAR given =SUBSTITUTE('Requirements'[Acceptance Criteria], "Given", "",1)VAR whenn = SUBSTITUTE( "Given", "When", "",1)VAR thenn = SUBSTITUTE( "When","Then", "",1)var cnt = LEN('Requirements'[Acceptance Criteria])-LEN(thenn)RETURNSWITCH(TRUE(),cnt>=3 ,3,cnt>=2,2,cnt>=1,1,0)TIA- AnonymousNot applicable
Hi Anonymous ,
Use the LOWER() function
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)