Forum Discussion
String block search
- 5 years ago
Hey Wresen ,
first I created a table that contains the "predefined blocks", I called this table "searchstrings" and the column "searchstring", the table looks like this:
The table is NOT related to the item-table.
Then I created this measure:
Measure = var __SearchstringsToFind = VALUES( 'Searchstrings'[searchstring] ) var lengthOfBlock = 3 return COUNTX( Sheet1 , var afunnystring = 'Sheet1'[String] var lengthofstring = LEN( afunnystring ) var noofoccurrences = IF( MOD( lengthofstring , lengthOfBlock ) = 0 , INT( DIVIDE( lengthofstring , lengthOfBlock ) ) , INT( DIVIDE( lengthofstring , lengthOfBlock ) ) + 1 ) var __blocks = ADDCOLUMNS( GENERATESERIES( 1 , noofoccurrences ) , "block" , MID( afunnystring , ''[Value] * lengthOfBlock - 2 , lengthOfBlock ) ) return COUNTROWS( FILTER( __blocks , [block] in __SearchstringsToFind ) ) )It seems the measure is returning the expected result:
Hopefully, this provides what you are looking for.
Regards,
Tom
Hey Wresen ,
this can be done using DAX inside a measure. The idea behind this approach is the following:
- separate the string into single characters
- remove unwanted characters like spaces (maybe not)
- create a table that contains combinations of the characters that form the sequence of characters, maybe based on a variable number, 3, 4, ...
- count the number of occurrences of the searchstring in the table
You have to be aware that this can become complex and slow, as text analysis is not the domain of Power BI.
Please take the time and create some sample data and provide a link to your sample data, if there is more than the "simple" example you provided.
Regards,
Tom
Hi TomMartens
First i would like to apoligize for a very late answer and reply ( have been on vaction)
I have tried it now and it seems to work perfectly as i want , thank you so much for this.