Forum Discussion
Marija_JC
1 year agoNew Member
Help with M code conditional column
Hello, I woluld like to create an coditional column based on the text values from another column. So, it should be like: if column B has value " x", then text in column A sholud start from 4th cha...
- 1 year ago
use the following formula
= if [ColumnB] = "x" then Text.Middle([ColumnA], 3) else if [ColumnB] = "y" then Text.BeforeDelimiter([ColumnA], "-") else if [ColumnB] = "z" then Text.BetweenDelimiters([ColumnA], "(", ")") else null
MarkLaf
1 year agoSuper User
Given a table like below:
| Column A | Column B |
| text1 text2_text3-text4 | x |
| text1 text2_text3-text4 | y |
| text1 text2_text3-text4 | z |
| text5 text6_text7-text8 | x |
| text5 text6_text7-text8 | y |
| text5 text6_text7-text8 | z |
I think the following code in a custom column would get what you want:
if [Column B] = "x"
then Text.RemoveRange( [Column A], 0, 3 ) else
if [Column B] = "y"
then Text.BeforeDelimiter( [Column A], " " ) else
if [Column B] = "z"
then Text.BetweenDelimiters([Column A], "_", "-") else
null
Output: