Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Filtering words using strartwith with DAX

Hello Everyone,

 

I have a column ('ColumnA') containing a string in the format "AAA-word1, AAA-word2, BBB-word3", with varying numbers of words in each entry. My goal is to create a new column ('ColumnB') derived from 'ColumnA' that isolates and returns only the words starting with "AAA", or even just contains "AAA".

 

Like:

"AAA-word1, AAA-word2, BBB-word3" -> "AAA-word1, AAA-word2"

 

I'm limited to performing this operation within Power BI (using DAX) as I don't have direct access to modify the source data.

Any insights, suggestions, or sample DAX code would be greatly appreciated!

Cheers

 

3 Replies

  • DOLEARY85's avatar
    DOLEARY85
    Resident Rockstar

    Hi,

     

    you could try creating a calculated column to get everything before the first '-' then use that column in a slicer

     

    Column = LEFT('Table'[Word], FIND("-", 'Table'[Word]) - 1)
     
    If I answered your question, please mark my post as solution, Appreciate your Kudos 👍
    • DOLEARY85's avatar
      DOLEARY85
      Resident Rockstar

      Additionally, if due to the data source you're not able to use a calculated column it would also work as a measure:

       

      Measure = LEFT(
          CALCULATE(
              MAX('Table'[Word]),
              FILTER('Table', FIND("-", 'Table'[Word]) > 0)
          ),
          FIND("-", CALCULATE(MAX('Table'[Word]), FILTER('Table', FIND("-", 'Table'[Word]) > 0)))-1
      )
       
      If I answered your question, please mark my post as solution, Appreciate your Kudos 👍