Forum Discussion

badger123's avatar
badger123
Resolver I
7 years ago
Solved

Search in text and count rows

Hello, hoping someone can help with this. I am counting how many times each "search term" in Table 1 appears in "phrases" in Table 2. It's working using this measure:

Search Word Measure = 
VAR CurrWord =
SELECTEDVALUE ( 'Table 1'[Search Term] )
RETURN
COUNTROWS (
    CALCULATETABLE (
        VALUES ( 'Table 2'[Phrase]), 
        FILTER ( 'Table 2'
        , SEARCH ( CurrWord, 'Table 2'[Phrase], 1, -1 ) > 0 ) ))

 

 

Table 1

TermSearch Term
apple1apple 1
apple1apple1
apple1apple one
apple2apple 2
apple2apple2
apple2apple two

 

Table 2 

Phrase
this phrase is about apple 1
this phrase is about apple1
this phrase is about apple two

 

So in this case, it would show the following in table visual:

Search TermSearch Word Measure
apple 11
apple11
apple two2

 

But I want to achieve is this  in table visual:

TermSearch Word Measure
apple12
apple22

 

 

Any ideas are appreciated! :) 

  • Hi badger123,

     

    Based on your information, I have a little confused about your scenario.

     

    I have test with your data sample and measure, but my output is not as the same as yours.

     

     

    In addition, if I understand your scenario correctly that your desired output should be like below based on your data sample, because there is only three rows in table 2.

     

     

    If I understand your logic correctly, you could follow the steps below.

     

    1. GO to Query Editor, duplicate the column Phrase in table 2 and split this column then you will get the output below.

     

    Then remove the column don't need and apply and close.

     

    2. Go to Data view, create a calculated column for table 1 with the formula below.

    Column = LOOKUPVALUE(Table2[Phrase term],Table2[Phrase term],'Table1'[Search Term])

    3. Create the measure

     

    Measure = CALCULATE(COUNT(Table1[Column]),ALLEXCEPT(Table1,'Table1'[Term]))

    More details, please refer to this attachment.

     

    If you still need help, please describe your logic in more details so that we could  help further on it.

     

    Best  Regards,

    Cherry

3 Replies

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi badger123,

     

    Based on your information, I have a little confused about your scenario.

     

    I have test with your data sample and measure, but my output is not as the same as yours.

     

     

    In addition, if I understand your scenario correctly that your desired output should be like below based on your data sample, because there is only three rows in table 2.

     

     

    If I understand your logic correctly, you could follow the steps below.

     

    1. GO to Query Editor, duplicate the column Phrase in table 2 and split this column then you will get the output below.

     

    Then remove the column don't need and apply and close.

     

    2. Go to Data view, create a calculated column for table 1 with the formula below.

    Column = LOOKUPVALUE(Table2[Phrase term],Table2[Phrase term],'Table1'[Search Term])

    3. Create the measure

     

    Measure = CALCULATE(COUNT(Table1[Column]),ALLEXCEPT(Table1,'Table1'[Term]))

    More details, please refer to this attachment.

     

    If you still need help, please describe your logic in more details so that we could  help further on it.

     

    Best  Regards,

    Cherry