Power BI: extract keyword or everything after, before or between a key character
When I have a column with sentences like a description column, I may want to extract everything before or after a keyword or simply to extract the keyword. Let´s take an example, I have this column and I want to extract everything before or after this delimiter “:”:
- Left: LEFT('table'[argument],SEARCH("value",'table'[argument])-1)
- Right: RIGHT('table'[argument],LEN('table'[argument])-(SEARCH("value",'table'[argument])+1))
NOTE:
- Replace “table”, “argument” and “value” by yours
- For the right, after “:”, there is a space, if I want to include it, for the “right” formula, just remove “+1”
- If searching for “?”, put “~?”
Let´s take another example, I have this column and I want to extract this word “new”:
- Left: same formula as above
- Right: same formula as above except to have “+1”, I have “+3”
NOTE: if I want to include the space, change “+3” by “+2”
- Word: MID('table'[argument],SEARCH("value",'table'[argument],,0),3)
NOTE: if I want to include the space, change “3” by “4”
Now, I have this column and I want to extract “new” (after, before and word) but only if “extract” is found:
- IF(CONTAINSSTRING('table'[argument],"value1"),second example formula,"value2")
NOTE: if the word is not found, to put a blank result, change "value2" by ""
If I want to extract words between 2 delimiters, for instance “ - “:
PATHITEM(SUBSTITUTE('table'[argument],"delimiter","|"),2)
To end, I want to extract only x characters after finding a word. For this, I have to go to the “query editor -> add column -> custom column” then put this formula:
Then put this formula:
Text.Start(Text.AfterDelimiter([argument],"value_find"),number_extract)
In my example, I am asking to extract the 4 characters after finding the word “new”
NOTE:
- A space is considered as a character
- “value_find” can be a sentence and not only a single word
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...